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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/target-cpu/fragments/seq-run-nobsp.in
ViewVC logotype

View of /branches/vis15/src/compiler/target-cpu/fragments/seq-run-nobsp.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3908 - (download) (annotate)
Tue May 24 14:33:23 2016 UTC (3 years, 1 month ago) by jhr
File size: 2208 byte(s)
working on merge: runtime and code generation
//! Run the Diderot program (sequential version without BSP semantics)
//! \param max_nsteps the limit on the number of super steps; 0 means unlimited
//! \return the number of steps taken, or -1 on error.
uint32_t world::run (uint32_t max_nsteps)
{
    if (this->_stage < POST_INITIALLY) {
        biffMsgAdd (this->_errors, "attempt to run uninitialized program\n");
        return -1;
    }
    this->_stage = RUNNING;

#ifndef DIDEROT_NO_GLOBALS
    @PREFIX@Globals_t *glob = this->_globals;
#endif

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

    double t0 = airTime();

  // iterate until all strands are stable
    if (this->_verboseFlg) {
	std::cerr << "run with " << this->_numStrands << " strands ..." << std::endl;
    }
    uint32_t nStabilizing = 0;
    uint32_t nDying = 0;
    uint32_t maxSteps = 0;
    for (int i = 0;  i < this->_numStrands;  i++) {
        StrandStatus_t sts = this->_status[i];
        @STRANDTY@ *self = &this->_state[i];
#ifdef DIDEROT_HAS_INITIALLY_METHOD
        this->run_initially();
#endif
        uint32_t nSteps = 0;
        while ((! sts) && (nSteps < max_nsteps)) {
	    nSteps++;
#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
            this->_status[i] = DIDEROT_STABLE;
            nStabilizing++;
            break;
          case DIDEROT_DIE:
            this->_status[i] = DIDEROT_DEAD;
            nDying++;
            break;
          default:
            assert (sts == this->_status[i]);
            break;
        }
        if (maxSteps < nSteps) maxSteps = nSteps;
    }

    this->_numActive -= nStabilizing + nDying;
    this->_numStable += nStabilizing;

    t0 = airTime() - t0;
    if (this->_verboseFlg) {
	std::cerr << "done in " << t0 << seconds" << std::endl;
    }
    this->_runTime += t0;

    if (this->_numActive == 0)
        this->_stage = DONE;

    return maxSteps;

} // @PREFIX@Run

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