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 2562 - (download) (annotate)
Mon Mar 10 04:10:03 2014 UTC (5 years, 4 months ago) by lamonts
File size: 4075 byte(s)
Fixed bug with queryPool not allocating correctly and fixed deadlock of spatail data structure
//! 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    
    QueryPool_t queryPool; 
    Diderot_InitQueryPool(&queryPool); 
    double spatialT0 = airTime();
    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;
                    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) {
#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@
#ifdef DIDEROT_SPATIAL_COM    
    spatialT0 = airTime();
    Diderot_KDTree_Build(wrld);
    spatialTotalTime = spatialTotalTime + (airTime() - spatialT0);   
#endif 
    }
    wrld->spatialTime = spatialTotalTime/nSteps; 
    return nSteps;

} // @PREFIX@Run

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