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 3388 - (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 : lamonts 2416
11 : jhr 1806 @PREFIX@Globals_t *glob = wrld->globals;
12 : jhr 1717
13 :     if (maxNSteps == 0) maxNSteps = 0xffffffff; // essentially unlimited
14 :    
15 :     // iterate until all strands are stable
16 :     if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
17 : lamonts 2416
18 : lamonts 2562 //initialize the query pool if the program is using a query function.
19 :     //we store the queried strands in the pool.
20 :     #ifdef DIDEROT_SPATIAL_COM
21 : lamonts 3273 QueryListPool_t queryPool;
22 :     Diderot_Init_QueryListPool(&queryPool);
23 : lamonts 2562 double spatialT0 = airTime();
24 : lamonts 3388 if(!wrld->disableSOpt)
25 :     Diderot_KDTree_Build(wrld);
26 : lamonts 2562 double spatialTotalTime = (airTime() - spatialT0);
27 :     #endif
28 :    
29 : jhr 1717 uint32_t nSteps = 0, nUpdates = 0;
30 : jhr 1917 uint32_t nActive = wrld->numActive;
31 : lamonts 2467 uint32_t nStable = wrld->numStable;
32 : jhr 1916 while ((nActive > 0) && (nSteps < maxNSteps)) {
33 : jhr 1717 nSteps++;
34 :     // update strands
35 :     bool existsStabilizing = false;
36 : jhr 2298 for (uint32_t i = 0; i < wrld->numStrands; i++) {
37 : jhr 1717 if (! wrld->status[i]) {
38 : lamonts 2562 #ifdef DIDEROT_SPATIAL_COM
39 :     queryPool.handle = 0; //clear the query pool
40 :     StrandStatus_t sts = @STRAND@_Update(wrld, i,&queryPool);
41 :     #else
42 : jhr 2298 StrandStatus_t sts = @STRAND@_Update(wrld, i);
43 : lamonts 2562 #endif
44 : jhr 2298 // StrandStatus_t sts = @STRAND@_Update(glob, wrld->inState[i], wrld->outState[i],
45 :     // &wrld->inState,&wrld->outState,
46 : lamonts 2416 // &wrld->status, &wrld->poolInfo);
47 : jhr 1717 switch (sts) {
48 :     case DIDEROT_STABILIZE:
49 :     existsStabilizing = true;
50 :     wrld->status[i] = DIDEROT_STABILIZE;
51 : lamonts 3084 nStable++;
52 : jhr 1717 break;
53 :     case DIDEROT_DIE:
54 :     wrld->status[i] = DIDEROT_DIE;
55 : lamonts 2467 nActive--;
56 :     nStable++;
57 : jhr 1717 break;
58 :     default:
59 :     break;
60 :     }
61 :     }
62 :     }
63 : lamonts 3084
64 : jhr 1717 if (existsStabilizing) {
65 :     for (int i = 0; i < wrld->numStrands; i++) {
66 :     // NOTE: we may want to compact the array of strands
67 : lamonts 3084 if (wrld->status[i] == DIDEROT_STABILIZE || StabalizeAllStrands) {
68 : jhr 2298 #ifdef DIDEROT_DUAL_STATE
69 : jhr 1717 // stabilize the strand's state. Note that the outState has been set by
70 :     // the last call to update, so we make the inState be the target of the
71 :     // stabilize method.
72 : jhr 1807 @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
73 : jhr 1717 memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
74 : jhr 2298 #else
75 :     @STRAND@_Stabilize(glob, &wrld->state[i]);
76 :     #endif
77 : jhr 1717 wrld->status[i] = DIDEROT_STABLE;
78 :     nActive--;
79 :     }
80 :     }
81 :     }
82 : lamonts 2371 // Increase the number of active strands if new strands were created
83 :     if (wrld->poolInfo.nNewStrand > 0) {
84 :     nActive += wrld->poolInfo.nNewStrand;
85 :     wrld->numStrands += wrld->poolInfo.nNewStrand;
86 :     wrld->poolInfo.nNewStrand = 0;
87 : lamonts 2416 @REALLOC_SPATIAL_COPY_ARRAY@
88 :    
89 : lamonts 2371 }
90 : jhr 2298 #ifdef DIDEROT_DUAL_STATE
91 : jhr 1717 // swap in and out
92 :     @STRANDTY@ **tmp = wrld->inState;
93 :     wrld->inState = wrld->outState;
94 :     wrld->outState = tmp;
95 : jhr 2298 #endif
96 : lamonts 2210 /** Run the Global Block Phase */
97 : lamonts 2467 wrld->numActive = nActive;
98 :     wrld->numStable = nStable;
99 : lamonts 2511 @CALL_GLOBAL_BLOCK_FN@
100 : lamonts 3084 if (StabalizeAllStrands) {
101 :     for (int i = 0; i < wrld->numStrands; i++) {
102 :     // NOTE: we may want to compact the array of strands
103 :     if (wrld->status[i] == DIDEROT_ACTIVE) {
104 :     #ifdef DIDEROT_DUAL_STATE
105 :     // stabilize the strand's state. Note that the outState has been set by
106 :     // the last call to update, so we make the inState be the target of the
107 :     // stabilize method.
108 :     @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
109 :     memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
110 :     #else
111 :     @STRAND@_Stabilize(glob, &wrld->state[i]);
112 :     #endif
113 :     wrld->status[i] = DIDEROT_STABLE;
114 :     nActive--;
115 : lamonts 3334 nStable++;
116 : lamonts 3084 }
117 :     }
118 : lamonts 3334 wrld->numActive = nActive;
119 :     wrld->numStable = nStable;
120 : lamonts 3084 }
121 :    
122 :    
123 :    
124 : lamonts 2562 #ifdef DIDEROT_SPATIAL_COM
125 :     spatialT0 = airTime();
126 : lamonts 3388 if(!wrld->disableSOpt)
127 :     Diderot_KDTree_Build(wrld);
128 :     // int num = countTree(wrld->spatialTree->root);
129 : lamonts 3284 // printf("Number of Nodes = %d, Num of strands = %d\n",num, wrld->numStrands);
130 : lamonts 2562 spatialTotalTime = spatialTotalTime + (airTime() - spatialT0);
131 :     #endif
132 : jhr 1717 }
133 : lamonts 2622 #ifdef DIDEROT_SPATIAL_COM
134 : lamonts 2562 wrld->spatialTime = spatialTotalTime/nSteps;
135 : lamonts 2622 #endif
136 : jhr 1717 return nSteps;
137 :    
138 :     } // @PREFIX@Run
139 : lamonts 3084 void Diderot_Stabilize_All(@PREFIX@World_t *wrld)
140 :     {
141 :     for (uint32_t i = 0; i < wrld->numStrands; i++) {
142 :     wrld->status[i] = DIDEROT_STABILIZE;
143 :     }
144 :     }

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