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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4418, Wed Aug 17 12:49:10 2016 UTC revision 4797, Mon Oct 24 16:59:27 2016 UTC
# Line 6  Line 6 
6  {  {
7      bool        timingFlg = false;      //! true if timing computation      bool        timingFlg = false;      //! true if timing computation
8      uint32_t    stepLimit = 0;          //! limit on number of execution steps (0 means unlimited)      uint32_t    stepLimit = 0;          //! limit on number of execution steps (0 means unlimited)
9        std::string printFile = "-";        //! file to direct printed output into
10        uint32_t    reqNumWorkers;          //! requested number of worker threads
11    #ifdef DIDEROT_EXEC_SNAPSHOT
12        uint32_t    snapshotPeriod = 1;     //! supersteps per snapshot
13    #endif
14        uint32_t    nSteps = 0;             //! number of supersteps taken
15    
16    // create the world    // create the world
17      world *wrld = new (std::nothrow) world();      world *wrld = new (std::nothrow) world();
# Line 14  Line 20 
20          exit (1);          exit (1);
21      }      }
22    
23      // get CPU info
24        if (wrld->_sched->get_cpu_info (wrld)) {
25            std::cerr << "Error creating workers:\n" << wrld->get_errors() << std::endl;
26            exit (1);
27        }
28    
29  #ifndef DIDEROT_NO_INPUTS  #ifndef DIDEROT_NO_INPUTS
30    // initialize the default values for the inputs    // initialize the default values for the inputs
31      cmd_line_inputs inputs;      cmd_line_inputs inputs;
# Line 23  Line 35 
35    // handle command-line options    // handle command-line options
36      {      {
37          diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();          diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();
38          uint32_t np = wrld->_sched->_numWorkers;          reqNumWorkers = wrld->_sched->_numHWCores;
         opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));  
         opts->addFlag ("t,timing", "enable execution timing", &timingFlg);  
         opts->add ("n,nworkers", "specify number of worker threads", &np, true);  
