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 4407 - (download) (annotate)
Fri Aug 12 13:33:46 2016 UTC (3 years ago) by jhr
File size: 2450 byte(s)
  working on merge: support for initially method (sequential target)
//! 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 < diderot::POST_CREATE) {
        biffMsgAdd (this->_errors, "attempt to run uninitialized program\n");
        return -1;
    }
    else if (this->_stage == diderot::DONE) {
        return 0;
    }
    else if (this->_stage == diderot::POST_CREATE) {
#ifdef DIDEROT_HAS_GLOBAL_INITIALLY
        this->global_initially();
#endif
        this->_stage = diderot::RUNNING;
    }
    assert (this->_stage == diderot::RUNNING);

#ifndef DIDEROT_NO_GLOBALS
    globals *glob = this->_globals;
#endif

    if (max_nsteps == 0) {
        max_nsteps = 0xffffffff;  // essentially unlimited
    }

    double t0 = airTime();

    if (this->_verbose) {
        std::cerr << "run with " << this->_nstrands << " strands ..." << std::endl;
    }

#ifdef DIDEROT_HAS_INITIALLY_METHOD
    this->run_initially();
#endif

  // iterate until all strands are stable
    uint32_t nStabilizing = 0;
    uint32_t nDying = 0;
    uint32_t maxSteps = 0;
    for (int i = 0;  i < this->_nstrands;  i++) {
        diderot::strand_status sts = static_cast<diderot::strand_status>(this->_status[i]);
        @STRANDTY@ *self = &this->_state[i];
        uint32_t nSteps = 0;
        while ((! sts) && (nSteps < max_nsteps)) {
            nSteps++;
            sts = @STRAND@_update(@UPDATE_ARGS@self);
        }
        switch (sts) {
          case diderot::kStabilize:
          // stabilize the strand's state.
#ifdef DIDEROT_HAS_STABILIZE
            @STRAND@_stabilize (@STABILIZE_ARGS@self);
#endif
            this->_status[i] = diderot::kStable;
            nStabilizing++;
            break;
          case diderot::kDie:
            this->_status[i] = diderot::kDead;
            nDying++;
            break;
          default:
            assert (sts == this->_status[i]);
            break;
        }
        if (maxSteps < nSteps) maxSteps = nSteps;
    }

    this->_nactive -= nStabilizing + nDying;
    this->_nstable += nStabilizing;

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

    if (this->_nactive == 0)
        this->_stage = diderot::DONE;

    return maxSteps;

} // world::run

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