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

View of /branches/vis15/src/compiler/target-cpu/fragments/par-worker.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4907 - (download) (annotate)
Thu Jan 26 22:33:34 2017 UTC (2 years, 6 months ago) by jhr
File size: 3744 byte(s)
  working on merge: parallel + communication
struct CACHE_ALIGN worker_arg {
    world       *_wrld;         //!< world pointer
    uint32_t    _id;            //!< worker ID
    uint32_t    _maxNSteps;     //!< maximum number of steps to take; 0 == infinity
    uint32_t    _nSteps;        //!< max number of steps taken by a strand in call to run
    uint32_t    _nStable;       //!< number of strands that stabilized in call to run
    uint32_t    _nDead;         //!< number of strands that died in call to run
    strand_array::worker_cache _strands;
};

/* Function which processes active strands. */
static void worker (void *arg)
{
    worker_arg *myArg = reinterpret_cast<worker_arg *>(arg);
    world *wrld = myArg->_wrld;
#ifndef DIDEROT_NO_GLOBALS
    globals *glob = wrld->_globals;
#endif
    diderot::scheduler *sched = wrld->_sched;

  // iterate until all strands are stable
    uint32_t numDead = 0;
    uint32_t numStabilized = 0;
    uint32_t nSteps = 0;
    uint32_t maxSteps = 0;
    uint32_t maxNSteps = myArg->_maxNSteps;
    while ((wrld->_strands.num_active() > 0) && (nSteps < maxNSteps)) {
      // barrier at start of super-step
        sched->_bspBar.wait ();
        nSteps++;
#ifdef DIDEROT_HAS_STRAND_COMMUNICATION
      // build spatial partition to support communication
        if (myArg->_id == 0) {
          // worker 0 does sequential work of rebuilding tree
/* FIXME: tree building should be parallel */
            wrld->_tree->rebuild ();
        }
      // synchronize on the tree having been built
        sched->_bspBar.wait ();
#endif
        strand_array::sched_block *blk;
        while ((blk = myArg->_strands.get_block()) != nullptr) {
#ifdef DIDEROT_HAS_START_METHOD
          // run start methods for fresh strands
            blk->run_start_methods();
#endif
	    uint32_t nStable = blk->_nStable;
#ifdef DIDEROT_HAS_STRAND_DIE
	    uint32_t nDead = blk->_nDead;
#endif
          // update the strands
            for (auto ix = myArg->_strands.begin_active(blk);
                ix != myArg->_strands.end_active(blk);
            ) {
                diderot::strand_status sts = myArg->_strands.strand_update(@UPDATE_ARGS_IN_WRLD@ix);
                switch (sts) {
                  case diderot::kStabilize:
                  // stabilize the strand's state.
                    IF_LOGGING ( LogStrandStabilize(wrld, myArg->_id+1, ix); )
                    ix = myArg->_strands.strand_stabilize(blk, @STABILIZE_ARGS_IN_WRLD@ix);
                    break;
#ifdef DIDEROT_HAS_STRAND_DIE
                  case diderot::kDie:
                    IF_LOGGING ( LogStrandDie(wrld, myArg->_id+1, ix); )
                    ix = myArg->_strands.kill (blk, ix);
                    break;
#endif
                  default:
                    assert (sts == myArg->_strands.status(ix));
                    ix = myArg->_strands.next_active(blk, ix);
                    break;
                }
            }
          // finish the local-phase of the superstep by updating strand status
// FIXME: do we need a finish_step() method for the block?
//            blk->_strands.finish_step();
	    numStabilized += (blk->_nStable - nStable);
#ifdef DIDEROT_HAS_STRAND_DIE
	    numDead += (blk->_nDead - nDead);
#endif
        }

      // barrier at start of super-step
        sched->_bspBar.wait ();
        if (myArg->_id == 0) {
#ifdef DIDEROT_HAS_GLOBAL_UPDATE
/* FIXME: global update should be parallel */
          // worker 0 does sequential work of global update
            wrld->global_update();
#endif
            wrld->swap_state();
        }
	myArg->_strands.swap();
    }

  // update global counts of active and stable strands
    myArg->_nSteps = maxSteps;
    myArg->_nStable = numStabilized;
    myArg->_nDead = numDead;

}

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