ENH: provide getter/setter interface to standard communicators

- similar to UPstream::parRun(), the setter returns the previous value.

  The accessors are prefixed with 'comm':
  Eg, commGlobal(), commWarn(), commWorld(), commSelf().
  This distinguishes them from any existing variables (eg, worldComm)
  and arguably more similar to MPI_COMM_WORLD etc...

  If demand-driven communicators are added in the future, the function
  call syntax can help encapsulate that.

  Previously:

      const label oldWarnComm = UPstream::warnComm;
      const label oldWorldComm = UPstream::worldComm;
      UPstream::warnComm = myComm;
      UPstream::worldComm = myComm;
      ...

      UPstream::warnComm = oldWarnComm;
      UPstream::worldComm = oldWorldComm;

  Now:
      const label oldWarnComm = UPstream::commWarn(myComm);
      const label oldWorldComm = UPstream::commWorld(myComm);
      ...

      UPstream::commWarn(oldWarnComm);
      UPstream::commWorld(oldWorldComm);

STYLE: check (warnComm >= 0) instead of (warnComm != -1)
This commit is contained in:
Mark Olesen
2023-03-09 12:57:41 +00:00
parent 06df44a588
commit 20566a87f5
15 changed files with 155 additions and 128 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -80,8 +80,7 @@ void Foam::functionObjects::syncObjects::sync()
return;
}
const label oldWarnComm = UPstream::warnComm;
UPstream::warnComm = 0;
const label oldWarnComm = UPstream::commWarn(UPstream::commGlobal());
// Send my data to all other processors
@ -90,7 +89,7 @@ void Foam::functionObjects::syncObjects::sync()
// Note provision of explicit all-world communicator
PstreamBuffers pBufs
(
UPstream::globalComm,
UPstream::commGlobal(),
UPstream::commsTypes::nonBlocking
);
@ -164,7 +163,8 @@ void Foam::functionObjects::syncObjects::sync()
// Pout<< type() << " : after synchronisation:" << allDict << endl;
//}
UPstream::warnComm = oldWarnComm;
// Restore communicator settings
UPstream::commWarn(oldWarnComm);
}