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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/lib/parallel-target/main.c
ViewVC logotype

Diff of /branches/pure-cfg/src/lib/parallel-target/main.c

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

revision 1216, Sat May 14 06:04:13 2011 UTC revision 1262, Sat May 28 23:45:43 2011 UTC
# Line 56  Line 56 
56      Diderot_World_t     *wrld;      Diderot_World_t     *wrld;
57  } WorkerArg_t;  } WorkerArg_t;
58    
59    // NOTE: we probably should put this in a file that supports runtime printing
60    static bool     VerboseFlg = false;
61    
62  /* Function which processes active strands. */  /* Function which processes active strands. */
63  static void *Worker (void *arg)  static void *Worker (void *arg)
64  {  {
# Line 173  Line 176 
176    
177  int main (int argc, const char **argv)  int main (int argc, const char **argv)
178  {  {
179      fprintf (stderr, "initializing globals ...\n");      CPUInfo_t cpuInfo;
180        if (! GetNumCPUs (&cpuInfo)) {
181            fprintf(stderr, "unable to get number of processors\n");
182            exit (1);
183        }
184    
185        Diderot_int_t np = cpuInfo.numHWCores;
186    
187        Diderot_Options_t *opts = Diderot_OptNew ();
188    
189        Diderot_OptAddFlag (opts, "verbose", "enable printing of runtime messages", &VerboseFlg);
190        Diderot_OptAddInt (opts, "np", "specify number of threads", &np, true);
191        Diderot_RegisterGlobalOpts (opts);
192        Diderot_OptProcess (opts, argc, argv);
193        Diderot_OptFree (opts);
194    
195        if (VerboseFlg) fprintf (stderr, "initializing globals ...\n");
196      Diderot_InitGlobals (argc, argv);      Diderot_InitGlobals (argc, argv);
197    
198      fprintf (stderr, "initializing strands ...\n");      if (VerboseFlg) fprintf (stderr, "initializing strands ...\n");
199      Diderot_World_t *wrld = Diderot_Initially ();      Diderot_World_t *wrld = Diderot_Initially ();
200      for (int i = 0;  i < wrld->numStrands;  i++) {      for (int i = 0;  i < wrld->numStrands;  i++) {
201        // hack to make the invariant part of the state the same in both copies        // hack to make the invariant part of the state the same in both copies
202          memcpy (wrld->outState[i], wrld->inState[i], Diderot_Strands[0]->stateSzb);          memcpy (wrld->outState[i], wrld->inState[i], Diderot_Strands[0]->stateSzb);
203      }      }
204    
     CPUInfo_t cpuInfo;  
     if (! GetNumCPUs (&cpuInfo)) {  
         fprintf(stderr, "unable to get number of processors\n");  
         exit (1);  
     }  
   
205    // Start worker threads    // Start worker threads
206      int nWorkers = cpuInfo.numHWCores;      int nWorkers = np;
207      WorkerArg_t *args = (WorkerArg_t *) malloc (nWorkers * sizeof(WorkerArg_t));      WorkerArg_t *args = (WorkerArg_t *) malloc (nWorkers * sizeof(WorkerArg_t));
208      printf ("initializing %d workers ...\n", nWorkers);      if (VerboseFlg) printf ("initializing %d workers ...\n", nWorkers);
209      wrld->numWorkers = nWorkers;      wrld->numWorkers = nWorkers;
210      wrld->numIdle = 0;      wrld->numIdle = 0;
211      for (int i = 0; i < nWorkers; i++) {      for (int i = 0; i < nWorkers; i++) {
# Line 211  Line 224 
224          pthread_cond_wait (&wrld->mainWait, &wrld->lock);          pthread_cond_wait (&wrld->mainWait, &wrld->lock);
225      pthread_mutex_unlock (&wrld->lock);      pthread_mutex_unlock (&wrld->lock);
226    
227  fprintf (stderr, "done: %d steps\n", wrld->nSteps);  if (VerboseFlg) fprintf (stderr, "done: %d steps\n", wrld->nSteps);
228    // here we have the final state of all of the strands in the "in" buffer    // here we have the final state of all of the strands in the "in" buffer
229      FILE *outS = fopen("mip.txt", "w");      FILE *outS = fopen("mip.txt", "w");
230      if (outS == NULL) {      if (outS == NULL) {
# Line 263  Line 276 
276          wrld->size[i] = size[i];          wrld->size[i] = size[i];
277      }      }
278    
279  fprintf(stderr, "AllocInitially: %d", size[0]);  if (VerboseFlg) {
280  for (int i = 1;  i < nDims;  i++)      printf("AllocInitially: %d", size[0]);
281      fprintf(stderr, " x %d", size[i]);      for (int i = 1;  i < nDims;  i++) printf(" x %d", size[i]);
282  fprintf(stderr, "\n");      printf("\n");
283    }
284    
285    // allocate the strand state pointers    // allocate the strand state pointers
286      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;

Legend:
Removed from v.1216  
changed lines
  Added in v.1262

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