diff --git a/src/application_map.cc b/src/application_map.cc index d28eda8d6b88f54476792fa22baaa8189dfefcbb..8e6e87fd38c309cf47a4ce41cc627d699cec735e 100644 --- a/src/application_map.cc +++ b/src/application_map.cc @@ -19,7 +19,7 @@ #include "music/application_map.hh" #if MUSIC_USE_MPI - #include <mpi.h> +#include "music/mpi_utils.hh" #endif #include "music/ioutils.hh" #include <iostream> @@ -120,8 +120,8 @@ namespace MUSIC { { std::map<int, int> leaders; - int size = MPI::COMM_WORLD.Get_size (); - int my_rank = MPI::COMM_WORLD.Get_rank (); + int size = mpi_get_size (MPI_COMM_WORLD); + int rank = mpi_get_rank (MPI_COMM_WORLD); int *colors = new int[size]; colors[my_rank] = lookup (my_app_label)->color (); MPI::COMM_WORLD.Allgather (MPI::IN_PLACE, 0, MPI::INT, colors, 1, MPI::INT); diff --git a/src/application_mapper.cc b/src/application_mapper.cc index 734931706ccd300c04b06d2010ecdf43b61c1bfd..5d3992586d364b18efabbc696df6e67245e48f48 100644 --- a/src/application_mapper.cc +++ b/src/application_mapper.cc @@ -87,9 +87,8 @@ namespace MUSIC { } else { - - int my_rank = MPI::COMM_WORLD.Get_rank (); - int nRanks = MPI::COMM_WORLD.Get_size (); + int nRanks = mpi_get_size (MPI_COMM_WORLD); + int my_rank = mpi_get_rank (MPI_COMM_WORLD); #if HAVE_SYS_STAT_H diff --git a/src/collector.cc b/src/collector.cc index a95b2fae3bf39ea1709b5185d1d13be3c7d3a148..5d76ca838fb2269e4566756b2d0df8ccc6710eee 100644 --- a/src/collector.cc +++ b/src/collector.cc @@ -104,7 +104,7 @@ namespace MUSIC { BIFO* buffer = b->first; Intervals& intervals = b->second; sort (intervals.begin (), intervals.end ()); - int elementSize = dataMap->type ().Get_size (); + int elementSize = mpi_get_size (dataMap->type ()); int size = 0; for (Intervals::iterator i = intervals.begin (); i != intervals.end (); diff --git a/src/distributor.cc b/src/distributor.cc index 374be25788d1d01e08c145db4fc6ff05c569ba15..40be7d84c4ce2de050be9013af7a1b73590b027f 100644 --- a/src/distributor.cc +++ b/src/distributor.cc @@ -104,7 +104,7 @@ namespace MUSIC { FIBO* buffer = b->first; Intervals& intervals = b->second; sort (intervals.begin (), intervals.end ()); - int elementSize = dataMap->type ().Get_size (); + int elementSize = mpi_get_size (dataMap->type ()); int size = 0; for (Intervals::iterator i = intervals.begin (); i != intervals.end (); diff --git a/src/error.cc b/src/error.cc index 583ad003bb1b928aee22b101d550133a9e4946ad..4a2a47c4ca8b26f8b1ee05eb384c3769db0548cb 100644 --- a/src/error.cc +++ b/src/error.cc @@ -68,8 +68,10 @@ namespace MUSIC { getRank () { #if MUSIC_USE_MPI - if (MPI::Is_initialized ()) - return MPI::COMM_WORLD.Get_rank (); + int isInitialized; + MPI_Initialized (&isInitialized); + if (isInitialized) + return mpi_get_rank (MPI_COMM_WORLD); #endif return -1; } diff --git a/src/event_router.cc b/src/event_router.cc index ab24ad156e7fe4817a98a4d8b218a111336d5326..efd0d377c2cda3978953e5ebedd92c509a01e12a 100644 --- a/src/event_router.cc +++ b/src/event_router.cc @@ -58,7 +58,7 @@ namespace MUSIC { } #if 0 if (size - size_ != extra_.size ()) - std::cout << "Rank " << MPI::COMM_WORLD.Get_rank () + std::cout << "Rank " << mpi_get_rank (MPI_COMM_WORLD) << ": DirectRouter: Had " << extra_.size () << " extra spike space, size changed from " << size_ << " to " << size << " = " << size - size_ diff --git a/src/multibuffer.cc b/src/multibuffer.cc index 2aba01612055e1c73b97f423be309c2688b8c3d7..bfaf92112be34cdf2b45ccc27d8616473a8852ed 100644 --- a/src/multibuffer.cc +++ b/src/multibuffer.cc @@ -45,16 +45,18 @@ namespace MUSIC { { //bool hang = true; //while (hang) ; - MPI::Group worldGroup = MPI::COMM_WORLD.Get_group (); - MPI::Group localGroup = comm.Get_group (); - int localSize = localGroup.Get_size (); + MPI_Group worldGroup; + MPI_Comm_group (MPI_COMM_WORLD, &worldGroup); + MPI_Group localGroup; + MPI_Comm_group (comm, &localGroup); + int localSize = mpi_get_size (localGroup); // maps leaders to vectors mapping local ranks to COMM_WORLD ranks RankMap* rankMap = new RankMap (); - setupRankMap (comm.Get_rank (), rankMap); + setupRankMap (mpi_get_rank (comm), rankMap); #if 0 std::ostringstream ostr; - ostr << "Rank " << MPI::COMM_WORLD.Get_rank () << ": rankMap "; + ostr << "Rank " << mpi_get_rank (MPI::COMM_WORLD) << ": rankMap "; for (RankMap::iterator i = rankMap->begin (); i != rankMap->end (); ++i) @@ -119,7 +121,7 @@ namespace MUSIC { // create OutputSubconnectorInfo OutputSubconnector* s = dynamic_cast<OutputSubconnector*> (connector->subconnector ()); - BufferInfo* bi = &*(isi.begin () + comm.Get_rank ()); + BufferInfo* bi = &*(isi.begin () + mpi_get_rank (comm)); outputConnectorMap_.insert (OutputConnectorMap::value_type (connector, OutputSubconnectorInfo (s, bi))); @@ -188,7 +190,7 @@ namespace MUSIC { #if 0 { std::ostringstream ostr; - ostr << "Rank " << MPI::COMM_WORLD.Get_rank () << ": block_ ranks "; + ostr << "Rank " << mpi_get_rank (MPI::COMM_WORLD) << ": block_ ranks "; for (Blocks::iterator b = block_.begin (); b != block_.end (); ++b) ostr << b->rank () << ' '; std::cout << ostr.str () << std::endl; @@ -249,8 +251,8 @@ namespace MUSIC { void MultiBuffer::setupRankMap (int localRank, RankMap* rankMap) { - int worldRank = MPI::COMM_WORLD.Get_rank (); - int worldSize = MPI::COMM_WORLD.Get_size (); + int worldSize = mpi_get_size (MPI_COMM_WORLD); + int worldRank = mpi_get_rank (MPI_COMM_WORLD); std::vector<RankInfo> rankInfos (worldSize); rankInfos[worldRank] = RankInfo (localLeader_, localRank); MPI::COMM_WORLD.Allgather (MPI::IN_PLACE, 0, MPI::DATATYPE_NULL, @@ -298,7 +300,7 @@ namespace MUSIC { // compute required total size unsigned int summedSize = 0; unsigned int thisRankSize = 0; - int thisRank = MPI::COMM_WORLD.Get_rank (); + int thisRank = mpi_get_rank (MPI::COMM_WORLD); for (Blocks::iterator b = block_.begin (); b != block_.end (); ++b) { unsigned int size; @@ -386,7 +388,7 @@ namespace MUSIC { // current rank => error staging area is used for // requested buffer sizes and buffer contains output // data - if (b->rank () == MPI::COMM_WORLD.Get_rank () + if (b->rank () == mpi_get_rank (MPI_COMM_WORLD) && newStart > oldPos) memmove (buffer_ + newStart, buffer_ + oldPos, @@ -552,7 +554,7 @@ namespace MUSIC { { #ifdef MUSIC_DEBUG std::ostringstream ostr; - ostr << "Rank " << MPI::COMM_WORLD.Get_rank () << ": Create "; + ostr << "Rank " << mpi_get_rank (MPI_COMM_WORLD) << ": Create "; #endif int nRanges = 0; for (GroupMap::iterator g = groupMap_->begin (); @@ -624,7 +626,7 @@ namespace MUSIC { { Blocks::iterator b = multiBuffer_->getBlock (indices[rank]); #ifdef MUSIC_DEBUG - if (b == multiBuffer_->blockEnd () && MPI::COMM_WORLD.Get_rank () == 0) + if (b == multiBuffer_->blockEnd () && mpi_get_rank (MPI_COMM_WORLD) == 0) { std::cout << "asked for rank " << indices[rank] << " among:" << std::endl; multiBuffer_->dumpBlocks (); @@ -861,12 +863,12 @@ namespace MUSIC { { std::ostringstream ostr; #if 1 - ostr << "Rank " << MPI::COMM_WORLD.Get_rank () << ": " + ostr << "Rank " << mpi_get_rank (MPI_COMM_WORLD) << ": " << id << ": Allgather " << *recvc; for (int i = 1; i < n; ++i) ostr << ", " << recvc[i]; #else - ostr << "Rank " << MPI::COMM_WORLD.Get_rank () << ": " + ostr << "Rank " << mpi_get_rank (MPI_COMM_WORLD) << ": " << id << ": Allgather " << *displs << ':' << *recvc; for (int i = 1; i < n; ++i) diff --git a/src/music/debug.hh b/src/music/debug.hh index 03bdb8888a496cd7eea3bef738041650ced2896a..4b09c7e9ff3e379dfdfb1b8c67cd0f6ac1883a8f 100644 --- a/src/music/debug.hh +++ b/src/music/debug.hh @@ -24,19 +24,19 @@ #define MUSIC_LOG(X) (std::cerr << X << std::endl << std::flush) #if MUSIC_USE_MPI #define MUSIC_LOGN(N, X) \ - { if (MPI::COMM_WORLD.Get_rank () == N) MUSIC_LOG (X); } + { if (mpi_get_rank (MPI_COMM_WORLD) == N) MUSIC_LOG (X); } #define MUSIC_LOG0(X) MUSIC_LOGN (0, X) #define MUSIC_LOGR(X) \ { \ - std::cerr << MPI::COMM_WORLD.Get_rank () << ": " \ + std::cerr << mpi_get_rank (MPI_COMM_WORLD) << ": " \ << X << std::endl << std::flush; \ } #define MUSIC_LOGRE(X) \ { \ - int _r = MPI::COMM_WORLD.Get_rank (); \ + int _r = mpi_get_rank (MPI_COMM_WORLD); \ char* _e = getenv ("MUSIC_DEBUG_RANK"); \ if (_e != NULL && atoi (_e) == _r) \ { \ diff --git a/src/music/multibuffer.hh b/src/music/multibuffer.hh index 53cea7212c1d7ef1ec8002faa1bb66dc05a5101e..074b7e6f2f76522f8a3b0383ab98022f650b663e 100644 --- a/src/music/multibuffer.hh +++ b/src/music/multibuffer.hh @@ -154,7 +154,7 @@ namespace MUSIC { bool errorFlag (BufferType buffer) const { //*fixme* Can set start_ to proper offset - unsigned int offset = rank_ == MPI::COMM_WORLD.Get_rank () ? 0 : start_; + unsigned int offset = rank_ == mpi_get_rank (MPI_COMM_WORLD) ? 0 : start_; return *headerPtr (buffer + offset) & MultiBuffer::ERROR_FLAG; } void clearBufferFlags (BufferType buffer) @@ -175,7 +175,7 @@ namespace MUSIC { } unsigned int requestedDataSize (BufferType buffer, int i) const { - unsigned int offset = rank_ == MPI::COMM_WORLD.Get_rank () ? 0 : start_; + unsigned int offset = rank_ == mpi_get_rank (MPI_COMM_WORLD) ? 0 : start_; return headerPtr (buffer + offset)[1 + i]; } BufferInfoPtrs::iterator begin () { return bufferInfoPtr_.begin (); } @@ -345,8 +345,8 @@ namespace MUSIC { void processInput (); void mergeGroup (int leader, bool isInput); - int rank () const { return comm_.Get_rank (); } - int size () const { return comm_.Get_size (); } + int rank () const { return mpi_get_rank (comm_); } + int size () const { return mpi_get_size (comm_); } //void setErrorFlag (MultiBuffer::BufferType buffer); #ifdef MUSIC_TWOSTAGE_ALLGATHER void processReceived (); diff --git a/src/music/subconnector.hh b/src/music/subconnector.hh index 53bd70aa78de84146f10808a6d5f0b7970e2da23..cd9db03129b72342b96de2f2db7fd1539d12fd04 100644 --- a/src/music/subconnector.hh +++ b/src/music/subconnector.hh @@ -74,7 +74,7 @@ namespace MUSIC { virtual void maybeCommunicate (std::vector<MPI_Request> &) {}; virtual void flush (bool& dataStillFlowing) = 0; bool isFlushed () { return flushed; } - int localRank () const { return intercomm.Get_rank (); } + int localRank () const { return mpi_get_rank (intercomm); } int remoteRank () const { return remoteRank_; } //*fixme* are the following still needed or can they be removed? int remoteWorldRank () const { return remoteWorldRank_; } @@ -352,8 +352,8 @@ namespace MUSIC { MPI_Datatype type) : Subconnector(type), CollectiveSubconnector (intracomm), - intervals_(intervals), - width_(width*type.Get_size ()) + intervals_ (intervals), + width_ (width * mpi_get_size (type)) { allocAllgathervArrays (); } diff --git a/src/port.cc b/src/port.cc index 286ae8b2fb5430650b9566d00b08a39515c7cab5..5e65662a676cf3af1b80c5bcf289e00856f2381d 100644 --- a/src/port.cc +++ b/src/port.cc @@ -631,7 +631,7 @@ namespace MUSIC { ********************************************************************/ MessagePort::MessagePort (Setup* s) - : rank_ (s->communicator ().Get_rank ()) + : rank_ (mpi_get_rank (s->communicator ())) { } diff --git a/src/runtime.cc b/src/runtime.cc index 8461830ef4fded3c13a0561afb9f04a569ba34f4..8de2775744222b21dab2f7dd8d66bff591017810 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -112,7 +112,7 @@ namespace MUSIC delete s; #ifdef MUSIC_AFTER_RUNTIME_CONSTRUCTOR_REPORT - if (MPI::COMM_WORLD.Get_rank () == 0) + if (mpi_get_rank (MPI_COMM_WORLD) == 0) reportMem (); #if 0 // Code used for debugging and analysis @@ -408,7 +408,7 @@ namespace MUSIC if (multiConnectors[multiId] == NULL) { - std::cout << "Rank " << MPI::COMM_WORLD.Get_rank () + std::cout << "Rank " << mpi_get_rank (MPI_COMM_WORLD) << " aborting on multiId " << multiId << " remote leader = " << connector->remoteLeader () << std::endl; @@ -504,7 +504,7 @@ namespace MUSIC } } - //if (MPI::COMM_WORLD.Get_rank () == 2) + //if (mpi_get_rank (MPI_COMM_WORLD) == 2) // std::cout << "multiId = " << multiId << std::endl; if (multiConnectors[multiId] == NULL) { diff --git a/src/sampler.cc b/src/sampler.cc index 0fbf62091bb603bea5edaced5e60a3d1a9af8273..dead7973d9a41b1cda848518fc478489c4dd9cd8 100644 --- a/src/sampler.cc +++ b/src/sampler.cc @@ -64,7 +64,7 @@ namespace MUSIC { void Sampler::initialize () { - elementSize = dataMap_->type ().Get_size (); + elementSize = mpi_get_size (dataMap_->type ()); size = 0; IndexMap* indices = dataMap_->indexMap (); diff --git a/src/scheduler.cc b/src/scheduler.cc index 11bccc638cedc775f263a3ea677951b534920dbb..1ff8d1d79a16521fbc3958f5fe2988c0c658dc42 100644 --- a/src/scheduler.cc +++ b/src/scheduler.cc @@ -181,7 +181,7 @@ namespace MUSIC MultiBuffer* multiBuffer, std::vector<MultiConnector*>& multiConnectors) { - //if (MPI::COMM_WORLD.Get_rank () == 2) + //if (mpi_get_rank (MPI_COMM_WORLD) == 2) // std::cout << "prep localTime = " << localTime.time () << std::endl; // We need to create the MultiConnectors ahead of time since their // creation requires communication between all members of @@ -377,7 +377,7 @@ namespace MUSIC } } - //if (MPI::COMM_WORLD.Get_rank () == 2) + //if mpi_get_rank ((MPI_COMM_WORLD) == 2) // std::cout << "Prep multiId = " << multiId << std::endl; if (cCache.size () == 0) { diff --git a/src/scheduler_agent.cc b/src/scheduler_agent.cc index 68262b5d8215805209b977951edb388f7f8dc55f..036e4581bdaad5a43619d53c6c13d1aaa29c7c18 100644 --- a/src/scheduler_agent.cc +++ b/src/scheduler_agent.cc @@ -238,7 +238,7 @@ namespace MUSIC unsigned int proxyId = (*comm).proxyId (); if (proxyId != 0 && ! (*multiProxies)[proxyId]) { - // std::cout << "Rank " << MPI::COMM_WORLD.Get_rank () + // std::cout << "Rank " << mpi_get_rank (MPI_COMM_WORLD) // << ": Proxy " << proxyId << std::endl; MPI::COMM_WORLD.Create (MPI::GROUP_EMPTY); MPI::COMM_WORLD.Barrier (); diff --git a/src/setup.cc b/src/setup.cc index ca20ba5631df4117d136aaee95a029f29af2c1d3..363f994e7665eb73d0d2404c2b180965983c306c 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -92,7 +92,7 @@ namespace MUSIC { void Setup::init (int& argc, char**& argv) { - int myRank = MPI::COMM_WORLD.Get_rank (); + int myRank = mpi_get_rank (MPI_COMM_WORLD); std::string config = ""; launchedByMusic_ = false; postponeSetup_ = false; @@ -208,7 +208,7 @@ namespace MUSIC { std::ifstream config; char* buffer; int size = 0; - int myRank = MPI::COMM_WORLD.Get_rank (); + int myRank = mpi_get_rank (MPI_COMM_WORLD); // Rank #0 is reading a file and broadcast it to each rank in the launch if (myRank == 0) { @@ -286,7 +286,7 @@ namespace MUSIC { { ApplicationMap* apps = applicationMap (); int nRequestedProc = apps->nProcesses (); - int nMPIProc = MPI::COMM_WORLD.Get_size (); + int nMPIProc = mpi_get_size (MPI_COMM_WORLD); if (nMPIProc != nRequestedProc) { std::ostringstream msg; @@ -365,7 +365,7 @@ namespace MUSIC { int Setup::nProcs () { - return comm.Get_size (); + return mpi_get_size (comm); } diff --git a/src/spatial.cc b/src/spatial.cc index ade4d94ffa80df9212b32a532689067160eb897c..49875b08bd049de57aa412492bd6f60d9cf6d218 100644 --- a/src/spatial.cc +++ b/src/spatial.cc @@ -140,8 +140,8 @@ namespace MUSIC { : comm(c), indices (ind), type (type_) { - nProcesses = comm.Get_size (); - localRank = comm.Get_rank (); + nProcesses = mpi_get_size (comm); + localRank = mpi_get_rank (comm); negotiateWidth (); } diff --git a/src/subconnector.cc b/src/subconnector.cc index da83268eac39799ccdd074c29688fcb9f27cd612..f2e206fd7a7a4a1a078dd439d892ab3c9e73f4ec 100644 --- a/src/subconnector.cc +++ b/src/subconnector.cc @@ -194,7 +194,7 @@ namespace MUSIC { char* data; MPI_Status status; int size, maxCount; - maxCount = CONT_BUFFER_MAX / type_.Get_size (); + maxCount = CONT_BUFFER_MAX / mpi_get_size (type_); do { data = static_cast<char*> (buffer_.insertBlock ()); @@ -733,7 +733,7 @@ namespace MUSIC { void CollectiveSubconnector::allocAllgathervArrays () { - nProcesses = intracomm_.Get_size (); + nProcesses = mpi_get_size (intracomm_); ppBytes = new int[nProcesses]; displ = new int[nProcesses]; } diff --git a/src/temporal.cc b/src/temporal.cc index 94f54364e76b6216895f74b0e180acbaba3a54fd..4fd13dfc727a8ed26e55c791c6ce022338d6bc3d 100644 --- a/src/temporal.cc +++ b/src/temporal.cc @@ -75,14 +75,14 @@ namespace MUSIC bool TemporalNegotiator::isLeader () { - return setup_->communicator ().Get_rank () == 0; + return mpi_get_rank (setup_->communicator ()) == 0; } bool TemporalNegotiator::hasPeers () { - return setup_->communicator ().Get_size () > 1; + return mpi_get_size (setup_->communicator ()) > 1; }