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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/c-target/fragments/par-run.in
ViewVC logotype

Diff of /branches/vis12/src/compiler/c-target/fragments/par-run.in

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

revision 1827, Thu Apr 12 14:37:41 2012 UTC revision 1828, Thu Apr 12 22:46:32 2012 UTC
# Line 7  Line 7 
7      Diderot_Sched_t *sched = wrld->sched;      Diderot_Sched_t *sched = wrld->sched;
8      Strand_t *strand = &(wrld->strandDesc[0]);      Strand_t *strand = &(wrld->strandDesc[0]);
9    
10      int nStrandsPerWorker = sched->numStrands / sched->numWorkers;      int nStrandsPerWorker = wrld->numStrands / sched->numWorkers;
11      int start = myArg->id * nStrandsPerWorker;      int start = myArg->id * nStrandsPerWorker;
12      int limit;      int limit;
13      if (sched->numWorkers-1 == myArg->id)      if (sched->numWorkers-1 == myArg->id)
# Line 15  Line 15 
15      else      else
16          limit = start + nStrandsPerWorker;          limit = start + nStrandsPerWorker;
17    
18      while (true) {      while ((sched->numActive) && (sched->numSteps <= myArg->maxNSteps)) {
19        // barrier synchronization at start of super step        // barrier synchronization at start of super step
20          pthread_mutex_lock (&sched->lock);          pthread_mutex_lock (&sched->lock);
21              if (sched->numIdle+1 < sched->numWorkers) {              if (sched->numIdle+1 < sched->numWorkers) {
# Line 25  Line 25 
25              else {              else {
26                // all other workers are idle, so we can proceed after some initialization                // all other workers are idle, so we can proceed after some initialization
27                  sched->numIdle = 0;                  sched->numIdle = 0;
28                  sched->numAvail = sched->numStrands;  // includes inactive strands                  sched->numAvail = wrld->numStrands;  // includes inactive strands
29                  sched->nextStrand = 0;                  sched->nextStrand = 0;
30                // swap in and out                // swap in and out
31                  void **tmp = wrld->inState;                  @STRANDTY@ **tmp = wrld->inState;
32                  wrld->inState = wrld->outState;                  wrld->inState = wrld->outState;
33                  wrld->outState = tmp;                  wrld->outState = tmp;
34                  pthread_cond_broadcast (&sched->barrier);                  pthread_cond_broadcast (&sched->barrier);
# Line 37  Line 37 
37    
38        // if there are no active strands left, then we're done        // if there are no active strands left, then we're done
39          if (sched->numActive == 0) {          if (sched->numActive == 0) {
40              pthread_cond_signal (&sched->mainWait);              pthread_cond_signal (&sched->runWait);
41              pthread_exit (0);              pthread_exit (0);
42          }          }
43    
# Line 86  Line 86 
86                // all other workers are idle, so we can proceed                // all other workers are idle, so we can proceed
87                  sched->numIdle = 0;                  sched->numIdle = 0;
88                  pthread_cond_broadcast (&sched->barrier);                  pthread_cond_broadcast (&sched->barrier);
89                  sched->nSteps++;                  sched->numSteps++;
90              }              }
91          pthread_mutex_unlock (&sched->lock);          pthread_mutex_unlock (&sched->lock);
92    
# Line 101  Line 101 
101                // stabilize the strand's state.  Note that the outState has been set by                // stabilize the strand's state.  Note that the outState has been set by
102                // the last call to update, so we make the inState be the target of the                // the last call to update, so we make the inState be the target of the
103                // stabilize method.                // stabilize method.
104                  strand->stabilize(wrld->outState[i], wrld->inState[i]);  //                strand->stabilize(glob, wrld->outState[i], wrld->inState[i]);
105                    @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
106                  memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);                  memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
107                  wrld->status[i] = DIDEROT_STABLE;                  wrld->status[i] = DIDEROT_STABLE;
108                  numStabilized++;                  numStabilized++;
# Line 115  Line 116 
116              sched->numActive -= numStabilized;              sched->numActive -= numStabilized;
117          pthread_mutex_unlock (&sched->lock);          pthread_mutex_unlock (&sched->lock);
118  #endif  #endif
119      } // end while(true)      } // end while
120    
121        return 0;
122    
123  }  }
124    
# Line 128  Line 131 
131      Diderot_Sched_t *sched = wrld->sched;      Diderot_Sched_t *sched = wrld->sched;
132    
133    // Start worker threads    // Start worker threads
134      int nWorkers = np;      int nWorkers = sched->numWorkers;
135      WorkerArg_t *args = NEWVEC(WorkerArg_t, nWorkers);      WorkerArg_t *args = NEWVEC(WorkerArg_t, nWorkers);
136      if (wrld->verboseFlg) fprintf (stderr, "initializing %d workers ...\n", nWorkers);      if (wrld->verboseFlg) fprintf (stderr, "initializing %d workers ...\n", nWorkers);
137      double t0 = airTime();      double t0 = airTime();
138      sched->numWorkers = nWorkers;      sched->numWorkers = nWorkers;
139      sched->numIdle = 0;      sched->numIdle = 0;
140        sched->numSteps = 0;
141      for (int i = 0; i < nWorkers; i++) {      for (int i = 0; i < nWorkers; i++) {
142          pthread_t pid;          pthread_t pid;
143          args[i].wrld = wrld;          args[i].wrld = wrld;
144          args[i].id = i;          args[i].id = i;
145          if (pthread_create (&pid, NULL, Worker, (void *)&(args[i])) != 0) {          if (pthread_create (&pid, NULL, @PREFIX@Worker, (void *)&(args[i])) != 0) {
146              fprintf (stderr, "unable to create worker thread\n");              fprintf (stderr, "unable to create worker thread\n");
147              exit (1);              exit (1);
148          }          }
# Line 147  Line 151 
151    
152    // wait for the computation to finish    // wait for the computation to finish
153      pthread_mutex_lock (&sched->lock);      pthread_mutex_lock (&sched->lock);
154          pthread_cond_wait (&sched->mainWait, &sched->lock);          pthread_cond_wait (&sched->runWait, &sched->lock);
155      pthread_mutex_unlock (&sched->lock);      pthread_mutex_unlock (&sched->lock);
156    
157      FREE(args);      FREE(args);
158    
159      return 0; /* FIXME: how many steps? */      return sched->numSteps;
160  }  }
161    

Legend:
Removed from v.1827  
changed lines
  Added in v.1828

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