Changeset 146:e94468699f12

Show
Ignore:
Timestamp:
03/13/2012 10:13:58 PM (15 months ago)
Author:
Andreas Schaefer <gentryx@…>
Branch:
default
Message:

changed HiParSimulator?'s event handling so that ParallelWriters? can be correctly notified at simulation start of both, inner ghost zones and inner set regions

Location:
src/parallelization
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • src/parallelization/hiparsimulator.h

    r142 r146  
    4848    typedef UpdateGroup<CELL_TYPE, PARTITION> UpdateGroupType; 
    4949    typedef typename ParentType::GridType GridType; 
     50    typedef ParallelWriterAdapter<typename UpdateGroupType::GridType, CELL_TYPE, PARTITION> ParallelWriterAdapterType; 
    5051    static const int DIM = Topology::DIMENSIONS; 
    5152 
     
    6263        communicator(_communicator) 
    6364    { 
     65    }    
     66 
     67    // fixme: need test 
     68    inline void run() 
     69    { 
     70        initUpdateGroup(); 
     71 
     72        // fixme: use events here 
     73        std::pair<int, int> currentStep = updateGroup->currentStep(); 
     74        unsigned remainingSteps =  
     75            this->initializer->maxSteps() - currentStep.first; 
     76        unsigned remainingNanoSteps =  
     77            remainingSteps * CELL_TYPE::nanoSteps() - currentStep.second; 
     78        nanoStep(remainingNanoSteps); 
     79    } 
     80 
     81    // fixme: need test 
     82    inline void step() 
     83    { 
     84        initUpdateGroup(); 
     85 
     86        nanoStep(CELL_TYPE::nanoSteps()); 
     87    } 
     88 
     89    // fixme: need test 
     90    virtual void getGridFragment( 
     91        const GridType **grid,  
     92        const Region<DIM> **validRegion)  
     93    { 
     94        *grid = &updateGroup->grid(); 
     95        // fixme: we can't even guarantee this part 
     96        *validRegion = &partitionManager.ownRegion(); 
     97    } 
     98 
     99    virtual unsigned getStep() const  
     100    { 
     101        if (updateGroup) { 
     102            return updateGroup->currentStep().first; 
     103        } else { 
     104            return this->initializer->startStep(); 
     105        } 
     106    } 
     107 
     108    virtual void registerWriter(ParallelWriter<CELL_TYPE> *writer) 
     109    { 
     110        DistributedSimulator<CELL_TYPE>::registerWriter(writer); 
     111 
     112        // we need two adapters as each ParallelWriter needs to be 
     113        // notified twice: once for the (inner) ghost zone, and once 
     114        // for the inner set. 
     115        typename UpdateGroupType::PatchAccepterPtr adapterGhost( 
     116            new ParallelWriterAdapterType( 
     117                this, 
     118                this->getWriters().back(), 
     119                this->initializer->startStep(), 
     120                this->initializer->maxSteps())); 
     121        typename UpdateGroupType::PatchAccepterPtr adapterInnerSet( 
     122            new ParallelWriterAdapterType( 
     123                this,  
     124                this->getWriters().back(), 
     125                this->initializer->startStep(), 
     126                this->initializer->maxSteps())); 
     127 
     128        writerAdaptersGhost.push_back(adapterGhost); 
     129        writerAdaptersInner.push_back(adapterInnerSet); 
     130    } 
     131 
     132private: 
     133    boost::shared_ptr<LoadBalancer> balancer; 
     134    unsigned loadBalancingPeriod; 
     135    unsigned ghostZoneWidth; 
     136    EventMap events; 
     137    PartitionManager<DIM, Topology> partitionManager; 
     138    MPI::Comm *communicator; 
     139    boost::shared_ptr<UpdateGroupType> updateGroup; 
     140    typename UpdateGroupType::PatchAccepterVec writerAdaptersGhost; 
     141    typename UpdateGroupType::PatchAccepterVec writerAdaptersInner; 
     142 
     143    SuperVector<long> initialWeights(const long& items, const long& size) const 
     144    {     
     145        SuperVector<long> ret(size); 
     146        long lastPos = 0; 
     147 
     148        for (long i = 0; i < size; i++) { 
     149            long currentPos = items * (i + 1) / size; 
     150            ret[i] = currentPos - lastPos; 
     151            lastPos = currentPos; 
     152        } 
     153 
     154        return ret; 
     155    } 
     156 
     157    inline void nanoStep(const unsigned& s) 
     158    { 
     159        std::cout << "nanoStep(" << s << ")\n"; 
     160        updateGroup->update(s); 
     161 
     162        // fixme: honor events here: 
     163        // unsigned endNanoStep = nanoStepCounter + s; 
     164        // events[endNanoStep].insert(PAUSE); 
     165         
     166        // while (nanoStepCounter < endNanoStep) { 
     167        //     std::pair<unsigned, EventSet> currentEvents = extractCurrentEvents(); 
     168        //     nanoStepCounter = currentEvents.first; 
     169        //     handleEvents(currentEvents.second); 
     170        // } 
     171    } 
     172 
     173    /** 
     174     * We need to do late/lazy initialization to give the user time to 
     175     * add ParallelWriter objects before calling run(). Writers may 
     176     * only be added savely to an UpdateGroup upon creation because of 
     177     * the way the Stepper handles ghostzone updates. It's a long 
     178     * story... At the end of the day this remains the best compromise 
     179     * of hiding complexity (in the Stepper) and a convenient API of 
     180     * the Simulator on the one hand, and avoiding objects with an 
     181     * uninitialized state on the other. 
     182     */ 
     183    inline void initUpdateGroup() 
     184    { 
     185        if (updateGroup) { 
     186            return; 
     187        } 
     188 
    64189        CoordBox<DIM> box = this->initializer->gridBox(); 
    65190        updateGroup.reset( 
     
    71196                ghostZoneWidth, 
    72197                this->initializer, 
     198                writerAdaptersGhost, 
     199                writerAdaptersInner, 
    73200                communicator)); 
    74     }    
    75  
    76     // fixme: need test 
    77     inline void run() 
    78     { 
    79         // fixme: use events here 
    80         std::pair<int, int> currentStep = updateGroup->currentStep(); 
    81         unsigned remainingSteps =  
    82             this->initializer->maxSteps() - currentStep.first; 
    83         unsigned remainingNanoSteps =  
    84             remainingSteps * CELL_TYPE::nanoSteps() - currentStep.second; 
    85         nanoStep(remainingNanoSteps); 
    86     } 
    87  
    88     // fixme: need test 
    89     inline void step() 
    90     { 
    91         nanoStep(CELL_TYPE::nanoSteps()); 
    92     } 
    93  
    94     // fixme: need test 
    95     virtual void getGridFragment( 
    96         const GridType **grid,  
    97         const Region<DIM> **validRegion)  
    98     { 
    99         *grid = &updateGroup->grid(); 
    100         // fixme: we can't even guarantee this part 
    101         *validRegion = &partitionManager.ownRegion(); 
    102     } 
    103  
    104     virtual unsigned getStep() const  
    105     { 
    106         return updateGroup->currentStep().first; 
    107     } 
    108  
    109     virtual void registerWriter(ParallelWriter<CELL_TYPE> *writer) 
    110     { 
    111         DistributedSimulator<CELL_TYPE>::registerWriter(writer); 
    112  
    113         typename UpdateGroupType::PatchAccepterPtr adapter( 
    114             new ParallelWriterAdapter< 
    115                 typename UpdateGroupType::GridType,  
    116                 CELL_TYPE,  
    117                 PARTITION>( 
    118                 this,  
    119                 this->getWriters().back())); 
    120         // fixme: use different adapters here to avoid nanostep confusion b/c of ghostzone updates 
    121         // updateGroup->addPatchAccepter(adapter, Stepper<CELL_TYPE>::GHOST); 
    122         updateGroup->addPatchAccepter(adapter, Stepper<CELL_TYPE>::INNER_SET); 
    123     } 
    124  
    125 private: 
    126     boost::shared_ptr<LoadBalancer> balancer; 
    127     unsigned loadBalancingPeriod; 
    128     unsigned ghostZoneWidth; 
    129     // fixme: need this? 
    130     EventMap events; 
    131     PartitionManager<DIM, Topology> partitionManager; 
    132     MPI::Comm *communicator; 
    133     boost::shared_ptr<UpdateGroupType> updateGroup; 
    134  
    135     SuperVector<long> initialWeights(const long& items, const long& size) const 
    136     {     
    137         SuperVector<long> ret(size); 
    138         long lastPos = 0; 
    139  
    140         for (long i = 0; i < size; i++) { 
    141             long currentPos = items * (i + 1) / size; 
    142             ret[i] = currentPos - lastPos; 
    143             lastPos = currentPos; 
    144         } 
    145  
    146         return ret; 
    147     } 
    148  
    149     inline void nanoStep(const unsigned& s) 
    150     { 
    151         std::cout << "nanoStep(" << s << ")\n"; 
    152         updateGroup->update(s); 
    153  
    154         // fixme: honor events here: 
    155         // unsigned endNanoStep = nanoStepCounter + s; 
    156         // events[endNanoStep].insert(PAUSE); 
    157          
    158         // while (nanoStepCounter < endNanoStep) { 
    159         //     std::pair<unsigned, EventSet> currentEvents = extractCurrentEvents(); 
    160         //     nanoStepCounter = currentEvents.first; 
    161         //     handleEvents(currentEvents.second); 
    162         // } 
     201 
     202        writerAdaptersGhost.clear(); 
     203        writerAdaptersInner.clear(); 
    163204    } 
    164205 
  • src/parallelization/hiparsimulator/parallelwriteradapter.h

    r142 r146  
    2424    ParallelWriterAdapter( 
    2525        HiParSimulatorType *_sim, 
    26         boost::shared_ptr<ParallelWriter<CELL_TYPE> > _writer) : 
     26        boost::shared_ptr<ParallelWriter<CELL_TYPE> > _writer, 
     27        const long& firstStep, 
     28        const long& lastStep) : 
    2729        sim(_sim), 
    28         writer(_writer) 
     30        writer(_writer), 
     31        firstNanoStep(firstStep * CELL_TYPE::nanoSteps()), 
     32        lastNanoStep(lastStep   * CELL_TYPE::nanoSteps()) 
    2933    { 
    30         reload(); 
     34        reload(firstNanoStep); 
     35        reload(lastNanoStep); 
    3136    } 
    3237 
     
    3641        const long& nanoStep)  
    3742    { 
    38         std::cout << "bingobongoA " << nanoStep << "\n"; 
    3943        if (!this->checkNanoStepPut(nanoStep)) 
    4044            return; 
    4145        this->requestedNanoSteps.erase_min(); 
    4246 
    43         std::cout << "bingobongoB " << nanoStep << "\n"; 
    44         // fixme: load next event 
    4547        // fixme: set simulator up to link to correct grid/validRegion 
    46         // writer->stepFinished(); 
     48        if (nanoStep == firstNanoStep) { 
     49            writer->initialized(); 
     50        } else { 
     51            if (nanoStep == lastNanoStep) { 
     52                writer->allDone(); 
     53            } else { 
     54                writer->stepFinished(); 
     55            } 
     56        } 
     57 
    4758        reload(); 
    4859    } 
     
    5162    HiParSimulatorType *sim; 
    5263    boost::shared_ptr<ParallelWriter<CELL_TYPE> > writer; 
     64    long firstNanoStep; 
     65    long lastNanoStep; 
    5366 
    54     long nextOutputStep() 
     67    long nextOutputStep(const long& step) 
    5568    { 
    56         long step = sim->getStep(); 
    5769        long remainder = step % writer->getPeriod(); 
    58         step += writer->getPeriod() - remainder; 
    59         return step; 
     70        long next = step + writer->getPeriod() - remainder; 
     71        return next; 
    6072    } 
    6173 
    6274    void reload() 
    6375    { 
    64         long nextNanoStep = nextOutputStep() * CELL_TYPE::nanoSteps(); 
    65         std::cout << "nextNanoStep: " << nextNanoStep << "\n"; 
     76        long nextNanoStep = nextOutputStep(sim->getStep()) * CELL_TYPE::nanoSteps(); 
     77        reload(nextNanoStep); 
     78    } 
     79 
     80    void reload(const long& nextNanoStep) 
     81    { 
    6682        this->pushRequest(nextNanoStep); 
    6783    } 
  • src/parallelization/hiparsimulator/updategroup.h

    r132 r146  
    4545        const unsigned& _ghostZoneWidth, 
    4646        Initializer<CELL_TYPE> *_initializer, 
     47        PatchAccepterVec patchAcceptersGhost=PatchAccepterVec(), 
     48        PatchAccepterVec patchAcceptersInner=PatchAccepterVec(), 
    4749        MPI::Comm *communicator = &MPI::COMM_WORLD) :  
    4850        partition(_partition), 
     
    9092        } 
    9193 
    92         stepper.reset(new STEPPER(partitionManager, initializer, ghostZoneAccepterLinks)); 
     94        stepper.reset(new STEPPER( 
     95                          partitionManager,  
     96                          initializer, 
     97                          patchAcceptersGhost + ghostZoneAccepterLinks, 
     98                          patchAcceptersInner)); 
    9399 
    94100        // the ghostzone receivers may be safely added after 
  • src/parallelization/hiparsimulator/vanillastepper.h

    r142 r146  
    2929        boost::shared_ptr<MyPartitionManager> _partitionManager, 
    3030        Initializer<CELL_TYPE> *_initializer, 
    31         const PatchAccepterVec ghostZonePatchAccepters = PatchAccepterVec()) : 
     31        const PatchAccepterVec ghostZonePatchAccepters = PatchAccepterVec(), 
     32        const PatchAccepterVec innerSetPatchAccepters = PatchAccepterVec()) : 
    3233        ParentType(_partitionManager, _initializer) 
    3334    { 
     
    3738        for (int i = 0; i < ghostZonePatchAccepters.size(); ++i) { 
    3839            addPatchAccepter(ghostZonePatchAccepters[i], ParentType::GHOST); 
     40        } 
     41        for (int i = 0; i < innerSetPatchAccepters.size(); ++i) { 
     42            addPatchAccepter(innerSetPatchAccepters[i], ParentType::INNER_SET); 
    3943        } 
    4044 
     
    101105        const long& nanoStep) 
    102106    { 
    103         std::cout << "notifyPatchAccepters(" << nanoStep << ")\n"; 
    104107        for (class ParentType::PatchAccepterList::iterator i =  
    105108                 this->patchAccepters[patchType].begin(); 
    106109             i != this->patchAccepters[patchType].end(); 
    107110             ++i) { 
    108             std::cout << "  @ " << (*i)->nextRequiredNanoStep() << "\n"; 
    109111            if (nanoStep == (*i)->nextRequiredNanoStep()) { 
    110112                (*i)->put(*oldGrid, region, nanoStep); 
     
    121123                 this->patchProviders[patchType].begin(); 
    122124             i != this->patchProviders[patchType].end(); 
    123              ++i) 
     125             ++i) { 
    124126            (*i)->get( 
    125127                &*oldGrid, 
    126128                region, 
    127129                nanoStep); 
     130        } 
    128131    } 
    129132 
     
    144147        newGrid->getEdgeCell() = oldGrid->getEdgeCell(); 
    145148        resetValidGhostZoneWidth(); 
     149 
     150        notifyPatchAccepters( 
     151            rim(),      
     152            ParentType::GHOST,      
     153            globalNanoStep()); 
     154        notifyPatchAccepters( 
     155            getPartitionManager().innerSet(0),  
     156            ParentType::INNER_SET,  
     157            globalNanoStep()); 
    146158 
    147159        kernelBuffer = MyPatchBuffer1(getPartitionManager().getVolatileKernel()); 
     
    176188        int oldNanoStep = curNanoStep; 
    177189        int oldStep = curStep; 
     190        int curGlobalNanoStep = globalNanoStep(); 
     191 
    178192        for (int t = 0; t < ghostZoneWidth(); ++t) { 
    179193            const Region<DIM>& region = getPartitionManager().rim(t + 1); 
     
    191205 
    192206            std::swap(oldGrid, newGrid); 
     207 
     208            ++curGlobalNanoStep; 
     209            notifyPatchAccepters(rim(), ParentType::GHOST, curGlobalNanoStep); 
    193210        } 
    194211        curNanoStep = oldNanoStep; 
    195212        curStep = oldStep; 
    196213 
    197         // offset ghostZoneWidth() for nanoStep needed as ghost zone 
    198         // updates preceede updates to the inner set. 
    199         int nextNanoStep = globalNanoStep() + ghostZoneWidth(); 
    200         notifyPatchAccepters(rim(), ParentType::GHOST, nextNanoStep); 
    201                    saveRim(nextNanoStep); 
     214        saveRim(curGlobalNanoStep); 
    202215        if (ghostZoneWidth() % 2) 
    203216            std::swap(oldGrid, newGrid);