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 4651 - (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 3912
11 :     // create the world
12 : jhr 3916 world *wrld = new (std::nothrow) world();
13 : jhr 3912 if (wrld == nullptr) {
14 : jhr 3916 std::cerr << "unable to create world" << std::endl;
15 : jhr 3912 exit (1);
16 :     }
17 :    
18 :     #ifndef DIDEROT_NO_INPUTS
19 :     // initialize the default values for the inputs
20 : jhr 3931 cmd_line_inputs inputs;
21 : jhr 3912 init_defaults (&inputs);
22 :     #endif
23 :    
24 :     // handle command-line options
25 :     {
26 : jhr 4317 diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();
27 :     uint32_t np = wrld->_sched->_numWorkers;
28 :     opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));
29 :     opts->addFlag ("t,timing", "enable execution timing", &timingFlg);
30 :     opts->add ("n,nworkers", "specify number of worker threads", &np, true);
31 :     opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",
32 : jhr 3912 &stepLimit, true);
33 : jhr 4633 opts->add ("print", "specify where to direct printed output", &printFile, true);
34 : jhr 3912 #ifndef DIDEROT_NO_INPUTS
35 :     // register options for setting global inputs
36 : jhr 4317 register_inputs (&inputs, opts);
37 : jhr 3912 #endif
38 : jhr 4317 register_outputs (opts);
39 :     opts->process (argc, argv);
40 :     delete opts;
41 :     wrld->_sched->_numWorkers = np;
42 : jhr 3912 }
43 :    
44 : jhr 4633 // redirect printing (if necessary)
45 :     if (printFile.compare("-") != 0) {
46 :     wrld->_printTo = new std::ofstream (printFile);
47 :     if (wrld->_printTo->fail()) {
48 :     std::cerr << "Error opening print file" << std::endl;
49 :     exit(1);
50 :     }
51 :     }
52 :    
53 : jhr 3912 // initialize scheduler stuff
54 : jhr 3916 if (wrld->_verbose) {
55 : jhr 3912 std::cerr << "initializing world ..." << std::endl;
56 :     }
57 :     if (wrld->init()) {
58 :     std::cerr << "Error initializing world:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
59 :     exit(1);
60 :     }
61 :    
62 :     #ifndef DIDEROT_NO_INPUTS
63 :     // initialize the input globals
64 : jhr 3916 if (init_inputs (wrld, &inputs)) {
65 : jhr 4317 std::cerr << "Error initializing inputs:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
66 :     exit(1);
67 : jhr 3912 }
68 :     #endif
69 :    
70 :     // run the generated global initialization code
71 : jhr 3916 if (wrld->_verbose) {
72 : jhr 4407 std::cerr << "initializing globals and creating strands ...\n";
73 : jhr 3912 }
74 : jhr 4418 if (wrld->create_strands()) {
75 : jhr 4063 std::cerr << "Error in global initialization:\n"
76 : jhr 4317 << biffMsgStrGet(wrld->_errors) << std::endl;
77 : jhr 3912 exit(1);
78 :     }
79 :    
80 : jhr 3922 uint32_t nSteps = wrld->run (stepLimit);
81 : jhr 3912
82 : jhr 3916 if (wrld->_errors->errNum > 0) {
83 : jhr 4063 std::cerr << "Error during execution:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
84 : jhr 3912 exit(1);
85 :     }
86 :    
87 : jhr 3916 if (wrld->_verbose) {
88 : jhr 3917 std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"
89 : jhr 4317 << std::endl;
90 : jhr 3912 }
91 :     else if (timingFlg) {
92 : jhr 4317 std::cout << "usr=" << wrld->_run_time << std::endl;
93 : jhr 3912 }
94 :    
95 : jhr 4650 #ifdef DIDEROT_HAS_STRAND_DIE
96 :     // check that there are strands that have output
97 :     if (wrld->_strands.num_stable() == 0) {
98 : jhr 4651 std::cerr << "Error: no stable strands at program termination, so no output was produced."
99 : jhr 4650 << std::endl;
100 :     return 1;
101 :     }
102 :     #endif
103 :    
104 : jhr 3912 // output the final strand states
105 : jhr 4259 write_output (wrld);
106 : jhr 3912
107 : jhr 3917 delete wrld;
108 : jhr 3912
109 :     return 0;
110 :    
111 :     } // main

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