72 if (str.empty() || !
Foam::read(str, len) || len <= 0)
82 if (Foam::UPstream::debug)
84 Foam::Pout<<
"UPstream::init : buffer-size " << len <<
'\n';
87 char* buf =
new char[len];
89 if (MPI_SUCCESS != MPI_Buffer_attach(buf, len))
92 Foam::Pout<<
"UPstream::init : could not attach buffer\n";
114 if (MPI_SUCCESS == MPI_Buffer_detach(&buf, &len) && len)
130 validParOptions.insert(
"np",
"");
131 validParOptions.insert(
"p4pg",
"PI file");
132 validParOptions.insert(
"p4wd",
"directory");
133 validParOptions.insert(
"p4amslave",
"");
134 validParOptions.insert(
"p4yourname",
"hostname");
135 validParOptions.insert(
"machinefile",
"machine file");
143 MPI_Finalized(&flag);
148 <<
"MPI was already finalized - cannot perform MPI_Init\n"
154 MPI_Initialized(&flag);
159 Pout<<
"UPstream::initNull : was already initialized\n";
185 int numprocs = 0, myRank = 0;
186 int provided_thread_support = 0;
189 MPI_Finalized(&flag);
194 <<
"MPI was already finalized - cannot perform MPI_Init" <<
endl
200 MPI_Initialized(&flag);
209 <<
"MPI was already initialized - cannot perform MPI_Init" <<
nl
210 <<
"This could indicate an application programming error!"
217 Pout<<
"UPstream::init : was already initialized\n";
228 ? MPI_THREAD_MULTIPLE
231 &provided_thread_support
238 label worldIndex = -1;
240 for (
int argi = 1; argi < argc; ++argi)
242 if (strcmp(argv[argi],
"-world") == 0)
248 <<
"Missing world name to argument \"world\""
257 if (worldIndex != -1)
259 for (label i = worldIndex+2; i < argc; i++)
266 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
267 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
271 Pout<<
"UPstream::init :"
272 <<
" thread-support : wanted:" << needsThread
275 provided_thread_support == MPI_THREAD_MULTIPLE
276 ?
"MPI_THREAD_MULTIPLE"
277 :
"MPI_THREAD_SINGLE"
279 <<
" procs:" << numprocs
280 <<
" rank:" << myRank
281 <<
" world:" << world <<
endl;
284 if (worldIndex == -1 && numprocs <= 1)
287 <<
"attempt to run parallel on 1 processor"
292 setParRun(numprocs, provided_thread_support == MPI_THREAD_MULTIPLE);
294 if (worldIndex != -1)
304 DynamicList<word> allWorlds(numprocs);
305 for (
const word& world : worlds)
307 allWorlds.appendUniq(world);
309 allWorlds_ = std::move(allWorlds);
311 worldIDs_.setSize(numprocs);
314 const word& world = worlds[proci];
315 worldIDs_[proci] = allWorlds_.find(world);
320 DynamicList<label> subRanks;
325 subRanks.append(proci);
330 const label subComm = allocateCommunicator(0, subRanks,
true);
340 int subNProcs, subRank;
352 Pout<<
"UPstream::init : in world:" << world
353 <<
" using local communicator:" << subComm
354 <<
" with procs:" << subNProcs
355 <<
" and rank:" << subRank
360 Pout.
prefix() =
'[' + world +
'/' +
name(myProcNo(subComm)) +
"] ";
361 Perr.
prefix() =
'[' + world +
'/' +
name(myProcNo(subComm)) +
"] ";
366 worldIDs_.setSize(numprocs, 0);
379 Pout<<
"UPstream::shutdown\n";
384 MPI_Initialized(&flag);
391 MPI_Finalized(&flag);
398 <<
"MPI was already finalized (by a connected program?)\n";
402 Pout<<
"UPstream::shutdown : was already finalized\n";
413 label nOutstanding = 0;
428 <<
"There were still " << nOutstanding
429 <<
" outstanding MPI_Requests." <<
nl
430 <<
"Which means your code exited before doing a "
431 <<
" UPstream::waitRequests()." <<
nl
432 <<
"This should not happen for a normal code exit."
438 forAll(myProcNo_, communicator)
440 if (myProcNo_[communicator] != -1)
442 freePstreamCommunicator(communicator);
453 <<
"Finalizing MPI, but was initialized elsewhere\n";
463 MPI_Abort(MPI_COMM_WORLD, errNo);
478 MPI_Abort(MPI_COMM_WORLD, 1);
484void Foam::UPstream::allocatePstreamCommunicator
486 const label parentIndex,
493 MPI_Group newGroup = MPI_GROUP_NULL;
495 MPI_Comm newComm = MPI_COMM_NULL;
501 <<
"PstreamGlobals out of sync with UPstream data. Problem."
506 if (parentIndex == -1)
513 <<
"world communicator should always be index "
530 procIDs_[index].setSize(numProcs);
531 forAll(procIDs_[index], i)
533 procIDs_[index][i] = i;
542 procIDs_[index].size(),
543 procIDs_[index].cdata(),
547 #if defined(MSMPI_VER)
557 MPI_Comm_create_group
568 myProcNo_[index] = -1;
583 <<
" when allocating communicator at " << index
584 <<
" from ranks " << procIDs_[index]
585 <<
" of parent " << parentIndex
586 <<
" cannot find my own rank"
594void Foam::UPstream::freePstreamCommunicator(
const label communicator)
596 if (communicator != 0)
631 Pout<<
"UPstream::waitRequests : starting wait for "
633 <<
" outstanding requests starting at " << start <<
endl;
638 SubList<MPI_Request> waitRequests
658 <<
"MPI_Waitall returned with error" <<
Foam::endl;
663 resetRequests(start);
668 Pout<<
"UPstream::waitRequests : finished wait." <<
endl;
677 Pout<<
"UPstream::waitRequest : starting wait for request:" << i
685 <<
" outstanding send requests and you are asking for i=" << i
687 <<
"Maybe you are mixing blocking/non-blocking comms?"
703 <<
"MPI_Wait returned with error" <<
Foam::endl;
712 Pout<<
"UPstream::waitRequest : finished wait for request:" << i
722 Pout<<
"UPstream::finishedRequest : checking request:" << i
730 <<
" outstanding send requests and you are asking for i=" << i
732 <<
"Maybe you are mixing blocking/non-blocking comms?"
746 Pout<<
"UPstream::finishedRequest : finished request:" << i
768 Pout<<
"UPstream::allocateTag "
769 <<
s <<
" : tag:" << tag <<
endl;
790 Pout<<
"UPstream::allocateTag "
791 <<
s.c_str() <<
" : tag:" << tag <<
endl;
802 Pout<<
"UPstream::freeTag "
803 <<
s <<
" tag:" << tag <<
endl;
813 Pout<<
"UPstream::freeTag "
814 <<
s.c_str() <<
" tag:" << tag <<
endl;
Inter-processor communication reduction functions.
static void detachOurBuffers()
static void attachOurBuffers()
T remove()
Remove and return the last element. Fatal on an empty list.
void append(const T &val)
Copy append an element to the end of this list.
void exit()
Job end with "exit" termination.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
static void broadcast(Type &value, const label comm=UPstream::worldComm)
static void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all processes in communicator.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
static void freeTag(const char *, const int tag)
static bool initNull()
Special purpose initialisation function.
static int allocateTag(const char *)
static int & msgType() noexcept
Message tag of standard messages.
static const int mpiBufferSize
MPI buffer-size (bytes)
static label worldComm
Default communicator (all processors)
static label nRequests()
Get number of outstanding requests.
static void addValidParOptions(HashTable< string > &validParOptions)
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
static void resetRequests(const label sz)
Truncate number of outstanding requests.
static void abort()
Call MPI_Abort with no other checks or cleanup.
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished?
static void waitRequest(const label i)
Wait until request i has finished.
void shutdown() const
Generate status=done in lock (only when run-state = master)
const string & prefix() const noexcept
Return the stream prefix.
int myProcNo() const noexcept
Return processor number.
static void beginTiming()
Update timer prior to measurement.
static void addWaitTime()
Add time increment to waitTime.
splitCell * master() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define WarningInFunction
Report a warning using Foam::Warning.
DynamicList< MPI_Request > outstandingRequests_
Outstanding non-blocking operations.
DynamicList< label > freedRequests_
DynamicList< MPI_Comm > MPICommunicators_
DynamicList< MPI_Group > MPIGroups_
DynamicList< int > freedTags_
Free'd message tags.
int nTags_
Max outstanding message tag operations.
string getEnv(const std::string &envName)
Get environment value for given envName.
List< word > wordList
A List of words.
bool read(const char *buf, int32_t &val)
Same as readInt32.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.