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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1807 - (download) (annotate)
Sat Apr 7 12:00:48 2012 UTC (7 years, 8 months ago) by jhr
Original Path: branches/vis12/src/compiler/c-target/fragments/run.in
File size: 2524 byte(s)
  Added support for setting image inputs from nrrd objects; better propogation of
  errors; better use of world err field for error messages.
//! Run the Diderot program
//! \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.
uint32_t @PREFIX@Run (@PREFIX@World_t *wrld, uint32_t maxNSteps)
{
    Strand_t *strand = &(wrld->strandDesc[0]);
    @PREFIX@Globals_t *glob = wrld->globals;

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

  // iterate until all strands are stable
    if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
    uint32_t nSteps = 0, nUpdates = 0;
    uint32_t nActive = wrld->numStrands;
    while ((nActive > 0) && (nSteps <= maxNSteps)) {
        nSteps++;
      // update strands
        bool existsStabilizing = false;
        for (int i = 0;  i < wrld->numStrands;  i++) {
            if (! wrld->status[i]) {
                nUpdates++;
//              StrandStatus_t sts = strand->update(glob, wrld->inState[i], wrld->outState[i]);
                StrandStatus_t sts = @STRAND@_Update(glob, wrld->inState[i], wrld->outState[i]);
                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) {
                  // 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.
//                    strand->stabilize(glob, wrld->outState[i], wrld->inState[i]);
                    @STRAND@_Stabilize(glob, wrld->outState[i], wrld->inState[i]);
                    memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
                    wrld->status[i] = DIDEROT_STABLE;
                    nActive--;
                }
            }
        }
      // swap in and out
        @STRANDTY@ **tmp = wrld->inState;
        wrld->inState = wrld->outState;
        wrld->outState = tmp;
    }

    return nSteps;

} // @PREFIX@Run

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