Changeset 146:e94468699f12
- Timestamp:
- 03/13/2012 10:13:58 PM (15 months ago)
- Branch:
- default
- Location:
- src/parallelization
- Files:
-
- 4 modified
-
hiparsimulator.h (modified) (3 diffs)
-
hiparsimulator/parallelwriteradapter.h (modified) (3 diffs)
-
hiparsimulator/updategroup.h (modified) (2 diffs)
-
hiparsimulator/vanillastepper.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/parallelization/hiparsimulator.h
r142 r146 48 48 typedef UpdateGroup<CELL_TYPE, PARTITION> UpdateGroupType; 49 49 typedef typename ParentType::GridType GridType; 50 typedef ParallelWriterAdapter<typename UpdateGroupType::GridType, CELL_TYPE, PARTITION> ParallelWriterAdapterType; 50 51 static const int DIM = Topology::DIMENSIONS; 51 52 … … 62 63 communicator(_communicator) 63 64 { 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 132 private: 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 64 189 CoordBox<DIM> box = this->initializer->gridBox(); 65 190 updateGroup.reset( … … 71 196 ghostZoneWidth, 72 197 this->initializer, 198 writerAdaptersGhost, 199 writerAdaptersInner, 73 200 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(); 163 204 } 164 205 -
src/parallelization/hiparsimulator/parallelwriteradapter.h
r142 r146 24 24 ParallelWriterAdapter( 25 25 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) : 27 29 sim(_sim), 28 writer(_writer) 30 writer(_writer), 31 firstNanoStep(firstStep * CELL_TYPE::nanoSteps()), 32 lastNanoStep(lastStep * CELL_TYPE::nanoSteps()) 29 33 { 30 reload(); 34 reload(firstNanoStep); 35 reload(lastNanoStep); 31 36 } 32 37 … … 36 41 const long& nanoStep) 37 42 { 38 std::cout << "bingobongoA " << nanoStep << "\n";39 43 if (!this->checkNanoStepPut(nanoStep)) 40 44 return; 41 45 this->requestedNanoSteps.erase_min(); 42 46 43 std::cout << "bingobongoB " << nanoStep << "\n";44 // fixme: load next event45 47 // 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 47 58 reload(); 48 59 } … … 51 62 HiParSimulatorType *sim; 52 63 boost::shared_ptr<ParallelWriter<CELL_TYPE> > writer; 64 long firstNanoStep; 65 long lastNanoStep; 53 66 54 long nextOutputStep( )67 long nextOutputStep(const long& step) 55 68 { 56 long step = sim->getStep();57 69 long remainder = step % writer->getPeriod(); 58 step +=writer->getPeriod() - remainder;59 return step;70 long next = step + writer->getPeriod() - remainder; 71 return next; 60 72 } 61 73 62 74 void reload() 63 75 { 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 { 66 82 this->pushRequest(nextNanoStep); 67 83 } -
src/parallelization/hiparsimulator/updategroup.h
r132 r146 45 45 const unsigned& _ghostZoneWidth, 46 46 Initializer<CELL_TYPE> *_initializer, 47 PatchAccepterVec patchAcceptersGhost=PatchAccepterVec(), 48 PatchAccepterVec patchAcceptersInner=PatchAccepterVec(), 47 49 MPI::Comm *communicator = &MPI::COMM_WORLD) : 48 50 partition(_partition), … … 90 92 } 91 93 92 stepper.reset(new STEPPER(partitionManager, initializer, ghostZoneAccepterLinks)); 94 stepper.reset(new STEPPER( 95 partitionManager, 96 initializer, 97 patchAcceptersGhost + ghostZoneAccepterLinks, 98 patchAcceptersInner)); 93 99 94 100 // the ghostzone receivers may be safely added after -
src/parallelization/hiparsimulator/vanillastepper.h
r142 r146 29 29 boost::shared_ptr<MyPartitionManager> _partitionManager, 30 30 Initializer<CELL_TYPE> *_initializer, 31 const PatchAccepterVec ghostZonePatchAccepters = PatchAccepterVec()) : 31 const PatchAccepterVec ghostZonePatchAccepters = PatchAccepterVec(), 32 const PatchAccepterVec innerSetPatchAccepters = PatchAccepterVec()) : 32 33 ParentType(_partitionManager, _initializer) 33 34 { … … 37 38 for (int i = 0; i < ghostZonePatchAccepters.size(); ++i) { 38 39 addPatchAccepter(ghostZonePatchAccepters[i], ParentType::GHOST); 40 } 41 for (int i = 0; i < innerSetPatchAccepters.size(); ++i) { 42 addPatchAccepter(innerSetPatchAccepters[i], ParentType::INNER_SET); 39 43 } 40 44 … … 101 105 const long& nanoStep) 102 106 { 103 std::cout << "notifyPatchAccepters(" << nanoStep << ")\n";104 107 for (class ParentType::PatchAccepterList::iterator i = 105 108 this->patchAccepters[patchType].begin(); 106 109 i != this->patchAccepters[patchType].end(); 107 110 ++i) { 108 std::cout << " @ " << (*i)->nextRequiredNanoStep() << "\n";109 111 if (nanoStep == (*i)->nextRequiredNanoStep()) { 110 112 (*i)->put(*oldGrid, region, nanoStep); … … 121 123 this->patchProviders[patchType].begin(); 122 124 i != this->patchProviders[patchType].end(); 123 ++i) 125 ++i) { 124 126 (*i)->get( 125 127 &*oldGrid, 126 128 region, 127 129 nanoStep); 130 } 128 131 } 129 132 … … 144 147 newGrid->getEdgeCell() = oldGrid->getEdgeCell(); 145 148 resetValidGhostZoneWidth(); 149 150 notifyPatchAccepters( 151 rim(), 152 ParentType::GHOST, 153 globalNanoStep()); 154 notifyPatchAccepters( 155 getPartitionManager().innerSet(0), 156 ParentType::INNER_SET, 157 globalNanoStep()); 146 158 147 159 kernelBuffer = MyPatchBuffer1(getPartitionManager().getVolatileKernel()); … … 176 188 int oldNanoStep = curNanoStep; 177 189 int oldStep = curStep; 190 int curGlobalNanoStep = globalNanoStep(); 191 178 192 for (int t = 0; t < ghostZoneWidth(); ++t) { 179 193 const Region<DIM>& region = getPartitionManager().rim(t + 1); … … 191 205 192 206 std::swap(oldGrid, newGrid); 207 208 ++curGlobalNanoStep; 209 notifyPatchAccepters(rim(), ParentType::GHOST, curGlobalNanoStep); 193 210 } 194 211 curNanoStep = oldNanoStep; 195 212 curStep = oldStep; 196 213 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); 202 215 if (ghostZoneWidth() % 2) 203 216 std::swap(oldGrid, newGrid);
