Commit Graph

112 Commits

Author SHA1 Message Date
Mark Olesen
0ba4f36c60 ENH: use List containers for Pstream read/write calls
- using the List containers, and not their low-level data_bytes(),
  size_bytes() methods is more convenient and allows future
  adjustments to be centralized

ENH: trivial intptr_t wrapper for MPI_Win

STYLE: minor adjustments to mpirunDebug
2025-02-11 11:09:30 +01:00
Mark Olesen
cf2b305b4f ENH: upgrade to use some C++17 constructs
- 'if constexpr (...)'
   * instead of std::enable_if
   * terminate template recursion
   * compile-time elimination of code

- use C++14 '_t', '_v' versions,
  eg, std::is_integral_v<T> instead of std::is_integral<T>::value

- std::begin, std::end, std::void_t instead of prev stdFoam versions

- provide is_contiguous_v<..> as short form of is_contiguous<..>::value
  with the additional benefit of removing any cv qualifiers.

ENH: include is_rotational_vectorspace trait

- tests for vector-space and nComponents > 1 (ie, not sphericalTensor)

ENH: improve robustness of pTraits_.. tests by removing cv qualifiers
2025-01-31 09:51:44 +01:00
Mattijs Janssens
96db337a99 ENH: more unique tags to avoid overlapping comms 2024-11-27 12:33:28 +00:00
Mark Olesen
7b38b148fa STYLE: use PstreamBuffers default construct
- PstreamBuffers are nonBlocking by default, so no need to re-specify
2024-04-29 10:21:25 +02:00
mattijs
c6ecf3113a COMP: syncTools: move attribute 2024-03-20 09:32:43 +00:00
Mark Olesen
a431e0fe9a ENH: additional parRun selection/protection on syncTools
- allow more control over using parallel communication or not.
2024-03-18 20:59:21 +01:00
Mark Olesen
7006056eae ENH: remove blocking communication for gather patterns
ENH: eliminate unnecessary duplicate communicator

- in globalMeshData previously had a comm_dup hack to avoid clashes
  with deltaCoeffs calculations. However, this was largely due to a
  manual implementation of reduce() that used point-to-point
  communication. This has since been updated to use an MPI_Allreduce
  and now an MPI_Allgather, neither of which need this hack.
2024-03-06 11:10:54 +01:00
Mark Olesen
04d880e2ce STYLE: use send/recv serializers for globalIndex and mapDistribute etc 2024-02-24 19:51:24 +01:00
Mark Olesen
4f43f0302d ENH: additional Map/HashTable constructors and ListOp functions
- construct Map/HashTable from key/value lists.

- invertToMap() : like invert() but returns a Map<label>,
  which is useful for sparse numbering

- inplaceRenumber() : taking a Map<label> for the mapper

ENH: construct/reset CStringList for list of C-strings
2024-02-23 18:10:48 +01:00
Mark Olesen
d9727fad1c ENH: use updated HashTable methods 2023-10-11 18:11:37 +00:00
Mark Olesen
f398d7b313 ENH: consolidate PstreamBuffers reduced communication bookkeeping
- can reduce communication by only sending non-zero data (especially
  when using NBX for size exchanges), but proper synchronisation with
  multiply-connected processor/processor patches (eg, processorCyclic)
  may still require speculative sends.

  Can now setup for PstreamBuffers 'registered' sends to avoid
  ad hoc bookkeeping within the caller.
