Commit Graph

98 Commits

Author SHA1 Message Date
Mark Olesen
09377471a3 ENH: stricter handling when freeing communicator components
- previously automatically skipped the first communicator (which was
  assumed to be MPI_COMM_WORLD), but now simply rely on the
  internal pendingMPIFree_ to track which communicators have actually
  been allocated.
2024-04-23 10:58:41 +02:00
Mark Olesen
97668eab26 STYLE: update noexcept and default construct for signals
- eliminate ClassName in favour of simple debug

- include Apple-specific FPE handling after local definition
  to allow for more redefinitions

COMP: remove stray <csignal> includes
2023-08-18 15:42:18 +02:00
Mark Olesen
3de090e602 BUG: UPstream::shutdown misbehaves with external initialisation (fixes #2808)
- freeCommmunicatorComponents needs an additional bounds check.
  When MPI is initialized outside of OpenFOAM, there are no
  UPstream communicator equivalents
2023-06-20 09:10:47 +02:00
Mark Olesen
4412566c58 ENH: support command-line specification of MPI threads (#2791)
- MPI_THREAD_MULTIPLE is usually undesirable for performance reasons,
  but in some cases may be necessary if a linked library expects it.
  Provide a '-mpi-threads' option to explicitly request it.

ENH: consolidate some looping logic within argList
2023-06-19 17:05:45 +02:00
Mark Olesen
9489a5a101 COMP: replace selfComm/globalComm variables with functions instead (#2799)
- with C++11, static constexpr variables apparently also require
  definition in a translation unit and not just as inlined quantities.
  Mostly not an issue, however gcc with -O0 does not do the inlining
  and thus actually requires them to be defined in a translation unit
  as well.

  These variables were provided for symmetry with worldComm, but only
  used in low-level internal code. Changing to inlined functions
  solves the linkage issue and also aligns with the commWorld()
  function naming.

Mnemonics:
   MPI_COMM_SELF           => UPstream::commSelf()
   overall MPI_COMM_WORLD  => UPstream::commGlobal(), sometimes commWorld()
   local COMM_WORLD        => UPstream::commWorld()
2023-06-14 13:55:38 +02:00
Mark Olesen
b687c4927c ENH: update UPstream communicator handling
UPstream::allocateCommunicator
  - with contiguous sub-procs. Simpler, more compact handling, ranks
    are guaranteed to be monotonic

UPstream::commWorld(label)
  - ignore placeholder values, prevents accidental negative values

- make communicator non-optional for UPstream::broadcast(), which
  means it has three mandatory parameters and thus always fully
  disambiguated from Pstream::broadcast().

ENH: relax size checking on gatherList/scatterList

- only fatal if the List size is less than nProcs.
  Can silent ignore any trailing elements: they will be untouched.
2023-05-22 17:13:41 +02:00
Mark Olesen
50f4d0444c ENH: avoid synchronization on UPstream::shutdown with error (#2774)
- UPstream exit with a non-zero return code is raised by things like
  exit(FatalError) which means there is no reason to believe that
  any/all of the buffered sends, requests etc have completed.

  Thus avoid detaching buffers, freeing communicators etc in this
  situation. This makes exit(1) behave much more like abort(), but
  without any stack trace. Should presumably help with avoiding
  deadlocks on exit.
2023-05-09 14:51:43 +02:00
Mark Olesen
639b800049 ENH: clearer separation of MPI initialize/finalize stages (#2774)
ENH: support transfer from a wrapped MPI request to global list

- allows coding with a list UPstream::Request and subsequently either
  retain that list or transfer into the global list.
2023-05-09 14:51:43 +02:00
Mark Olesen
ce282dfbbf ENH: correct the selfComm procNo relative to world communicator
STYLE: qualify worldComm as UPstream instead Pstream

STYLE: PPCG::gSumMagProd() as static function
2023-04-24 15:46:04 +02:00
Mark Olesen
80bc1db5b7 ENH: provide UPstream intra-host and inter-host communicators
- simplifies communication structuring with intra-host communication.
  Can be used for IO only, or for specialised communication.

  Demand-driven construction. Gathers the SHA1 of host names when
  determining the connectivity. Internally uses an MPI_Gather of the
  digests and a MPI_Bcast of the unique host indices.

  NOTE:
    does not use MPI_Comm_splt or MPI_Comm_splt_type since these
    return MPI_COMM_NULL on non-participating process which does not
    easily fit into the OpenFOAM framework.

    Additionally, if using the caching version of
    UPstream::commInterHost() and UPstream::commIntraHost()
    the topology is determined simultaneously
    (ie, equivalent or potentially lower communication).
2023-04-18 14:08:39 +02:00
Mark Olesen
9d3427e0b4 ENH: consolidate UPstream::commsStruct code
- make sizing of commsStruct List demand-driven as well
  for more robustness, fewer unneeded allocations.

- fix potential latent bug with allBelow/allNotBelow for proc 0
  (linear communication).

ENH: remove unused/unusable UPstream::communicator optional parameter

- had constructor option to avoid constructing the MPI backend,
  but this is not useful and inconsistent with what the reset or
  destructor expect.

STYLE: local use of UPstream::communicator

- automatically frees communicator when it leaves scope
2023-04-18 14:08:39 +02:00
Mark Olesen
b277b913cf ENH: add guards for partially populated communicators
- these are primarily when encountering sparse (eg, inter-host)
  communicators. Additional UPstream convenience methods:

  is_rank(comm)
    => True if process corresponds to a rank in the communicators.
       Can be a master rank or a sub-rank.

  is_parallel(comm)
    => True if parallel algorithm or exchange is used on the process.
       same as

           (parRun() && (nProcs(comm) > 1) && is_rank(comm))
2023-04-18 14:08:39 +02:00
Mark Olesen
74db18a9c3 ENH: add interface code for MPI_Allgather
COMP: incorrect macro declaration for mpiGather/mpiScatter
2023-04-18 14:08:39 +02:00
Mark Olesen
89e1d8c269 ENH: restrict use of MPI_Group to local scope
- don't need to retain group references globally.
  Just retrieve parent group reference on-demand and discard
  immediately afterwards.
2023-04-11 16:00:12 +02:00
Mark Olesen
aa002122c2 ENH: simplify handling of pushed/freed requests
- previously had an additional stack for freedRequests_,
  which were used to 'remember' locations into the list of
  outstandingRequests_ that were handled by 'waitRequest()'.

  This was principally done for sanity checks on shutdown,
  but we now just test for any outstanding requests that
  are *not* MPI_REQUEST_NULL instead (much simpler).

  The framework with freedRequests_ also had a provision to 'recycle'
  them by popping from that stack, but this is rather fragile since it
  would only triggered by some collectives
  (MPI_Iallreduce, MPI_Ialltoall, MPI_Igather, MPI_Iscatter)
  with no guarantee that these will all be properly removed again.
  There was also no pruning of extraneous indices.

ENH: consolidate internal reset/push of requests

- replace duplicate code with inline functions
  reset_request(), push_request()

ENH: null out trailing requests

- extra safety (paranoia) for the UPstream::Request versions
  of finishedRequests(), waitAnyRequest()

CONFIG: document nPollProcInterfaces in etc/controlDict

- still experimental, but at least make the keyword known
2023-04-08 18:46:39 +02:00
Mark Olesen
700156b4c5 DEFEATURE: remove unused UPstream allocateTag(), freeTag() routines
- mechanism has been unused for at least a decade or more
  (or was never used). Message tags are assigned on an ad hoc basis
  locally when collision avoidance is necessary.
2023-04-08 18:33:52 +02:00
Mark Olesen
9577a0f6b5 ENH: extend parProfiling (#2737)
- separate broadcast times from reduce/gather/scatter time
- separate wait times from all-to-all time
- support invocation counts, split off requests time/count
  from others to avoid flooding the counts

- support 'detail' switch to increase the output information.
  Format may change in the future
2023-04-05 11:33:39 +02:00
Mark Olesen
a7d77391fa BUG: selfComm had 0 instead of parent rank for UPstream::procID (#2706) 2023-02-21 09:29:44 +01:00
Mark Olesen
74fd94dff3 REGRESSION: overly aggressive handling of MPI groups
- attempted reduction in bookkeeping (commit: 068ab8ccc7) meant that
  the worldComm didn't have a group from which sub-communicators could
  be spun off.

- do not force reset of PstreamBuffers positions

STYLE: UPstream::globalComm instead of '0'
2023-02-10 19:43:43 +01:00
Mark Olesen
068ab8ccc7 ENH: add separate tracking of MPI_Comm_free, MPI_Group_free pending
- permits distinction between communicators/groups that were
  user-created (eg, MPI_Comm_create) versus those queried from MPI.
  Previously simply relied on non-null values, but that is too fragile

ENH: support List<Request> version of UPstream::finishedRequests

- allows more independent algorithms

ENH: added UPstream::probeMessage(...). Blocking or non-blocking
2023-02-07 22:39:00 +01:00
Mark Olesen
568ced68e2 ENH: support independent handling of MPI requests (#2674)
- UPstream::Request wrapping class provides an opaque wrapper for
  vendor MPI_Request values, independent of global lists.

ENH: support for MPI barrier (blocking or non-blocking)
ENH: support for MPI sync-send variants

STYLE: deprecate waitRequests() without a position parameter

- in many cases this can indicate a problem in the program logic since
  normally the startOfRequests should be tracked locally.
2023-01-12 21:19:12 +01:00
Mark Olesen
06f479fbd4 ENH: improve handling of wait/finished requests
- now simply a no-op for out-of-range values (instead of an error),
  which simplifies the calling code.

  Previously
  ==========

      if (request_ >= 0 && request_ < UPstream::nRequests())
      {
          UPstream::waitRequest(request_);
      }

  Updated
  =======

      UPstream::waitRequest(request_);

- when 'recycling' freed request indices, ensure they are actually
  within the currently addressable range

- MPI finalization now checks outstanding requests against
  MPI_REQUEST_NULL to verify that they have been waited or tested on.
  Previously simply checked against freed request indices

ENH: consistent initialisation of send/receive bookkeeping
2023-01-12 21:19:11 +01:00
Mark Olesen
05322608a2 ENH: Pstream waitRequest ignore placeholder (negative) requests 2022-12-13 10:45:44 +01:00
Mark Olesen
b69db76b67 ENH: bundle together freed/outstanding MPI request handling
- improve communicator wrapping
- avoid indexing errors when using partial subranks
- UPstream::is_subrank (for testing partial subranks)
2022-12-09 10:59:32 +01:00
Mark Olesen
ffeef76d8f ENH: cleaner separation of global and local world naming
- UPstream::globalComm constant always refers to MPI_COMM_WORLD but
  UPstream::worldComm could be MPI_COMM_WORLD (single world)
  or a dedicated local communicator (for multi-world).

- provide a Pstream wrapped version of MPI_COMM_SELF,
  references as UPstream::selfComm

- UPstream::isUserComm(label)
  test for additional user-defined communicators
2022-12-01 12:18:38 +00:00
Mark Olesen
47e172e6ef ENH: add internal parRun guards to some UPstream methods
- simplifies coding
  * finishedRequest(), waitRequest(), waitRequests() with parRun guards
  * nRequests() is noexcept

- more consistent use of UPstream::defaultCommsType in branching
2022-09-22 11:50:50 +02:00
Mark Olesen
18e0d7e4d6 ENH: bundle broadcasts (#2371)
- additional Pstream::broadcasts() method to serialize/deserialize
  multiple items.

- revoke the broadcast specialisations for std::string and List(s) and
  use a generic broadcasting template. In most cases, the previous
  specialisations would have required two broadcasts:
    (1) for the size
    (2) for the contiguous content.

  Now favour reduced communication over potential local (intermediate)
  storage that would have only benefited a few select cases.

ENH: refine PstreamBuffers access methods

- replace 'bool hasRecvData(label)' with 'label recvDataCount(label)'
  to recover the number of unconsumed receive bytes from specified
  processor.  Can use 'labelList recvDataCounts()' to recover the
  number of unconsumed receive bytes from all processor.

- additional peekRecvData() method (for transcribing contiguous data)

ENH: globalIndex whichProcID - check for isLocal first

- reasonable to assume that local items are searched for more
  frequently, so do preliminary check for isLocal before performing
  a more costly binary search of globalIndex offsets

ENH: masterUncollatedFileOperation - bundled scatter of status
2022-04-29 11:44:28 +02:00
Mark Olesen
87e3b196b0 ENH: extend wrapping of MPI calls to more data types
- supports gatherv of label and scalar types

- combine blocking and non-blocking interfaces in UPstreamWrapping
  (code reduction).

DEFEATURE: remove unused UPstream allToAllv wrapping

- backend interface preserved in UPstreamWrapping

COMP: add genericListBroadcast - simplifies code
2022-03-31 16:01:07 +02:00
Mark Olesen
0cf02eb384 ENH: globalIndex with direct gather/broadcast
- less communication than gatherList/scatterList

ENH: refine send granularity in Pstream::exchange

STYLE: ensure PstreamBuffers and defaultCommsType agree

- simpler loops for lduSchedule
2022-03-12 21:16:29 +01:00
Mark Olesen
b0ef650a12 ENH: Pstream specialization for float/scalar, FixedList (#2351)
- native MPI min/max/sum reductions for float/double
  irrespective of WM_PRECISION_OPTION

- native MPI min/max/sum reductions for (u)int32_t/(u)int64_t types,
  irrespective of WM_LABEL_SIZE

- replace rarely used vector2D sum reduction with FixedList as a
  indicator of its intent and also generalizes to different lengths.

  OLD:
      vector2D values;  values.x() = ...;  values.y() = ...;
      reduce(values, sumOp<vector2D>());

  NEW:
      FixedList<scalar,2> values;  values[0] = ...;  values[1] = ...;
      reduce(values, sumOp<scalar>());

- allow returnReduce() to use native reductions. Previous code (with
  linear/tree selector) would have bypassed them inadvertently.

ENH: added support for MPI broadcast (for a memory span)

ENH: select communication schedule as a static method

- UPstream::whichCommunication(comm) to select linear/tree
  communication instead of ternary or
  if (Pstream::nProcs() < Pstream::nProcsSimpleSum) ...

STYLE: align nProcsSimpleSum static value with etc/controlDict override
2022-03-04 17:49:23 +00:00
Mark Olesen
83243cf01e COMP: non-group-local communicator for MS-MPI (mingw)
- partial revert for 13740de427 (#2158)

  MS-MPI does not currently have a MPI_Comm_create_group(),
  so keep using MPI_Comm_create() there.

  Only affects multi-world simulations.

CONFIG: retain dummy version of libPstream.dll

- retain as libPstream.dll-dummy so that it is available for
  manual replacement of the regular libPstream.dll (#2290)

  Keep extra copy of libPstream.dll as libPstream.dll-msmpi
  (for example) for manual replacement.
2021-12-16 14:44:28 +01:00
Mattijs Janssens
227b3976ba BUG: collated: threaded writing accesses out-of-scope. Fixes #2257. 2021-11-02 14:26:30 +00:00
Mark Olesen
b6539cd02e ENH: additional MPI gather/scatter routines, globalIndex gather methods
- UPstream::mpiGather (MPI_Gather)   - used by Pstream::listGatherValues
- UPstream::mpiScatter (MPI_Scatter) - used by Pstream::listScatterValues

  These are much simpler forms for gather/scatter of fixed-sized
  contiguous types data types (eg, primitives, simple pairs etc).

  In the gather form, creates a list of gathered values on the master
  process. The subranks have a list size of zero.

  Similarly, scatter will distribute a list of values to single values
  on each process.

  Instead of

      labelList sendSizes(Pstream::nProcs());
      sendSizes[Pstream::myProcNo()] = sendData.size();
      Pstream::gatherList(sendSizes);

  Can write

      const labelList sendSizes
      (
          UPstream::listGatherValues<label>(sendData.size())
      );

  // Less code, lower overhead and list can be const.

  For scattering an individual value only,
  instead of

      labelList someValues;
      if (Pstream::master()) someValues = ...;

      Pstream::gatherList(sendSizes);
      const label localValue
      (
          someValues[Pstream::myProcNo()]
      );

  Can write

      labelList someValues;
      if (Pstream::master()) someValues = ...;

      Pstream::gatherList(sendSizes);
      const label localValue
      (
          UPstream::listScatterValues<label>(someValues)
      );

   Can of course also mix listGatherValues to assemble a list on master
   and use Pstream::scatterList to distribute.

ENH: adjusted globalIndex gather methods

- added mpiGather() method [contiguous data only] using MPI_Gatherv

- respect localSize if gathering master data to ensure that a
  request for 0 master elements is properly handled.
2021-10-29 17:04:52 +02:00
mattijs
13740de427 BUG: mpi: use group-local communicator allocation. Fixes #2158 2021-07-28 16:07:30 +02:00
Mark Olesen
cdbc3e2de6 ENH: List/DynamicList appendUniq() method
- affords some code reduction.

STYLE: use HashSet insert() without found() check in more places
2021-04-19 16:33:42 +00:00
Mark Olesen
fa645c2dac ENH: noexcept size_bytes() method for lists
- for use when the is_contiguous check has already been done outside
  the loop. Naming as per std::span.

STYLE: use data/cdata instead of begin

ENH: replace random_shuffle with shuffle, fix OSX int64 ambiguity
2021-03-09 09:49:31 +01:00
mattijs
89f2cda3ab ENH: mpi: use per-application communicator. 2020-12-09 15:17:44 +00:00
Mark Olesen
01f6505442 ENH: add a Pstream::shutdown() method (#1660)
- previously used a Pstream::exit() invoked from the argList
  destructor to handle all MPI shutdown, but this has the unfortunate
  side-effect of using a fixed return value for the program exit.

  Instead use the Pstream::shutdown() method in the destructor and allow
  the normal program exit codes as usual. This means that the
  following code now works as expected.

  ```
  argList args(...);

  if (...)
  {
      InfoErr<< "some error\n";
      return 1;
  }
  ```
2020-04-01 12:33:39 +02:00
Mark Olesen
de4c728e12 STYLE: use List::found() instead of deprecated findIndex function 2020-03-12 13:05:42 +01:00
Mattijs Janssens
ab4bfaeee3 ENH: lduMatrix: new matrix solvers: PPCG,PPCR
PPCG is pipelined version of PCG, PPCR is conjugate
residual version.
2020-03-11 13:53:03 +00:00
mattijs
1b47034e24 ENH: Pstream: use native reduce in SPDP mode. Fixes #1574. 2020-02-06 12:36:26 +00:00
Andrew Heather
fdf8d10ab4 Merge commit 'e9219558d7' into develop-v1906 2019-12-05 11:47:19 +00:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
97c2a62536 COMP: silence gcc 8.2 memcpy warnings
- we know they have already protected by an is_contiguous check,
  so the class-memaccess warning/error can be suppressed.
2019-10-28 16:57:47 +01:00
mattijs
46bc808261 ENH: add primitives support for mixed precision (#1086)
- add vsmall pTraits for scalars
- report the solve scalar in buildArch information
2019-02-03 16:54:25 +00:00
Mark Olesen
828f8e8504 ENH: add simple profiling of MPI communications 2019-04-25 15:33:51 +02:00
Mark Olesen
0fab8abc76 COMP: adjust compilation order. Can compile OSspecific before Pstream
STYLE: report MPI flavour (WM_MPLIB) when making mpi-related libraries
2019-04-11 18:22:33 +02:00
Mark Olesen
d5c01f1aa4 ENH: support external MPI initialize / finalize (#1266) 2019-04-01 18:44:23 +02:00
Mark Olesen
f3670521cd STYLE: use std:: qualifier on ::abort, ::exit
- consistent with use of <cstdlib> and makes for a stronger distinct
  from Foam::abort etc.
2019-04-03 20:24:30 +02:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00