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

SCM Repository

[diderot] View of /branches/lamont/src/compiler/c-target/fragments/seq-run.in
ViewVC logotype

View of /branches/lamont/src/compiler/c-target/fragments/seq-run.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3388 - (download) (annotate)
Tue Nov 10 03:17:51 2015 UTC (3 years, 11 months ago) by lamonts
File size: 5456 byte(s)
Adding support for disabling spatial optimization
//! Run the Diderot program (sequential version)
//! \param wrld the world-state of the Diderot program
//! \param maxNSteps the limit on the number of super steps; 0 means unlimited
//! \return the number of steps taken.
uint32_t @PREFIX@Run (@PREFIX@World_t *wrld, uint32_t maxNSteps)
{
#ifdef DIDEROT_DUAL_STATE
    Strand_t *strand = &(wrld->strandDesc[0]);
#endif

    @PREFIX@Globals_t *glob = wrld->globals;

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

  // iterate until all strands are stable
    if (wrld->verboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);

//initialize the query pool if the program is using a query function. 
//we store the queried strands in the pool. 
#ifdef DIDEROT_SPATIAL_COM    
    QueryListPool_t queryPool; 
    Diderot_Init_QueryListPool(&queryPool); 
    double spatialT0 = airTime();
    if(!wrld->disableSOpt)
      Diderot_KDTree_Build(wrld);
    double spatialTotalTime = (airTime() - spatialT0);   
#endif 

    uint32_t nSteps = 0, nUpdates = 0;
    uint32_t nActive = wrld->numActive;
    uint32_t nStable = wrld->numStable;
    while ((nActive > 0) && (nSteps < maxNSteps)) {
        nSteps++;
      // update strands
        bool existsStabilizing = false;
        for (uint32_t i = 0;  i < wrld->numStrands;  i++) {
            if (! wrld->status[i]) {
              #ifdef DIDEROT_SPATIAL_COM    
                queryPool.handle = 0; //clear the query pool 
                StrandStatus_t sts = @STRAND@_Update(wrld, i,&queryPool);
              #else 
                StrandStatus_t sts = @STRAND@_Update(wrld, i);
              #endif 
//                StrandStatus_t sts = @STRAND@_Update(glob, wrld->inState[i], wrld->outState[i],
//                                                     &wrld->inState,&wrld->outState,
//                                                     &wrld->status, &wrld->poolInfo);
                switch (sts) {
                  case DIDEROT_STABILIZE:
                    existsStabilizing = true;
                    wrld->status[i] = DIDEROT_STABILIZE;
                    nStable++; 
                    break;
                  case DIDEROT_DIE:
                    wrld->status[i] = DIDEROT_DIE;
                    nActive--;  
                    nStable++; 
                    break;
                  default:
                    break;
                }
            }
        }

        if (existsStabilizing) {
            for (int i = 0;  i < wrld->numStrands;  i++) {
// NOTE: we may want to compact the array of strands
                if (wrld->status[i] == DIDEROT_STABILIZE || StabalizeAllStrands) {
#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(glob, wrld->outState[i], wrld->inState[i]);
                    memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
#else
                    @STRAND@_Stabilize(glob, &wrld->state[i]);
#endif
                    wrld->status[i] = DIDEROT_STABLE;
                    nActive--;
                }
            }
        }
        // Increase the number of active strands if new strands were created
        if (wrld->poolInfo.nNewStrand > 0) { 
            nActive += wrld->poolInfo.nNewStrand;
            wrld->numStrands += wrld->poolInfo.nNewStrand;
            wrld->poolInfo.nNewStrand = 0; 
			@REALLOC_SPATIAL_COPY_ARRAY@
     
        }
#ifdef DIDEROT_DUAL_STATE
      // swap in and out
        @STRANDTY@ **tmp = wrld->inState;
        wrld->inState = wrld->outState;
        wrld->outState = tmp;
#endif
      /** Run the Global Block Phase */ 
       wrld->numActive = nActive;
       wrld->numStable = nStable;
       @CALL_GLOBAL_BLOCK_FN@
      if (StabalizeAllStrands) {
            for (int i = 0;  i < wrld->numStrands;  i++) {
// NOTE: we may want to compact the array of strands
                if (wrld->status[i] == DIDEROT_ACTIVE) {
#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(glob, wrld->outState[i], wrld->inState[i]);
                    memcpy (wrld->outState[i], wrld->inState[i], strand->stateSzb);
#else
                    @STRAND@_Stabilize(glob, &wrld->state[i]);
#endif
                    wrld->status[i] = DIDEROT_STABLE;
                    nActive--;
                    nStable++; 
                }
            }
          wrld->numActive = nActive;
          wrld->numStable = nStable;
        }
       


#ifdef DIDEROT_SPATIAL_COM    
    spatialT0 = airTime();
    if(!wrld->disableSOpt)
      Diderot_KDTree_Build(wrld);
  //  int num = countTree(wrld->spatialTree->root); 
   // printf("Number of Nodes = %d, Num of strands = %d\n",num, wrld->numStrands); 
    spatialTotalTime = spatialTotalTime + (airTime() - spatialT0);   
#endif 
    }
#ifdef DIDEROT_SPATIAL_COM
    wrld->spatialTime = spatialTotalTime/nSteps; 
#endif 
    return nSteps;

} // @PREFIX@Run
void Diderot_Stabilize_All(@PREFIX@World_t *wrld)
{
  for (uint32_t i = 0;  i < wrld->numStrands;  i++) {
    wrld->status[i] = DIDEROT_STABILIZE;
  }
}

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