39          opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",          opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",
40              &stepLimit, true);              &stepLimit, true);
41    #ifdef DIDEROT_EXEC_SNAPSHOT
42            opts->add ("s,snapshot",
43                "specify number of super-steps per snapshot (0 means no snapshots)",
44                &snapshotPeriod, true);
45    #endif
46            opts->add ("print", "specify where to direct printed output", &printFile, true);
47            opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));
48            opts->addFlag ("t,timing", "enable execution timing", &timingFlg);
49            opts->add ("n,nworkers", "specify number of worker threads", &reqNumWorkers, true);
50  #ifndef DIDEROT_NO_INPUTS  #ifndef DIDEROT_NO_INPUTS
51        // register options for setting global inputs        // register options for setting global inputs
52          register_inputs (&inputs, opts);          register_inputs (&inputs, opts);
# Line 36  Line 54 
54          register_outputs (opts);          register_outputs (opts);
55          opts->process (argc, argv);          opts->process (argc, argv);
56          delete opts;          delete opts;
57          wrld->_sched->_numWorkers = np;      }
58    
59      // redirect printing (if necessary)
60        if (printFile.compare("-") != 0) {
61            wrld->_printTo = new std::ofstream (printFile);
62            if (wrld->_printTo->fail()) {
63                std::cerr << "Error opening print file" << std::endl;
64                exit(1);
65            }
66      }      }
67    
68    // initialize scheduler stuff    // initialize scheduler stuff
# Line 44  Line 70 
70          std::cerr << "initializing world ..." << std::endl;          std::cerr << "initializing world ..." << std::endl;
71      }      }
72      if (wrld->init()) {      if (wrld->init()) {
73          std::cerr << "Error initializing world:\n" << biffMsgStrGet(wrld->_errors) << std::endl;          std::cerr << "Error initializing world:\n" << wrld->get_errors() << std::endl;
74            exit(1);
75        }
76        if (wrld->_sched->create_workers (wrld, reqNumWorkers)) {
77            std::cerr << "Error creating workers:\n" << wrld->get_errors() << std::endl;
78          exit(1);          exit(1);
79      }      }
80    
81  #ifndef DIDEROT_NO_INPUTS  #ifndef DIDEROT_NO_INPUTS
82    // initialize the input globals    // initialize the input globals
83      if (init_inputs (wrld, &inputs)) {      if (init_inputs (wrld, &inputs)) {
84          std::cerr << "Error initializing inputs:\n" << biffMsgStrGet(wrld->_errors) << std::endl;          std::cerr << "Error initializing inputs:\n" << wrld->get_errors() << std::endl;
85          exit(1);          exit(1);
86      }      }
87  #endif  #endif
# Line 62  Line 92 
92      }      }
93      if (wrld->create_strands()) {      if (wrld->create_strands()) {
94          std::cerr << "Error in global initialization:\n"          std::cerr << "Error in global initialization:\n"
95              << biffMsgStrGet(wrld->_errors) << std::endl;              << wrld->get_errors() << std::endl;
96          exit(1);          exit(1);
97      }      }
98    
99      uint32_t nSteps = wrld->run (stepLimit);  #ifdef DIDEROT_EXEC_SNAPSHOT
100    
101        if (snapshotPeriod > 0) {
102         // write initial state as snapshot 0
103            write_snapshot (wrld, "-0000");
104         // run the program for `snapshotPeriod` steps at a time with a snapshot after each run
105            while (true) {
106                uint32_t n, limit;
107              // determine a step limit for the next run
108                if (stepLimit > 0) {
109                    if (stepLimit <= nSteps) {
110                        break;
111                    }
112                    limit = std::min(stepLimit - nSteps, snapshotPeriod);
113                }
114                else {
115                    limit = snapshotPeriod;
116                }
117              // run the program for upto limit steps
118                if ((n = wrld->run (limit)) == 0) {
119                    break;
120                }
121                nSteps += n;
122                if ((wrld->_errors->errNum > 0) || (wrld->_strands.num_alive() == 0)) {
123                    break;
124                }
125              // write a snapshot with the step count as a suffix
126                std::string suffix = std::to_string(nSteps);
127                if (suffix.length() < 4) {
128                    suffix = std::string("0000").substr(0, 4 - suffix.length()) + suffix;
129                }
130                suffix = "-" + suffix;
131                write_snapshot (wrld, suffix);
132            }
133        }
134        else {
135            nSteps = wrld->run (stepLimit);
136        }
137    
138    #else // !DIDEROT_EXEC_SNAPSHOT
139    
140        nSteps = wrld->run (stepLimit);
141    
142    #endif // DIDEROT_EXEC_SNAPSHOT
143    
144      if (wrld->_errors->errNum > 0) {      if (wrld->_errors->errNum > 0) {
145          std::cerr << "Error during execution:\n" << biffMsgStrGet(wrld->_errors) << std::endl;          std::cerr << "Error during execution:\n" << wrld->get_errors() << std::endl;
146          exit(1);          exit(1);
147      }      }
148    
149        if ((stepLimit != 0) && (wrld->_strands.num_active() > 0)) {
150    #ifdef DIDEROT_STRAND_ARRAY
151            if (wrld->_verbose) {
152                std::cerr << "Step limit expired; "
153                    << wrld->_strands.num_active() << " active strands remaining" << std::endl;
154            }
155    #else
156          // step limit expired, so kill remaining strands
157            if (wrld->_verbose) {
158                std::cerr << "Step limit expired. Killing remaining "
159                    << wrld->_strands.num_active() << " active strands" << std::endl;
160            }
161            wrld->kill_all();
162    #endif
163        }
164    
165      if (wrld->_verbose) {      if (wrld->_verbose) {
166          std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"          std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"
167              << std::endl;              << std::endl;

Legend:
Removed from v.4418  
changed lines
  Added in v.4797

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