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.in
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3226 - (download) (annotate)
Thu Jul 23 11:33:34 2015 UTC (4 years, 2 months ago) by jhr
File size: 3670 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)
//! \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;
    }
#ifdef DIDEROT_HAS_INITIALLY_METHOD
    else if (wrld->stage == POST_INITIALLY) {
	@PREFIX@RunInitially (@PREFIX@World_t wrld);
    }
#endif
    wrld->stage = RUNNING;    

#ifdef DIDEROT_DUAL_STATE
    Strand_t *strand = &(wrld->strandDesc[0]);
#endif
#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 nSteps = 0;
    uint32_t nActive = wrld->numActive;
    while ((nActive > 0) && (nSteps < maxNSteps)) {
        nSteps++;
      // update strands
        bool existsStabilizing = false;
        for (int i = 0;  i < wrld->numStrands;  i++) {
            if (! wrld->status[i]) {
#ifdef DIDEROT_DUAL_STATE
# ifdef DIDEROT_NO_GLOBALS
                StrandStatus_t sts = @STRAND@_Update(wrld->inState[i], wrld->outState[i]);
# else
                StrandStatus_t sts = @STRAND@_Update(glob, wrld->inState[i], wrld->outState[i]);
# endif
#else
# ifdef DIDEROT_NO_GLOBALS
                StrandStatus_t sts = @STRAND@_Update(&wrld->state[i]);
# else
                StrandStatus_t sts = @STRAND@_Update(glob, &wrld->state[i]);
# endif
#endif
                switch (sts) {
                  case DIDEROT_STABILIZE:
                    existsStabilizing = true;
                    wrld->status[i] = DIDEROT_STABILIZE;
                    break;
                  case DIDEROT_DIE:
                    wrld->status[i] = DIDEROT_DIE;
                    nActive--;
                    break;
                  default:
                    break;
                }
            }
        }
        if (existsStabilizing) {
            for (int i = 0;  i < wrld->numStrands;  i++) {
// NOTE: we may want to compact the array of strands
                if (wrld->status[i] == DIDEROT_STABILIZE) {
#ifdef DIDEROT_DUAL_STATE
                  // stabilize the strand's state.  Note that the outState has been set by
                  // the last call to update, so we make the inState be the target of the
                  // stabilize method.
# ifdef DIDEROT_NO_GLOBALS
                    @STRAND@_Stabilize(wrld->outState[i], wrld->inState[i]);
# else
                    @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
# endif
                    memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
#else
# ifdef DIDEROT_NO_GLOBALS
                    @STRAND@_Stabilize(&wrld->state[i]);
# else
                    @STRAND@_Stabilize(glob, &wrld->state[i]);
# endif
#endif
                    wrld->status[i] = DIDEROT_STABLE;
                    nActive--;
                }
            }
        }
#ifdef DIDEROT_DUAL_STATE
      // swap in and out
        @STRANDTY@ **tmp = wrld->inState;
        wrld->inState = wrld->outState;
        wrld->outState = tmp;
#endif
    }
    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 nSteps;

} // @PREFIX@Run

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