Skip to content

Commit

Permalink
voloctree: use unordered maps for lists of overlapping rank ids
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocisternino committed May 9, 2023
1 parent 7dcb1d7 commit 496c154
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/voloctree_mapper_example_00003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ void run()
//Communicate needed data for mapping
std::map<int, std::map<long, double> > datarec;
{
std::map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();

//build send buffers
MPI_Comm comm = MPI_COMM_WORLD;
Expand Down
12 changes: 6 additions & 6 deletions examples/voloctree_mapper_example_00004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ void runReferenceAdaptation()
std::map<int, std::map<long, double> > datarec;
std::map<int, std::map<long, double> > volrec;
{
std::map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();

//build send buffers
MPI_Comm comm = MPI_COMM_WORLD;
Expand Down Expand Up @@ -453,8 +453,8 @@ void runReferenceAdaptation()
std::map<int, std::map<long, double> > datarec;
std::map<int, std::map<long, double> > volrec;
{
std::map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();

//build send buffers
MPI_Comm comm = MPI_COMM_WORLD;
Expand Down Expand Up @@ -1271,8 +1271,8 @@ void runMappedAdaptation()
std::map<int, std::map<long, double> > datarec;
std::map<int, std::map<long, double> > volrec;
{
std::map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();

//build send buffers
MPI_Comm comm;
Expand Down
16 changes: 8 additions & 8 deletions src/POD/pod_voloctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ void PODVolOctree::communicatePODField(const pod::PODField & field, std::map<int
std::size_t nsf = field.scalar->getFieldCount();
std::size_t nvf = field.vector->getFieldCount();

std::map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();

//build send buffers
DataCommunicator dataCommunicator(m_communicator);
Expand Down Expand Up @@ -1370,7 +1370,7 @@ void PODVolOctree::communicatePODFieldFromPOD(const pod::PODField & field, std::
std::size_t nsf = field.scalar->getFieldCount();
std::size_t nvf = field.vector->getFieldCount();

std::map<int, std::vector<long> > rankIDsend = m_meshmap->getSentReferenceIds();
std::unordered_map<int, std::vector<long> > rankIDsend = m_meshmap->getSentReferenceIds();

//build send buffers
DataCommunicator dataCommunicator(m_communicator);
Expand Down Expand Up @@ -1437,8 +1437,8 @@ void PODVolOctree::communicatePODFieldFromPOD(const pod::PODField & field, std::
void PODVolOctree::communicateBoolField(const PiercedStorage<bool> & field, std::map<int, std::map<long, bool> > & dataBrec)
{

std::map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();

//build send buffers
DataCommunicator dataCommunicator(m_communicator);
Expand Down Expand Up @@ -1477,8 +1477,8 @@ void PODVolOctree::communicateField(const PiercedStorage<double> & field, const

std::size_t nf = field.getFieldCount();

std::map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();
std::unordered_map<int, std::vector<long> > rankIDrec = m_meshmap->getReceivedMappedIds();
std::unordered_map<int, std::vector<long> > rankIDsend = m_meshmap->getSentMappedIds();

//build send buffers
DataCommunicator dataCommunicator(m_communicator);
Expand Down Expand Up @@ -1522,7 +1522,7 @@ void PODVolOctree::communicateFieldFromPOD(const PiercedStorage<double> & field,

std::size_t nf = field.getFieldCount();

std::map<int, std::vector<long> > rankIDsend = m_meshmap->getSentReferenceIds();
std::unordered_map<int, std::vector<long> > rankIDsend = m_meshmap->getSentReferenceIds();

//build send buffers
DataCommunicator dataCommunicator(m_communicator);
Expand Down
6 changes: 3 additions & 3 deletions src/patchkernel/volume_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class VolumeMapper {

#if BITPIT_ENABLE_MPI
virtual bool checkPartition() = 0;
virtual std::map<int, std::vector<long> > getReceivedMappedIds() = 0;
virtual std::map<int, std::vector<long> > getSentMappedIds() = 0;
virtual std::map<int, std::vector<long> > getSentReferenceIds() = 0;
virtual std::unordered_map<int, std::vector<long> > getReceivedMappedIds() = 0;
virtual std::unordered_map<int, std::vector<long> > getSentMappedIds() = 0;
virtual std::unordered_map<int, std::vector<long> > getSentReferenceIds() = 0;
#endif

protected:
Expand Down
20 changes: 9 additions & 11 deletions src/voloctree/voloctree_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ void VolOctreeMapper::_mappingAdaptionMappedUpdate(const std::vector<adaption::I
* (argument) of the mapped mesh overlapped with the local partition of the
* reference mesh.
*/
std::map<int, std::vector<long>> VolOctreeMapper::getReceivedMappedIds()
std::unordered_map<int, std::vector<long>> VolOctreeMapper::getReceivedMappedIds()
{
std::map<int, std::vector<long>> received;
std::unordered_map<int, std::vector<long>> received;

for (OctantIR octir : m_partitionIR.list_rec_octantIR_before) {
received[octir.rank].push_back(octir.id);
Expand All @@ -772,12 +772,12 @@ std::map<int, std::vector<long>> VolOctreeMapper::getReceivedMappedIds()
* (argument) of the reference mesh overlapped with the partition (rank) of
* the mapped mesh.
*/
std::map<int, std::vector<long>> VolOctreeMapper::getSentReferenceIds()
std::unordered_map<int, std::vector<long>> VolOctreeMapper::getSentReferenceIds()
{
std::map<int, std::vector<long>> sent;
std::unordered_map<int, std::vector<long>> sent;

// Recover id to be recv/send
std::map<int, std::set<long>> rankIdSend;
std::unordered_map<int, std::set<long>> rankIdSend;

for (Cell &cell : m_referencePatch->getCells()) {
long id = cell.getId();
Expand All @@ -789,10 +789,8 @@ std::map<int, std::vector<long>> VolOctreeMapper::getSentReferenceIds()
}
}

for (std::map<int, std::set<long>>::iterator it=rankIdSend.begin(); it!=rankIdSend.end(); ++it) {
for (long id : it->second) {
sent[it->first].push_back(id);
}
for (const auto & rankId : rankIdSend) {
sent[rankId.first].assign(rankId.second.begin(), rankId.second.end());
}

return sent;
Expand All @@ -806,9 +804,9 @@ std::map<int, std::vector<long>> VolOctreeMapper::getSentReferenceIds()
* (argument) of the mapped mesh overlapped with the partition (rank) of the
* reference mesh.
*/
std::map<int, std::vector<long>> VolOctreeMapper::getSentMappedIds()
std::unordered_map<int, std::vector<long>> VolOctreeMapper::getSentMappedIds()
{
std::map<int, std::vector<long>> sent;
std::unordered_map<int, std::vector<long>> sent;

for (OctantIR octir : m_partitionIR.list_sent_octantIR) {
sent[octir.rank].push_back(octir.id);
Expand Down
6 changes: 3 additions & 3 deletions src/voloctree/voloctree_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class VolOctreeMapper: public VolumeMapper {
#if BITPIT_ENABLE_MPI
bool checkPartition() override;
void clearPartitionMapping();
std::map<int, std::vector<long>> getReceivedMappedIds() override;
std::map<int, std::vector<long>> getSentMappedIds() override;
std::map<int, std::vector<long>> getSentReferenceIds() override;
std::unordered_map<int, std::vector<long>> getReceivedMappedIds() override;
std::unordered_map<int, std::vector<long>> getSentMappedIds() override;
std::unordered_map<int, std::vector<long>> getSentReferenceIds() override;
#endif

private:
Expand Down

0 comments on commit 496c154

Please sign in to comment.