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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/c-target/fragments/seq-run-nobsp.in
ViewVC logotype

View of /branches/vis12-cl/src/compiler/c-target/fragments/seq-run-nobsp.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3226 - (download) (annotate)
Thu Jul 23 11:33:34 2015 UTC (6 years ago) by jhr
File size: 2084 byte(s)
  Build improvements for documentation; merged some doc changes from vis12; fixed error
  reporting/return status when running a Diderot program.
//! Run the Diderot program (sequential version without BSP semantics)
//! \param wrld the world-state of the Diderot program
//! \param maxNSteps the limit on the number of super steps; 0 means unlimited
//! \return the number of steps taken, or -1 on error.
uint32_t @PREFIX@Run (@PREFIX@World_t *wrld, uint32_t maxNSteps)
{
    if (wrld->stage < POST_INITIALLY) {
	biffMsgAdd (wrld->errors, "attempt to run uninitialized program\n");
	return -1;
    }
    wrld->stage = RUNNING;    

#ifndef DIDEROT_NO_GLOBALS
    @PREFIX@Globals_t *glob = wrld->globals;
#endif

    if (maxNSteps == 0) maxNSteps = 0xffffffff;  // essentially unlimited

    double t0 = airTime();

  // iterate until all strands are stable
    if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
    uint32_t nActive = wrld->numActive;
    uint32_t maxStepsTaken = 0;
    for (int i = 0;  i < wrld->numStrands;  i++) {
	uint32_t nSteps = 0;
	uint32_t limit = maxNSteps;
	StrandStatus_t sts = wrld->status[i];
	@STRANDTY@ *self = &wrld->state[i];
	while ((! sts) && (limit-- > 0)) {
#ifdef DIDEROT_NO_GLOBALS
	    sts = @STRAND@_Update(self);
#else
	    sts = @STRAND@_Update(glob, self);
#endif
        }
        switch (sts) {
          case DIDEROT_STABILIZE:
          // stabilize the strand's state.
#ifdef DIDEROT_NO_GLOBALS
            @STRAND@_Stabilize (self);
#else
            @STRAND@_Stabilize (glob, self);
#endif
            wrld->status[i] = DIDEROT_STABLE;
            nActive--;
            break;
          case DIDEROT_DIE:
            wrld->status[i] = DIDEROT_DIE;
            nActive--;
            break;
          default:
            assert (sts == wrld->status[i]);
            break;
        }
	if ((maxNSteps - limit) > maxStepsTaken)
	    maxStepsTaken = maxNSteps - limit;
    }

    wrld->numActive = nActive;

    t0 = airTime() - t0;
    if (wrld->verboseFlg) {
        fprintf (stderr, "done in %f seconds\n", t0);
    }
    wrld->runTime += t0;

    if (wrld->numActive == 0)
	wrld->stage = DONE;

    return maxStepsTaken;

} // @PREFIX@Run

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