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 4489 - (download) (annotate)
Sat Sep 3 00:32:03 2016 UTC (3 years, 1 month ago) by jhr
File size: 4027 byte(s)
working on merge: changing initially to start
//! 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_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_START
        this->global_start();
#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_START_METHOD
    this->run_start_methods();
#endif

  // iterate until all strands are stable
    uint32_t nSteps = 0;
    uint32_t nActive = this->_strands.num_active();
    while ((nActive > 0) && (nSteps < max_nsteps)) {
        nSteps++;
#ifdef DIDEROT_HAS_STRAND_COMMUNICATION
      // build spatial partition to support communication
        this->_tree->rebuild (this->_nstable + this->_nactive, this->_inState);
#endif
      // update strands
        uint32_t nStabilizing = 0;
	for (auto ix = this->_strands.begin_active();
	    ix != this->_strands.end_active();
	    ix = this->_strands.next_active(ix))
	{
#ifdef DIDEROT_DUAL_STATE
	    diderot::strand_status sts = @STRAND@_update(@UPDATE_ARGS@
		this->_strands.local_state(ix),
		this->_strands.in_state(ix),
		this->_strands.out_state(ix));
#else
	    diderot::strand_status sts = @STRAND@_update(@UPDATE_ARGS@
		this->_strands.strand(ix));
#endif
	    switch (sts) {
	      case diderot::kStabilize:
		this->_strands._status[ix] = diderot::kStabilize;
		nStabilizing++;
		break;
	      case diderot::kDie:
		this->_strands._status[ix] = 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) {
#if defined(DIDEROT_HAS_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.
#  ifdef DIDEROT_DUAL_STATE
                    @STRAND@_stabilize(@STABILIZE_ARGS@&this->_outState[i], &this->_inState[i]);
#    if defined(DIDEROT_HAS_STRAND_COMMUNICATION) || defined(DIDEROT_HAS_MAPREDUCE)
                  // need to copy stable input state to output so that subsequent queries/reductions work
                    std::memcpy (&this->_outState[i], &this->_inState[i], sizeof(@STRAND@_strand));
#    endif
#  else
                    @STRAND@_stabilize(@STABILIZE_ARGS@&this->_state[i]);
#  endif
#elif defined(DIDEROT_DUAL_STATE)
                  // need to copy output state to input so that subsequent queries/reductions work
                    std::memcpy (&this->_inState[i], &this->_outState[i], sizeof(@STRAND@_strand));
#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