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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1718 - (view) (download)

1 : jhr 1717 //! Run the Diderot program
2 :     //! \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 :     Strand_t *strand = &(wrld->strandDesc[0]);
8 :    
9 :     if (maxNSteps == 0) maxNSteps = 0xffffffff; // essentially unlimited
10 :    
11 :     // iterate until all strands are stable
12 :     if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
13 :     uint32_t nSteps = 0, nUpdates = 0;
14 :     uint32_t nActive = wrld->numStrands;
15 :     while ((nActive > 0) && (nSteps <= maxNSteps)) {
16 :     nSteps++;
17 :     // update strands
18 :     bool existsStabilizing = false;
19 :     for (int i = 0; i < wrld->numStrands; i++) {
20 :     if (! wrld->status[i]) {
21 :     nUpdates++;
22 :     StrandStatus_t sts = strand->update(wrld->inState[i], wrld->outState[i]);
23 :     switch (sts) {
24 :     case DIDEROT_STABILIZE:
25 :     existsStabilizing = true;
26 :     wrld->status[i] = DIDEROT_STABILIZE;
27 :     break;
28 :     case DIDEROT_DIE:
29 :     wrld->status[i] = DIDEROT_DIE;
30 :     nActive--;
31 :     break;
32 :     default:
33 :     break;
34 :     }
35 :     }
36 :     }
37 :     if (existsStabilizing) {
38 :     for (int i = 0; i < wrld->numStrands; i++) {
39 :     // NOTE: we may want to compact the array of strands
40 :     if (wrld->status[i] == DIDEROT_STABILIZE) {
41 :     // stabilize the strand's state. Note that the outState has been set by
42 :     // the last call to update, so we make the inState be the target of the
43 :     // stabilize method.
44 :     strand->stabilize(wrld->outState[i], wrld->inState[i]);
45 :     memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
46 :     wrld->status[i] = DIDEROT_STABLE;
47 :     nActive--;
48 :     }
49 :     }
50 :     }
51 :     // swap in and out
52 :     @STRANDTY@ **tmp = wrld->inState;
53 :     wrld->inState = wrld->outState;
54 :     wrld->outState = tmp;
55 :     }
56 :    
57 :     return nSteps;
58 :    
59 :     } // @PREFIX@Run

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