Skip to content

Commit

Permalink
Remove overloading of function mpi_get_size
Browse files Browse the repository at this point in the history
The function mpi_get_size in mpi_utils.cc was renamed to include the
name of the type it is operating on, i.e.: mpi_get_comm_size,
mpi_get_group_size and mpi_get_type_size. Overloading does not work on
MPI implementations where the MPI_Comm and MPI_Group types are the
same.
  • Loading branch information
mdjurfeldt committed Aug 25, 2022
1 parent 8ac4052 commit f33b66e
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/application_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace MUSIC {
{
std::map<int, int> leaders;

int size = mpi_get_size (MPI_COMM_WORLD);
int size = mpi_get_comm_size (MPI_COMM_WORLD);
int rank = mpi_get_rank (MPI_COMM_WORLD);
int *colors = new int[size];
colors[rank] = lookup (my_app_label)->color ();
Expand Down
2 changes: 1 addition & 1 deletion src/application_mapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace MUSIC {
}
else
{
int nRanks = mpi_get_size (MPI_COMM_WORLD);
int nRanks = mpi_get_comm_size (MPI_COMM_WORLD);
int my_rank = mpi_get_rank (MPI_COMM_WORLD);

#if HAVE_SYS_STAT_H
Expand Down
2 changes: 1 addition & 1 deletion src/collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace MUSIC {
BIFO* buffer = b->first;
Intervals& intervals = b->second;
sort (intervals.begin (), intervals.end ());
int elementSize = mpi_get_size (dataMap->type ());
int elementSize = mpi_get_type_size (dataMap->type ());
int size = 0;
for (Intervals::iterator i = intervals.begin ();
i != intervals.end ();
Expand Down
6 changes: 3 additions & 3 deletions src/connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ namespace MUSIC {
EventOutputConnector::makeSubconnector (int remoteRank)
{
//////
/* int world_size = mpi_get_size (MPI_COMM_WORLD);
/* int world_size = mpi_get_comm_size (MPI_COMM_WORLD);
if (mpi_get_rank (MPI_COMM_WORLD) < world_size/2)
std::cout << remoteRank << std::flush << std::endl;*/
return new EventOutputSubconnector (//&synch,
Expand Down Expand Up @@ -1041,9 +1041,9 @@ error( "LOCAL Indices are not supported with MUSIC_ANYSOURCE");

for (NegotiationIterator i = spatialNegotiator_->negotiate (info.nProcesses (), this); !i.end (); ++i)
{
int begin = (i->displ()) * mpi_get_size (data_type_);
int begin = (i->displ()) * mpi_get_type_size (data_type_);
// length field is stored overlapping the end field
int end = (i->end() - i->begin()) * mpi_get_size (data_type_);
int end = (i->end() - i->begin()) * mpi_get_type_size (data_type_);
receiver_intrvs.insert (std::make_pair ( remoteToCollectiveRankMap[i->rank ()], Interval(begin, end)));
intrvs.push_back(i->interval());
}
Expand Down
2 changes: 1 addition & 1 deletion src/distributor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace MUSIC {
FIBO* buffer = b->first;
Intervals& intervals = b->second;
sort (intervals.begin (), intervals.end ());
int elementSize = mpi_get_size (dataMap->type ());
int elementSize = mpi_get_type_size (dataMap->type ());
int size = 0;
for (Intervals::iterator i = intervals.begin ();
i != intervals.end ();
Expand Down
6 changes: 3 additions & 3 deletions src/mpi_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ namespace MUSIC {
}

int
mpi_get_size (MPI_Comm comm)
mpi_get_comm_size (MPI_Comm comm)
{
int size;
MPI_Comm_size (comm, &size);
return size;
}

int
mpi_get_size (MPI_Group group)
mpi_get_group_size (MPI_Group group)
{
int size;
MPI_Group_size (group, &size);
return size;
}

int
mpi_get_size (MPI_Datatype type)
mpi_get_type_size (MPI_Datatype type)
{
int size;
MPI_Type_size (type, &size);
Expand Down
7 changes: 4 additions & 3 deletions src/multibuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace MUSIC {
MPI_Comm_group (MPI_COMM_WORLD, &worldGroup);
MPI_Group localGroup;
MPI_Comm_group (comm, &localGroup);
int localSize = mpi_get_size (localGroup);
int localSize = mpi_get_group_size (localGroup);

// maps leaders to vectors mapping local ranks to COMM_WORLD ranks
RankMap* rankMap = new RankMap ();
Expand Down Expand Up @@ -250,7 +250,7 @@ namespace MUSIC {
void
MultiBuffer::setupRankMap (int localRank, RankMap* rankMap)
{
int worldSize = mpi_get_size (MPI_COMM_WORLD);
int worldSize = mpi_get_comm_size (MPI_COMM_WORLD);
int worldRank = mpi_get_rank (MPI_COMM_WORLD);
std::vector<RankInfo> rankInfos (worldSize);
rankInfos[worldRank] = RankInfo (localLeader_, localRank);
Expand Down Expand Up @@ -609,7 +609,8 @@ namespace MUSIC {
idstr_ << ':' << cid->first << cid->second;
id_ = "mc" + idstr_.str ();

if (!isContiguous || mpi_get_size (group_) < mpi_get_size (MPI_COMM_WORLD))
if (!isContiguous
|| mpi_get_group_size (group_) < mpi_get_comm_size (MPI_COMM_WORLD))
MPI_Comm_create (MPI_COMM_WORLD, group_, &comm_);
else
comm_ = MPI_COMM_WORLD;
Expand Down
6 changes: 3 additions & 3 deletions src/music/mpi_utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace MUSIC
{
bool mpi_is_initialized ();
int mpi_get_rank (MPI_Comm comm);
int mpi_get_size (MPI_Comm comm);
int mpi_get_size (MPI_Group group);
int mpi_get_size (MPI_Datatype type);
int mpi_get_comm_size (MPI_Comm comm);
int mpi_get_group_size (MPI_Group group);
int mpi_get_type_size (MPI_Datatype type);
MPI_Group mpi_get_group (MPI_Comm comm);
}

Expand Down
2 changes: 1 addition & 1 deletion src/music/multibuffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ namespace MUSIC {
void mergeGroup (int leader, bool isInput);

int rank () const { return mpi_get_rank (comm_); }
int size () const { return mpi_get_size (comm_); }
int size () const { return mpi_get_comm_size (comm_); }
//void setErrorFlag (MultiBuffer::BufferType buffer);
#ifdef MUSIC_TWOSTAGE_ALLGATHER
void processReceived ();
Expand Down
2 changes: 1 addition & 1 deletion src/music/subconnector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace MUSIC {
: Subconnector(type),
CollectiveSubconnector (intracomm),
intervals_ (intervals),
width_ (width * mpi_get_size (type))
width_ (width * mpi_get_type_size (type))
{
allocAllgathervArrays ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace MUSIC {
void
Sampler::initialize ()
{
elementSize = mpi_get_size (dataMap_->type ());
elementSize = mpi_get_type_size (dataMap_->type ());

size = 0;
IndexMap* indices = dataMap_->indexMap ();
Expand Down
4 changes: 2 additions & 2 deletions src/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ namespace MUSIC {
{
ApplicationMap* apps = applicationMap ();
int nRequestedProc = apps->nProcesses ();
int nMPIProc = mpi_get_size (MPI_COMM_WORLD);
int nMPIProc = mpi_get_comm_size (MPI_COMM_WORLD);
if (nMPIProc != nRequestedProc)
{
std::ostringstream msg;
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace MUSIC {
int
Setup::nProcs ()
{
return mpi_get_size (comm);
return mpi_get_comm_size (comm);
}


Expand Down
2 changes: 1 addition & 1 deletion src/spatial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace MUSIC {
: comm(c), indices (ind), type (type_)
{

nProcesses = mpi_get_size (comm);
nProcesses = mpi_get_comm_size (comm);
localRank = mpi_get_rank (comm);
negotiateWidth ();

Expand Down
10 changes: 5 additions & 5 deletions src/subconnector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace MUSIC {

MUSIC_LOGR ("Sending to rank " << remoteRank_);
MPI_Ssend (buffer,
CONT_BUFFER_MAX / mpi_get_size (type_),
CONT_BUFFER_MAX / mpi_get_type_size (type_),
type_,
remoteRank_,
CONT_MSG,
Expand All @@ -126,7 +126,7 @@ namespace MUSIC {
}
MUSIC_LOGR ("Last send to rank " << remoteRank_);
MPI_Ssend (buffer,
size / mpi_get_size (type_),
size / mpi_get_type_size (type_),
type_,
remoteRank_,
CONT_MSG,
Expand Down Expand Up @@ -196,7 +196,7 @@ namespace MUSIC {
char* data;
MPI_Status status;
int size, maxCount;
maxCount = CONT_BUFFER_MAX / mpi_get_size (type_);
maxCount = CONT_BUFFER_MAX / mpi_get_type_size (type_);
do
{
data = static_cast<char*> (buffer_.insertBlock ());
Expand All @@ -216,7 +216,7 @@ namespace MUSIC {
return;
}
MPI_Get_count (&status, type_, &size);
buffer_.trimBlock (mpi_get_size (type_) * size);
buffer_.trimBlock (mpi_get_type_size (type_) * size);
}
while (size == maxCount);
}
Expand Down Expand Up @@ -747,7 +747,7 @@ namespace MUSIC {
void
CollectiveSubconnector::allocAllgathervArrays ()
{
nProcesses = mpi_get_size (intracomm_);
nProcesses = mpi_get_comm_size (intracomm_);
ppBytes = new int[nProcesses];
displ = new int[nProcesses];
}
Expand Down
2 changes: 1 addition & 1 deletion src/temporal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace MUSIC
bool
TemporalNegotiator::hasPeers ()
{
return mpi_get_size (setup_->communicator ()) > 1;
return mpi_get_comm_size (setup_->communicator ()) > 1;
}


Expand Down
4 changes: 2 additions & 2 deletions testsuite/sanitytests/multiport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class OutputPort : public Port {
{
MPI_Comm comm = setup_->communicator ();
int rank = MUSIC::mpi_get_rank (comm);
int nProcesses = MUSIC::mpi_get_size (comm);
int nProcesses = MUSIC::mpi_get_comm_size (comm);

if (indextype == "global")
type = MUSIC::Index::GLOBAL;
Expand Down Expand Up @@ -218,7 +218,7 @@ class InputPort : public Port {
{
MPI_Comm comm = setup_->communicator ();
int rank = MUSIC::mpi_get_rank (comm);
int nProcesses = MUSIC::mpi_get_size (comm);
int nProcesses = MUSIC::mpi_get_comm_size (comm);

if (imaptype == "linear")
{
Expand Down

0 comments on commit f33b66e

Please sign in to comment.