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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4351 - (download) (annotate)
Wed Aug 3 01:15:46 2016 UTC (3 years, 3 months ago) by jhr
File size: 3298 byte(s)
  Working on merge: spatial query support
//! Run the Diderot program (sequential version)
//! \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_INITIALLY) {
        biffMsgAdd (this->_errors, "attempt to run uninitialized program\n");
        return -1;
    }
#ifdef DIDEROT_HAS_INITIALLY_METHOD
    else if (this->_stage == diderot::POST_INITIALLY) {
        this->run_initially();
    }
#endif
    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();

  // iterate until all strands are stable
    if (this->_verbose) {
        std::cerr << "run with " << this->_nstrands << " strands ..." << std::endl;
    }
    uint32_t nSteps = 0;
    uint32_t nActive = this->_nactive;
    while ((nActive > 0) && (nSteps < max_nsteps)) {
        nSteps++;
      // update strands
        uint32_t nStabilizing = 0;
        for (int i = 0;  i < this->_nstrands;  i++) {
            if (! this->_status[i]) {
#ifdef DIDEROT_DUAL_STATE
                diderot::strand_status sts =
                    @STRAND@_update(@UPDATE_ARGS@&this->_inState[i], &this->_outState[i]);
#else
                diderot::strand_status sts = @STRAND@_update(@UPDATE_ARGS@&this->_state[i]);
#endif
                switch (sts) {
                  case diderot::kStabilize:
                    this->_status[i] = diderot::kStabilize;
                    nStabilizing++;
                    break;
                  case diderot::kDie:
                    this->_status[i] = diderot::kDead;
                    nActive--;
                    break;
                  default:
                    break;
                }
            }
        }
        if (nStabilizing > 0) {
            this->_nstable += nStabilizing;
            nActive -= nStabilizing;
            for (int i = 0;  (nStabilizing > 0) && (i < this->_nstrands);  i++) {
// NOTE: we may want to compact the array of strands
                if (this->_status[i] == diderot::kStabilize) {
#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.
                    @STRAND@_stabilize(
                        @STABILIZE_ARGS@&this->_outState[i], &this->_inState[i]);
                    std::memcpy (&this->_outState[i], &this->_inState[i], sizeof(@STRAND@_strand));
#else
                    @STRAND@_stabilize(@STABILIZE_ARGS@&this->_state[i]);
#endif
                    this->_status[i] = diderot::kStable;
                    nStabilizing--;
                }
            }
        }
#ifdef DIDEROT_HAS_GLOBAL_UPDATE
        this->global_update();
#endif
        this->swap_state();
    }
    this->_nactive = nActive;

    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 nSteps;

} // world::run

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