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

SCM Repository

[diderot] Annotation of /branches/lamont/src/compiler/c-target/fragments/seq-run.in
ViewVC logotype

Annotation of /branches/lamont/src/compiler/c-target/fragments/seq-run.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (view) (download)

1 : jhr 1826 //! Run the Diderot program (sequential version)
2 : jhr 1717 //! \param wrld the world-state of the Diderot program
3 :     //! \param maxNSteps the limit on the number of super steps; 0 means unlimited
4 :     //! \return the number of steps taken.
5 :     uint32_t @PREFIX@Run (@PREFIX@World_t *wrld, uint32_t maxNSteps)
6 :     {
7 : jhr 2298 #ifdef DIDEROT_DUAL_STATE
8 : jhr 1717 Strand_t *strand = &(wrld->strandDesc[0]);
9 : jhr 2298 #endif
10 : jhr 1806 @PREFIX@Globals_t *glob = wrld->globals;
11 : jhr 1717
12 :     if (maxNSteps == 0) maxNSteps = 0xffffffff; // essentially unlimited
13 :    
14 :     // iterate until all strands are stable
15 :     if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
16 : lamonts 2191 @GRID_INIT@
17 : lamonts 2088 @BUILD_GRID@
18 : jhr 1717 uint32_t nSteps = 0, nUpdates = 0;
19 : jhr 1917 uint32_t nActive = wrld->numActive;
20 : jhr 1916 while ((nActive > 0) && (nSteps < maxNSteps)) {
21 : jhr 1717 nSteps++;
22 :     // update strands
23 :     bool existsStabilizing = false;
24 : jhr 2298 for (uint32_t i = 0; i < wrld->numStrands; i++) {
25 : jhr 1717 if (! wrld->status[i]) {
26 : jhr 2298 StrandStatus_t sts = @STRAND@_Update(wrld, i);
27 :     // StrandStatus_t sts = @STRAND@_Update(glob, wrld->inState[i], wrld->outState[i],
28 :     // &wrld->inState,&wrld->outState,
29 :     // &wrld->status, &wrld->poolInfo @PASS_GRID@);
30 : jhr 1717 switch (sts) {
31 :     case DIDEROT_STABILIZE:
32 :     existsStabilizing = true;
33 :     wrld->status[i] = DIDEROT_STABILIZE;
34 :     break;
35 :     case DIDEROT_DIE:
36 :     wrld->status[i] = DIDEROT_DIE;
37 :     nActive--;
38 :     break;
39 :     default:
40 :     break;
41 :     }
42 :     }
43 :     }
44 : lamonts 2191 @BUILD_GRID@
45 : jhr 1717 if (existsStabilizing) {
46 :     for (int i = 0; i < wrld->numStrands; i++) {
47 :     // NOTE: we may want to compact the array of strands
48 :     if (wrld->status[i] == DIDEROT_STABILIZE) {
49 : jhr 2298 #ifdef DIDEROT_DUAL_STATE
50 : jhr 1717 // stabilize the strand's state. Note that the outState has been set by
51 :     // the last call to update, so we make the inState be the target of the
52 :     // stabilize method.
53 : jhr 1807 @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
54 : jhr 1717 memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
55 : jhr 2298 #else
56 :     @STRAND@_Stabilize(glob, &wrld->state[i]);
57 :     #endif
58 : jhr 1717 wrld->status[i] = DIDEROT_STABLE;
59 :     nActive--;
60 :     }
61 :     }
62 :     }
63 : jhr 2298 #ifdef DIDEROT_DUAL_STATE
64 : jhr 1717 // swap in and out
65 :     @STRANDTY@ **tmp = wrld->inState;
66 :     wrld->inState = wrld->outState;
67 :     wrld->outState = tmp;
68 : jhr 2298 #endif
69 : lamonts 2210 /** Run the Global Block Phase */
70 : jhr 2298 @GLOBAL_BLOCK@
71 :     @GLOBAL_REDUCE@
72 : lamonts 2246
73 : jhr 2298 // Increase the number of active strands if new strands were created
74 :     if (wrld->poolInfo.nNewStrand > 0) {
75 : lamonts 2246 nActive += wrld->poolInfo.nNewStrand;
76 :     wrld->numActive += wrld->poolInfo.nNewStrand;
77 :     wrld->numStrands += wrld->poolInfo.nNewStrand;
78 :     wrld->poolInfo.nNewStrand = 0;
79 :    
80 :     }
81 :    
82 :    
83 : jhr 1717 }
84 : jhr 1917 wrld->numActive = nActive;
85 : jhr 1717
86 :     return nSteps;
87 :    
88 :     } // @PREFIX@Run

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