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 1518, Sat Oct 8 02:39:41 2011 UTC revision 1519, Sun Oct 9 18:30:16 2011 UTC
# Line 8  Line 8 
8   * All rights reserved.   * All rights reserved.
9   */   */
10    
 #include <string.h>  
 #include <stdio.h>  
 #include <assert.h>  
11  #include <Diderot/diderot.h>  #include <Diderot/diderot.h>
12  #include <pthread.h>  #include <pthread.h>
13  #include <teem/nrrd.h>  #include <teem/nrrd.h>
# Line 32  Line 29 
29  #define BLOCK_SIZE 256  #define BLOCK_SIZE 256
30    
31  struct struct_world {  struct struct_world {
32      const char          *name;          // the program name      STRUCT_WORLD_PREFIX
     bool                isArray;        // is the initialization an array or collection?  
     uint32_t            nDims;          // depth of iteration nesting  
     int32_t             *base;          // nDims array of base indices  
     uint32_t            *size;          // nDims array of iteration sizes  
     uint32_t            numStrands;     // number of strands in the world  
33      void                **inState;      void                **inState;
34      void                **outState;      void                **outState;
     uint8_t             *status;        // array of strand status flags  
35      uint32_t            numWorkers;     // number of worker threads      uint32_t            numWorkers;     // number of worker threads
36      uint32_t            nSteps;         // number of super steps      uint32_t            nSteps;         // number of super steps
37    // synchronization state    // synchronization state
# Line 120  Line 111 
111                      StrandStatus_t sts = Diderot_Strands[0]->update(wrld->inState[i], wrld->outState[i]);                      StrandStatus_t sts = Diderot_Strands[0]->update(wrld->inState[i], wrld->outState[i]);
112                      switch (sts) {                      switch (sts) {
113                        case DIDEROT_STABILIZE:                        case DIDEROT_STABILIZE:
                         Diderot_Strands[0]->stabilize(wrld->inState[i], wrld->outState[i]);  
114                          wrld->status[i] = DIDEROT_STABILIZE;                          wrld->status[i] = DIDEROT_STABILIZE;
115                          break;                          break;
116                        case DIDEROT_DIE:                        case DIDEROT_DIE:
# Line 156  Line 146 
146    
147        // stabilize any threads that need stabilization.  Each worker is responsible for        // stabilize any threads that need stabilization.  Each worker is responsible for
148        // a contiguous region of the strands        // a contiguous region of the strands
149  // FIXME: once we switch to dynamic lists of strand blocks, then we use finer-grain  // FIXME: once we switch to dynamic lists of strand blocks, then we can use finer-grain tracking
 // tracking  
150          int numStabilized = 0;          int numStabilized = 0;
151          for (int i = start;  i < limit;  i++) {          for (int i = start;  i < limit;  i++) {
152              if (wrld->status[i] == DIDEROT_STABILIZE) {              if (wrld->status[i] == DIDEROT_STABILIZE) {
153                // copy out to in so that both copies are the stable state                // stabilize the strand's state.  Note that the outState has been set by
154                  memcpy (wrld->inState[i], wrld->outState[i], Diderot_Strands[0]->stateSzb);                // the last call to update, so we make the inState be the target of the
155                  // stabilize method.
156                    Diderot_Strands[0]->stabilize(wrld->outState[i], wrld->inState[i]);
157                    memcpy (wrld->outState[i], wrld->inState[i], Diderot_Strands[0]->stateSzb);
158                  wrld->status[i] = DIDEROT_STABLE;                  wrld->status[i] = DIDEROT_STABLE;
159                  numStabilized++;                  numStabilized++;
160              }              }
# Line 242  Line 234 
234          printf ("np=%d usr=%f\n", nWorkers, totalTime);          printf ("np=%d usr=%f\n", nWorkers, totalTime);
235    
236    // output the final strand states    // output the final strand states
     Output_Args_t outArgs;  
     outArgs.name = wrld->name;  
     outArgs.isArray = wrld->isArray;  
     outArgs.numStrands = wrld->numStrands;  
     outArgs.status = wrld->status;  
     outArgs.inState = wrld->inState;  
     outArgs.nDims = wrld->nDims;  
     outArgs.size = wrld->size;  
     outArgs.outputSzb =  Diderot_Strands[0]->outputSzb;  
237      if (NrrdOutputFlg)      if (NrrdOutputFlg)
238          Diderot_Output (&outArgs);          Diderot_Output (wrld, Diderot_Strands[0]->outputSzb);
239      else      else
240          Diderot_Print (&outArgs);          Diderot_Print (wrld);
241    
242      Diderot_Shutdown (wrld);      Diderot_Shutdown (wrld);
243    
# Line 262  Line 245 
245    
246  }  }
247    
   
 // this should be the part of the scheduler  
 void *Diderot_AllocStrand (Strand_t *strand)  
 {  
     return CheckedAlloc(strand->stateSzb);  
 }  
   
248  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
249  Diderot_World_t *Diderot_AllocInitially (  Diderot_World_t *Diderot_AllocInitially (
250      const char *name,           // the name of the program      const char *name,           // the name of the program
# Line 313  Line 289 
289    
290    // initialize strand state pointers etc.    // initialize strand state pointers etc.
291      for (size_t i = 0;  i < numStrands;  i++) {      for (size_t i = 0;  i < numStrands;  i++) {
292          wrld->inState[i] = Diderot_AllocStrand (strand);          wrld->inState[i] = CheckedAlloc (strand->stateSzb);
293          wrld->outState[i] = Diderot_AllocStrand (strand);          wrld->outState[i] = CheckedAlloc (strand->stateSzb);
294          wrld->status[i] = DIDEROT_ACTIVE;          wrld->status[i] = DIDEROT_ACTIVE;
295      }      }
296    
# Line 338  Line 314 
314      assert (i < wrld->numStrands);      assert (i < wrld->numStrands);
315      return wrld->outState[i];      return wrld->outState[i];
316  }  }
   
 bool Diderot_IsActive (Diderot_World_t *wrld, uint32_t i)  
 {  
     assert (i < wrld->numStrands);  
     return !wrld->status[i];  
 }  

Legend:
Removed from v.1518  
changed lines
  Added in v.1519

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