Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Voloctree Mapper rank-overlapped ids getter #381

Merged
merged 5 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 deletions src/patchkernel/volume_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ 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> > getReceivedReferenceIds() = 0;
virtual std::unordered_map<int, std::vector<long> > getSentReferenceIds() = 0;
#endif

protected:
Expand Down
57 changes: 44 additions & 13 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,17 +789,48 @@ std::map<int, std::vector<long>> VolOctreeMapper::getSentReferenceIds()
}
}

for (int rank = 0; rank < m_nProcs; rank++) {
sent[rank].reserve(rankIdSend[rank].size());
for (const auto & rankId : rankIdSend) {
sent[rankId.first].assign(rankId.second.begin(), rankId.second.end());
}

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);
return sent;
}

/**
* Get the list of the octants of the partitions of the reference mesh, different
* from the local rank, overlapped to the local partition of the mapped mesh.
*
* \result Returns the map with for each rank (key) the list of the octants
* (argument) of the reference mesh overlapped with the local partition of the
* mapped mesh.
*/
std::unordered_map<int, std::vector<long>> VolOctreeMapper::getReceivedReferenceIds()
{
std::unordered_map<int, std::vector<long>> received;

// Use set to retrieve ordered ids from senders using volume mapper mapping
// We loop over the cells of the reference mesh, we ask the mapping for the
// mapped mesh ids of cells overlapping the current cell, we checks for ranks
// and saves non-matching rank cells in the set, rank-by-rank.

std::unordered_map<int, std::set<long>> rankIdRecv;

for (Cell & cell : m_mappedPatch->getCells()) {
long id = cell.getId();
auto info = m_inverseMapping.at(id);
std::size_t idsSize = info.ids.size();
for (std::size_t i = 0; i < idsSize; ++i) {
if (info.ranks[i] != m_mappedPatch->getRank()) {
rankIdRecv[info.ranks[i]].insert(info.ids[i]);
}
}
}

return sent;
for (const auto & rankId : rankIdRecv) {
received[rankId.first].assign(rankId.second.begin(), rankId.second.end());
}

return received;
}

/**
Expand All @@ -810,9 +841,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
7 changes: 4 additions & 3 deletions src/voloctree/voloctree_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ 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>> getReceivedReferenceIds() override;
std::unordered_map<int, std::vector<long>> getSentReferenceIds() override;
#endif

private:
Expand Down