2023-07-05 14:03:54 +02:00
Mark Olesen
c5c7f2b7fe ENH: reduce local overheads in send/recv bookkeeping (#2814)
- replace Map with a List or DynamicList to reduce the number of
  operations and allocations within the loops.

  Use polyBoundaryMesh::nProcessorPatches() for initial capacity
  to avoid reallocations.
2023-06-22 12:16:45 +00:00
Mark Olesen
3dee3438d5 ENH: improve send/recv robustness in the presence of processorCyclic (#2814)
- the changes introduced in f215ad15d1 aim to reduce unnecessary
  point-to-point communication. However, if there are also
  processorCyclic boundaries involved, there are multiple connections
  between any two processors, so simply skipping empty sends will cause
  synchronization problems.

  Eg,

    On the send side:
        patch0to1_a is zero (doesn't send) and patch0to1_b does send
        (to the same processor).

    On the receive side:
        patch1to0_a receives the data intended for patch1to0_b !

  Remedy
  ======
     Simply stream all of send data into PstreamBuffers
     (regardless if empty or non-empty) but track the sends
     as a bit operation: empty (0) or non-empty (1)

     Reset the buffer slots that were only sent empty data.
     This adds an additional local overhead but avoids communication
     as much as possible.
2023-06-22 12:16:45 +00:00
Mark Olesen
1bef57d018 ENH: optional saving of illegal edges in patch surfaceType() check
- reduce some intermediate storage in looping

STYLE: explicit iterator dereference in syncTools
2023-05-09 19:30:58 +02:00
Mark Olesen
f215ad15d1 ENH: skip zero data sends via PstreamBuffers
- in several cases can use the PstreamBuffers recvDataCount(proci)
  on the receiving part of the logic
2023-02-14 23:32:58 +01:00
Mark Olesen
d597b3f959 STYLE: check iterator validity with good() instead of found()
- aligns better with other container checks
2023-02-10 17:12:48 +01:00
Mark Olesen
473e14418a ENH: more consistent use of broadcast, combineReduce etc.
- broadcast           : (replaces scatter)
  - combineReduce       == combineGather + broadcast
  - listCombineReduce   == listCombineGather + broadcast
  - mapCombineReduce    == mapCombineGather + broadcast
  - allGatherList       == gatherList + scatterList

  Before settling on a more consistent naming convention,
  some intermediate namings were used in OpenFOAM-v2206:

    - combineReduce       (2206: combineAllGather)
    - listCombineReduce   (2206: listCombineAllGather)
    - mapCombineReduce    (2206: mapCombineAllGather)
2022-11-08 16:48:08 +00:00
Mark Olesen
8e017fa63c STYLE: specify "U[IO]Pstream" instead of "[IO]Pstream" for (read|write)
- consistency. Replace some instances of 'slave' with proc
2022-07-08 11:13:00 +02:00
Mark Olesen
d38de84d21 ENH: bundle Pstream:: AllGather methods
- bundles frequently used 'gather/scatter' patterns more consistently.

  - combineAllGather     -> combineGather + broadcast
  - listCombineAllGather -> listCombineGather + broadcast
  - mapCombineAllGather  -> mapCombineGather + broadcast
  - allGatherList        -> gatherList + scatterList
  - reduce               -> gather + broadcast (ie, allreduce)

- The allGatherList currently wraps gatherList/scatterList, but may be
  replaced with a different algorithm in the future.

STYLE: PstreamCombineReduceOps.H is mostly unneeded now
2022-03-31 15:56:04 +02:00
Mark Olesen
327c43f3e8 ENH: identityOp as equivalent to std::identity (C++20)
- similar to how noOp was defined, but with perfect forwarding

STYLE: combine Swap into stdFoam

STYLE: capitalize FileOp, NegateOp template parameters
2022-03-13 22:35:18 +01:00
Mark Olesen
14631984df ENH: additional control and access methods for PstreamBuffers
- PstreamBuffers nProcs() and allProcs() methods to recover the rank
  information consistent with the communicator used for construction

- allowClearRecv() methods for more control over buffer reuse
  For example,

      pBufs.allowClearRecv(false);

      forAll(particles, particlei)
      {
          pBufs.clear();

          fill...

          read via IPstream(..., pBufs);
       }

  This preserves the receive buffers memory allocation between calls.

- finishedNeighbourSends() method as compact wrapper for
  finishedSends() when send/recv ranks are identically
  (eg, neighbours)

- hasSendData()/hasRecvData() methods for PstreamBuffers.

  Can be useful for some situations to skip reading entirely.
  For example,

      pBufs.finishedNeighbourSends(neighProcs);

      if (!returnReduce(pBufs.hasRecvData(), orOp<bool>()))
      {
          // Nothing to do
          continue;
      }
      ...

  On an individual basis:

      for (const int proci : pBufs.allProcs())
      {
          if (pBufs.hasRecvData(proci))
          {
             ...
          }
      }

  Also conceivable to do the following instead (nonBlocking only):

      if (!returnReduce(pBufs.hasSendData(), orOp<bool>()))
      {
          // Nothing to do
          pBufs.clear();
          continue;
      }

      pBufs.finishedNeighbourSends(neighProcs);
      ...
2022-03-04 17:49:23 +00:00
Mark Olesen
f3674eee36 ENH: simpler use of broadcast (via Pstream::scatter)
- avoids worrying about forgetting a (Pstream::parRun()) guard
  and reduces code. The Pstream::scatter does the same thing under the
  hood.
2022-03-04 17:49:23 +00:00
Mark Olesen
ff4998d364 ENH: avoid all-to-all communication in isoAdvection (#2371)
- the data front for isoAdvection can be particularly sparse and at
  higher processor counts there is an advantage to avoiding all-to-all
  communication for the PstreamBuffers exchange

Based on code changes from T.Aoyagi(RIST), A.Azami(RIST)
2022-03-04 17:49:23 +00:00
Mark Olesen
1348cd7e7b ENH: use broadcasting Pstreams for one-to-all sends 2022-03-04 17:49:23 +00:00
Mark Olesen
3781f17eee ENH: add '_bytes()' versions of List data(), cdata()
- simply adds in the reinterpret_cast, which simplifies coding for
  binary data movement.
  Name complements the size_bytes() method for contiguous data

STYLE: container IO.C files into main headers for better visibility

STYLE: include CompactListList.H in polyTopoChange

- avoids future mismatches if the CompactListList template signature
  changes

GIT: relocate CompactListList into CompactLists/ directory
2021-10-29 17:04:51 +02: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
Mark Olesen
6cdf89dced ENH: use concise forms for walking processor and cyclic boundaries 2021-02-09 17:57:49 +01:00
Mark Olesen
9b56c6b1ac ENH: consistent noexcept for list iterators and raw-data accessors
- add byteSize to FixedList and Matrix, for possible streaming

ENH: expose data/cdata for PackedList, bitSet
2021-01-26 09:42:27 +01:00
mattijs
0e7a2d1529 ENH: syncTools: specialisation for contiguous data. Fixes #1986. 2021-01-20 09:33:44 +00:00
mattijs
542dae4a6d ENH: syncTools: add edge orientation. Fixes #1974. 2021-01-06 09:54:37 +00:00
mattijs
b179cd355e STYLE: headers: unused includes. 2020-12-10 15:43:28 +00:00
Mark Olesen
5dc5ea928a ENH: add UPstream::subProcs() static method
- returns a range of `int` values that can be iterated across.
  For example,

      for (const int proci : Pstream::subProcs()) { ... }

  instead of

      for
      (
          int proci = Pstream::firstSlave();
          proci <= Pstream::lastSlave();
          ++proci
      )
      {
          ...
      }
2020-09-28 14:26:07 +02:00
Mark Olesen
4ecc6ccfca ENH: declare generated methods for vector-space, primitives
- make read construct from Istream explicit

BUG: sph(const SymmTensor2D<Cmpt>&)

- had incorrect constant, but the 2D routines still need more attention
 (#1575)
2020-01-30 12:38:28 +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
13169cf8e3 ENH: improve syncTools handling of bitSet/PackedList types
- additional support for face sync/swap of boundary values.
  This allows use of bitSet instead of boolList in more places
2019-08-09 10:07:28 +02:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00
Mark Olesen
ed94a2714d STYLE: use HashTable iterator 'val()' method instead of 'object()' 2019-01-18 16:26:50 +01:00
Mark Olesen
64c3e484bb STYLE: add nBoundaryFaces() method to primitiveMesh
- nBoundaryFaces() is often used and is identical to
  (nFaces() - nInternalFaces()).

- forward the mesh nInternalFaces() and nBoundaryFaces() to
  polyBoundaryMesh as nFaces() and start() respectively,
  for use when operating on a polyBoundaryMesh.

STYLE:

- use identity() function with starting offset when creating boundary maps.

     labelList map
     (
         identity(mesh.nBoundaryFaces(), mesh.nInternalFaces())
     );

  vs.

     labelList map(mesh.nBoundaryFaces());
     forAll(map, i)
     {
         map[i] = mesh.nInternalFaces() + i;
     }
2018-09-27 10:17:30 +02:00
Mark Olesen
ca5d91239d STYLE: use edgeHashes include
STYLE: use initial hash size 128 instead of 100 in a few places
2018-08-08 23:54:27 +02:00
Mark Olesen
a1345b7e83 ENH: improve syncTools handling of PackedList and bitSet
- create a subset copy for sending on the processor patches instead of
  a List of unsigned ints. Reduces memory overhead and data transfer
  amount.
2018-08-01 21:55:45 +02:00
Mark Olesen
51c32360cd ENH: use bitSet operations in syncTools
- concise and more efficient
2018-08-01 15:22:19 +02:00
Mark Olesen
49d9589d26 STYLE: update iterator access and looping in syncTools 2018-08-01 14:34:34 +02:00
Mark Olesen
640aac95bd STYLE: remove dead code from syncTools (unused since 2014 or earlier) 2018-08-01 13:38:37 +02:00
Mark Olesen
35facb8208 ENH: add PackedList::unpack() method
- allows for simpler unpacking of a full list, or list range into any
  sufficiently large integral type.

  For example,
    processorPolyPatch pp = ...;

    UOPstream toNbr(pp.neighbProcNo(), pBufs);
    toNbr << faceValues.unpack<char>(pp.range());
2018-08-01 12:48:35 +02:00
Mark Olesen
dc521b95df STYLE: consistent use of '= delete' 2018-05-30 12:03:17 +02:00
Mark Olesen
bac943e6fc ENH: new bitSet class and improved PackedList class (closes #751)
- The bitSet class replaces the old PackedBoolList class.
  The redesign provides better block-wise access and reduced method
  calls. This helps both in cases where the bitSet may be relatively
  sparse, and in cases where advantage of contiguous operations can be
  made. This makes it easier to work with a bitSet as top-level object.

  In addition to the previously available count() method to determine
  if a bitSet is being used, now have simpler queries:

    - all()  - true if all bits in the addressable range are empty
    - any()  - true if any bits are set at all.
    - none() - true if no bits are set.

  These are faster than count() and allow early termination.

  The new test() method tests the value of a single bit position and
  returns a bool without any ambiguity caused by the return type
  (like the get() method), nor the const/non-const access (like
  operator[] has). The name corresponds to what std::bitset uses.

  The new find_first(), find_last(), find_next() methods provide a faster
  means of searching for bits that are set.

  This can be especially useful when using a bitSet to control an
  conditional:

  OLD (with macro):

      forAll(selected, celli)
      {
          if (selected[celli])
          {
              sumVol += mesh_.cellVolumes()[celli];
          }
      }

  NEW (with const_iterator):

      for (const label celli : selected)
      {
          sumVol += mesh_.cellVolumes()[celli];
      }

      or manually

      for
      (
          label celli = selected.find_first();
          celli != -1;
          celli = selected.find_next()
      )
      {
          sumVol += mesh_.cellVolumes()[celli];
      }

- When marking up contiguous parts of a bitset, an interval can be
  represented more efficiently as a labelRange of start/size.
  For example,

  OLD:

      if (isA<processorPolyPatch>(pp))
      {
          forAll(pp, i)
          {
              ignoreFaces.set(i);
          }
      }

  NEW:

      if (isA<processorPolyPatch>(pp))
      {
          ignoreFaces.set(pp.range());
      }
2018-03-07 11:21:48 +01:00
Mark Olesen
5d1fb23555 ENH: code reduction in PackedList, PackedBoolList (issue #751)
- eliminate iterators from PackedList since they were unused, had
  lower performance than direct access and added unneeded complexity.

- eliminate auto-vivify for the PackedList '[] operator.
  The set() method provides any required auto-vivification and
  removing this ability from the '[]' operator allows for a lower
  when accessing the values. Replaced the previous cascade of iterators
  with simpler reference class.

PackedBoolList:

- (temporarily) eliminate logic and addition operators since
  these contained partially unclear semantics.

- the new test() method tests the value of a single bit position and
  returns a bool without any ambiguity caused by the return type
  (like the get() method), nor the const/non-const access (like
  operator[] has). The name corresponds to what std::bitset uses.

- more consistent use of PackedBoolList test(), set(), unset() methods
  for fewer operation and clearer code. Eg,

      if (list.test(index)) ...    |  if (list[index]) ...
      if (!list.test(index)) ...   |  if (list[index] == 0u) ...
      list.set(index);             |  list[index] = 1u;
      list.unset(index);           |  list[index] = 0u;

- deleted the operator=(const labelUList&) and replaced with a setMany()
  method for more clarity about the intended operation and to avoid any
  potential inadvertent behaviour.
2018-03-13 08:32:40 +01:00
Andrew Heather
45381b1085 MRG: Integrated Foundation code to commit 19e602b 2017-03-28 11:30:10 +01:00
Henry Weller
96ad725a0b Updated UPstream::commsTypes to use the C++11 enum class 2017-03-10 19:54:55 +00:00