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 3922 - (view) (download)

1 : jhr 3912 //! Main function for standalone parallel C target
2 :     //
3 :     int main (int argc, const char **argv)
4 :     {
5 :     bool timingFlg = false; //! true if timing computation
6 :     uint32_t stepLimit = 0; //! limit on number of execution steps (0 means unlimited)
7 :    
8 :     // create the world
9 : jhr 3916 world *wrld = new (std::nothrow) world();
10 : jhr 3912 if (wrld == nullptr) {
11 : jhr 3916 std::cerr << "unable to create world" << std::endl;
12 : jhr 3912 exit (1);
13 :     }
14 :    
15 :     #ifndef DIDEROT_NO_INPUTS
16 :     // initialize the default values for the inputs
17 :     inputs inputs;
18 :     init_defaults (&inputs);
19 :     #endif
20 :    
21 :     // handle command-line options
22 :     {
23 : jhr 3916 diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();
24 : jhr 3912 uint32_t np = wrld->_sched->numWorkers;
25 : jhr 3916 opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));
26 :     opts->addFlag ("t,timing", "enable execution timing", &timingFlg);
27 :     opts->add ("n,nworkers", "specify number of worker threads", &np, true);
28 :     opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",
29 : jhr 3912 &stepLimit, true);
30 :     #ifndef DIDEROT_NO_INPUTS
31 :     // register options for setting global inputs
32 :     register_inputs (&inputs, opts);
33 :     #endif
34 :     register_outputs (opts);
35 : jhr 3916 opts->process (argc, argv);
36 :     delete opts;
37 : jhr 3912 wrld->_sched->numWorkers = np;
38 :     }
39 :    
40 :     // initialize scheduler stuff
41 : jhr 3916 if (wrld->_verbose) {
42 : jhr 3912 std::cerr << "initializing world ..." << std::endl;
43 :     }
44 :     if (wrld->init()) {
45 :     std::cerr << "Error initializing world:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
46 :     exit(1);
47 :     }
48 :    
49 :     #ifndef DIDEROT_NO_INPUTS
50 :     // initialize the input globals
51 : jhr 3916 if (init_inputs (wrld, &inputs)) {
52 : jhr 3912 std::cerr << "Error initializing inputs:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
53 :     exit(1);
54 :     }
55 :     #endif
56 :    
57 :     // run the generated global initialization code
58 : jhr 3916 if (wrld->_verbose) {
59 : jhr 3917 std::cerr << "initializing globals ...\n";
60 : jhr 3912 }
61 : jhr 3916 if (initially (wrld)) {
62 : jhr 3912 std::cerr << "Error in global initialization:\n%s\n"
63 :     << biffMsgStrGet(wrld->_errors) << std::endl;
64 :     exit(1);
65 :     }
66 :    
67 : jhr 3916 if (wrld->_verbose) {
68 : jhr 3917 std::cerr << "run with " << wrld->_num_strands << " strands ..." << std::endl;
69 : jhr 3912 }
70 :    
71 : jhr 3922 uint32_t nSteps = wrld->run (stepLimit);
72 : jhr 3912
73 : jhr 3916 if (wrld->_errors->errNum > 0) {
74 : jhr 3917 std::cerr << "Error during execution:\n%s\n" << biffMsgStrGet(wrld->_errors);
75 : jhr 3912 exit(1);
76 :     }
77 :    
78 : jhr 3916 if (wrld->_verbose) {
79 : jhr 3917 std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"
80 :     << std::endl;
81 : jhr 3912 }
82 :     else if (timingFlg) {
83 : jhr 3917 std::cout << "usr=" << wrld->_run_time << std::endl;
84 : jhr 3912 }
85 :    
86 :     // output the final strand states
87 : jhr 3917 write_outputs (wrld);
88 : jhr 3912
89 : jhr 3917 delete wrld;
90 : jhr 3912
91 :     return 0;
92 :    
93 :     } // main

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