Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/target-cpu/fragments/par-main.in
ViewVC logotype

Annotation of /branches/vis15/src/compiler/target-cpu/fragments/par-main.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4664 - (view) (download)

1 : jhr 3924 using namespace @PREFIX@;
2 :    
3 : jhr 3912 //! Main function for standalone parallel C target
4 :     //
5 :     int main (int argc, const char **argv)
6 :     {
7 :     bool timingFlg = false; //! true if timing computation
8 :     uint32_t stepLimit = 0; //! limit on number of execution steps (0 means unlimited)
9 : jhr 4633 std::string printFile = "-"; //! file to direct printed output into
10 : jhr 4664 #ifdef DIDEROT_EXEC_SNAPSHOT
11 :     uint32_t snapshotPeriod = 1; //! supersteps per snapshot
12 :     #endif
13 :     uint32_t nSteps = 0; //! number of supersteps taken
14 : jhr 3912
15 :     // create the world
16 : jhr 3916 world *wrld = new (std::nothrow) world();
17 : jhr 3912 if (wrld == nullptr) {
18 : jhr 3916 std::cerr << "unable to create world" << std::endl;
19 : jhr 3912 exit (1);
20 :     }
21 :    
22 :     #ifndef DIDEROT_NO_INPUTS
23 :     // initialize the default values for the inputs
24 : jhr 3931 cmd_line_inputs inputs;
25 : jhr 3912 init_defaults (&inputs);
26 :     #endif
27 :    
28 :     // handle command-line options
29 :     {
30 : jhr 4317 diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();
31 :     uint32_t np = wrld->_sched->_numWorkers;
32 :     opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));
33 :     opts->addFlag ("t,timing", "enable execution timing", &timingFlg);
34 :     opts->add ("n,nworkers", "specify number of worker threads", &np, true);
35 :     opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",
36 : jhr 3912 &stepLimit, true);
37 : jhr 4633 opts->add ("print", "specify where to direct printed output", &printFile, true);
38 : jhr 3912 #ifndef DIDEROT_NO_INPUTS
39 :     // register options for setting global inputs
40 : jhr 4317 register_inputs (&inputs, opts);
41 : jhr 3912 #endif
42 : jhr 4317 register_outputs (opts);
43 :     opts->process (argc, argv);
44 :     delete opts;
45 :     wrld->_sched->_numWorkers = np;
46 : jhr 3912 }
47 :    
48 : jhr 4633 // redirect printing (if necessary)
49 :     if (printFile.compare("-") != 0) {
50 :     wrld->_printTo = new std::ofstream (printFile);
51 :     if (wrld->_printTo->fail()) {
52 :     std::cerr << "Error opening print file" << std::endl;
53 :     exit(1);
54 :     }
55 :     }
56 :    
57 : jhr 3912 // initialize scheduler stuff
58 : jhr 3916 if (wrld->_verbose) {
59 : jhr 3912 std::cerr << "initializing world ..." << std::endl;
60 :     }
61 :     if (wrld->init()) {
62 :     std::cerr << "Error initializing world:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
63 :     exit(1);
64 :     }
65 :    
66 :     #ifndef DIDEROT_NO_INPUTS
67 :     // initialize the input globals
68 : jhr 3916 if (init_inputs (wrld, &inputs)) {
69 : jhr 4317 std::cerr << "Error initializing inputs:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
70 :     exit(1);
71 : jhr 3912 }
72 :     #endif
73 :    
74 :     // run the generated global initialization code
75 : jhr 3916 if (wrld->_verbose) {
76 : jhr 4407 std::cerr << "initializing globals and creating strands ...\n";
77 : jhr 3912 }
78 : jhr 4418 if (wrld->create_strands()) {
79 : jhr 4063 std::cerr << "Error in global initialization:\n"
80 : jhr 4317 << biffMsgStrGet(wrld->_errors) << std::endl;
81 : jhr 3912 exit(1);
82 :     }
83 :    
84 : jhr 4664 #ifdef DIDEROT_EXEC_SNAPSHOT
85 : jhr 3912
86 : jhr 4664 if (snapshotPeriod > 0) {
87 :     uint32_t n;
88 :     write_snapshot (wrld, "-0000"); // write initial state as snapshot 0
89 :     while ((n = wrld->run (snapshotPeriod)) > 0) {
90 :     nSteps += n;
91 :     if ((wrld->_errors->errNum > 0) || (wrld->_strands.num_alive() == 0)) {
92 :     break;
93 :     }
94 :     // write a snapshot with the step count as a suffix
95 :     std::string suffix = std::to_string(nSteps);
96 :     if (suffix.length() < 4) {
97 :     suffix = std::string("0000").substr(0, 4 - suffix.length()) + suffix;
98 :     }
99 :     suffix = "-" + suffix;
100 :     write_snapshot (wrld, suffix);
101 :     }
102 :     }
103 :     else {
104 :     nSteps = wrld->run (stepLimit);
105 :     }
106 :    
107 :     #else // !DIDEROT_EXEC_SNAPSHOT
108 :    
109 :     nSteps = wrld->run (stepLimit);
110 :    
111 :     #endif // DIDEROT_EXEC_SNAPSHOT
112 :    
113 : jhr 3916 if (wrld->_errors->errNum > 0) {
114 : jhr 4063 std::cerr << "Error during execution:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
115 : jhr 3912 exit(1);
116 :     }
117 :    
118 : jhr 3916 if (wrld->_verbose) {
119 : jhr 3917 std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"
120 : jhr 4317 << std::endl;
121 : jhr 3912 }
122 :     else if (timingFlg) {
123 : jhr 4317 std::cout << "usr=" << wrld->_run_time << std::endl;
124 : jhr 3912 }
125 :    
126 : jhr 4650 #ifdef DIDEROT_HAS_STRAND_DIE
127 :     // check that there are strands that have output
128 :     if (wrld->_strands.num_stable() == 0) {
129 : jhr 4651 std::cerr << "Error: no stable strands at program termination, so no output was produced."
130 : jhr 4664 << std::endl;
131 :     return 1;
132 : jhr 4650 }
133 :     #endif
134 :    
135 : jhr 3912 // output the final strand states
136 : jhr 4259 write_output (wrld);
137 : jhr 3912
138 : jhr 3917 delete wrld;
139 : jhr 3912
140 :     return 0;
141 :    
142 :     } // main

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0