mapDistributeBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::mapDistributeBase
29 
30 Description
31  Class containing processor-to-processor mapping information.
32 
33  We store mapping from the bits-to-send to the complete starting list
34  (subXXXMap) and from the received bits to their location in the new
35  list (constructXXXMap).
36 
37 Note:
38  Schedule is a list of processor pairs (one send, one receive. One of
39  them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
40  See distribute on how to use it.
41  Note2: number of items sent on one processor have to equal the number
42  of items received on the other processor.
43 
44  To aid constructing these maps there are the constructors from global
45  numbering, either with or without transforms.
46 
47  Constructors using compact numbering: layout is
48  - all my own elements first (whether used or not)
49  - followed by used-only remote elements sorted by remote processor.
50  So e.g 4 procs and on proc 1 the compact
51  table will first have all globalIndex.localSize() elements from proc1
52  followed by used-only elements of proc0, proc2, proc3.
53  The constructed mapDistributeBase sends the local elements from and
54  receives the remote elements into their compact position.
55  compactMap[proci] is the position of elements from proci in the compact
56  map. compactMap[myProcNo()] is empty since trivial addressing.
57 
58  It rewrites the input global indices into indices into the constructed
59  data.
60 
61  When constructing from components optionally a 'flip' on
62  the maps can be specified. This will interpret the map
63  values as index+flip, similar to e.g. faceProcAddressing. The flip
64  will only be applied to fieldTypes (scalar, vector, .. triad)
65 
66 
67 SourceFiles
68  mapDistributeBase.C
69  mapDistributeBaseIO.C
70  mapDistributeBaseTemplates.C
71 
72 \*---------------------------------------------------------------------------*/
73 
74 #ifndef Foam_mapDistributeBase_H
75 #define Foam_mapDistributeBase_H
76 
77 #include "boolList.H"
78 #include "labelList.H"
79 #include "labelPair.H"
80 #include "Pstream.H"
81 #include "Map.H"
82 #include "InfoProxy.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 
89 // Forward Declarations
90 class bitSet;
91 class dictionary;
92 class globalIndex;
93 class PstreamBuffers;
94 class mapPolyMesh;
95 class mapDistributeBase;
96 
97 Istream& operator>>(Istream&, mapDistributeBase&);
98 Ostream& operator<<(Ostream&, const mapDistributeBase&);
99 
100 template<>
101 Ostream& operator<<(Ostream&, const InfoProxy<mapDistributeBase>&);
102 
104 /*---------------------------------------------------------------------------*\
105  Class mapDistributeBase Declaration
106 \*---------------------------------------------------------------------------*/
107 
108 class mapDistributeBase
109 {
110  // Private Data
111 
112  //- Size of reconstructed data
113  label constructSize_;
114 
115  //- Maps from subsetted data back to original data
116  labelListList subMap_;
117 
118  //- Maps from subsetted data to new reconstructed data
119  labelListList constructMap_;
120 
121  //- Whether subMap includes flip or not
122  bool subHasFlip_;
123 
124  //- Whether constructMap includes flip or not
125  bool constructHasFlip_;
126 
127  //- Communicator to use for parallel operations
128  label comm_;
129 
130  //- Schedule
131  mutable autoPtr<List<labelPair>> schedulePtr_;
132 
133 
134 protected:
135 
136  // Protected Member Functions
137 
138  //- Fatal if expected and received size are not equal
139  static void checkReceivedSize
140  (
141  const label proci,
142  const label expectedSize,
143  const label receivedSize
144  );
145 
146  //- Scan the maps for the max addressed index.
147  //
148  // \param maps The maps to scan
149  // \param hasFlip True if maps has flip addressing
150  // \return max-size needed for addressing (eg, constructSize)
151  static label getMappedSize
152  (
153  const labelListList& maps,
154  const bool hasFlip
155  );
156 
157  //- Construct per processor compact addressing of the global elements
158  // needed. The ones from the local processor are not included since
159  // these are always all needed.
161  (
162  const globalIndex& globalNumbering,
163  const labelUList& elements,
164  List<Map<label>>& compactMap
165  ) const;
166 
168  (
169  const globalIndex& globalNumbering,
170  const labelListList& elements,
171  List<Map<label>>& compactMap
172  ) const;
173 
174  void exchangeAddressing
175  (
176  const int tag,
177  const globalIndex& globalNumbering,
178  labelList& elements,
179  List<Map<label>>& compactMap,
180  labelList& compactStart
181  );
182  void exchangeAddressing
183  (
184  const int tag,
185  const globalIndex& globalNumbering,
186  labelListList& elements,
187  List<Map<label>>& compactMap,
188  labelList& compactStart
189  );
190 
191  //- Synchronize send/recv mask buffers as a 'copy' operation.
192  // Somewhat similar to Pstream::exchangeContainer
193  //
194  // The masks must be properly sized by the caller, which avoids
195  // a needless all-to-all for the sizes and the sizing is already
196  // given by the maps.
197  static void exchangeMasks
198  (
199  const UList<bitSet>& sendMasks,
200  UList<bitSet>& recvMasks,
201  const int tag,
202  const label comm
203  );
204 
205  //- Bi-direction sync of send/recv buffers using bitwise '&='
206  //- combine operation.
207  //
208  // The masks must be properly sized by the caller, which avoids
209  // a needless all-to-all for the sizes and the sizing is already
210  // given by the maps.
211  static void unionCombineMasks
212  (
213  UList<bitSet>& sendMasks,
214  UList<bitSet>& recvMasks,
215  const int tag,
216  const label comm
217  );
218 
219 
220  template<class T, class CombineOp, class NegateOp>
221  static void flipAndCombine
222  (
223  const labelUList& map,
224  const bool hasFlip,
225  const UList<T>& rhs,
226  const CombineOp& cop,
227  const NegateOp& negOp,
228  List<T>& lhs
229  );
230 
231  //- Lookup a field value at specified index and return its value
232  //- after any flip negation operations
233  template<class T, class NegateOp>
234  static T accessAndFlip
235  (
236  const UList<T>& values,
237  const label index,
238  const bool hasFlip,
239  const NegateOp& negOp
240  );
241 
242  //- Lookup field values at specified indices and return
243  //- after any flip negation operations
244  template<class T, class NegateOp>
245  static List<T> accessAndFlip
246  (
247  const UList<T>& values,
248  const labelUList& indices,
249  const bool hasFlip,
250  const NegateOp& negOp
251  );
252 
253 
254 private:
255 
256  // Private Member Functions
257 
258  //- Helper for compactData (private: filescope only!)
259  // Establishes the exact send/recv elements used after masking.
260  //
261  // \param allowedLocalElems Permissible local mapped elements
262  // (true/false). Can be longer/shorter than actual number
263  // of mapped elements.
264  // \param allowedRemoteElems Permissible remote mapped elements
265  // (true/false). Can be longer/shorter than actual number
266  // of mapped elements.
267  // \param[out] sendMasks Mask of local elements sent to procs.
268  // \param[out] recvMasks Mask of remote elements received
269  // from procs
270  // \param tag The message tag
271  void calcCompactDataRequirements
272  (
273  const bitSet& allowedLocalElems,
274  const bitSet& allowedRemoteElems,
275  List<bitSet>& sendMasks, // [out]
276  List<bitSet>& recvMasks, // [out]
277  const int tag
278  );
279 
280  //- Helper for compactLocalData (private: filescope only!)
281  // Establishes the exact send/recv elements used after masking.
282  //
283  // \param allowedLocalElems Permissible local mapped elements
284  // (true/false). Can be longer/shorter than actual number
285  // of mapped elements.
286  // \param[out] sendMasks Mask of local elements sent to procs.
287  // \param[out] recvMasks Mask of remote elements received by proc.
288  // from procs
289  // \param tag The message tag
290  void calcCompactLocalDataRequirements
291  (
292  const bitSet& allowedLocalElems,
293  List<bitSet>& sendMasks, // [out]
294  List<bitSet>& recvMasks, // [out]
295  const int tag
296  );
297 
298  //- Helper for compactRemoteData (private: filescope only!)
299  // Establishes the exact send/recv elements used after masking.
300  //
301  // \param allowedRemoteElems Permissible remote mapped elements
302  // (true/false). Can be longer/shorter than actual number
303  // of mapped elements.
304  // \param[out] sendMasks Mask of local elements sent to procs.
305  // \param[out] recvMasks Mask of remote elements received by proc.
306  // \param tag The message tag
307  void calcCompactRemoteDataRequirements
308  (
309  const bitSet& allowedRemoteElems,
310  List<bitSet>& sendMasks, // [out]
311  List<bitSet>& recvMasks, // [out]
312  const int tag
313  );
314 
315  //- Implementation for compact{Local,Remote}Data (private).
316  // Also renumbers the subMap/constructMap if oldToNew maps
317  // are notNull().
318  //
319  // No communication
320  void compactData
321  (
322  const UList<bitSet>& sendMasks,
323  const UList<bitSet>& recvMasks,
324  labelList& oldToNewSub,
325  labelList& oldToNewConstruct,
326  const label localSize = -1
327  );
328 
329  //- Wrapper for compactData (private) that supplies oldToNew
330  //- maps for renumbering if doRenumber is true.
331  // No communication
332  void compactDataImpl
333  (
334  const UList<bitSet>& sendMasks,
335  const UList<bitSet>& recvMasks,
336  const bool doRenumber
337  );
338 
339 
340  //- Helper for renumbering compacted map elements and updating the
341  //- supplied old-to-new mapping to account for the visit order of
342  //- the original elements
343  //
344  // \param origElements The original elements visited (eg, meshPoints)
345  // \param[in,out] oldToNew The old-to-new mapping
346  // \param[in,out] mapElements The map to be renumbered
347  // \param hasFlip True if map has flip addressing
348  static void renumberVisitOrder
349  (
350  const labelUList& origElements,
351  labelList& oldToNew,
352  labelListList& maps,
353  const bool hasFlip
354  );
355 
356 
357 public:
358 
359  // Declare name of the class and its debug switch
360  ClassName("mapDistributeBase");
361 
362 
363  // Constructors
364 
365  //- Default construct (uses worldComm)
367 
368  //- Default construct with specified communicator
369  explicit mapDistributeBase(const label comm);
370 
371  //- Copy construct
373 
374  //- Move construct
376 
377  //- Read construct from dictionary
378  explicit mapDistributeBase
379  (
380  const dictionary& dict,
381  const label comm = UPstream::worldComm
382  );
383 
384  //- Move construct from components
386  (
387  const label constructSize,
390  const bool subHasFlip = false,
391  const bool constructHasFlip = false,
392  const label comm = UPstream::worldComm
393  );
394 
395  //- Construct from reverse addressing: per data item the send
396  //- processor and the receive processor.
397  //
398  // \note data is not sorted per processor - cannot use printLayout!
400  (
401  const labelUList& sendProcs,
402  const labelUList& recvProcs,
403  const label comm = UPstream::worldComm
404  );
405 
406  //- Construct from list of (possibly) remote elements in globalIndex
407  //- numbering (or -1).
408  //
409  // Determines compact numbering (see above) and distribute map
410  // to get data into this ordering and renumbers the elements to
411  // be in compact numbering.
413  (
414  const globalIndex&,
415  labelList& elements,
416  List<Map<label>>& compactMap,
417  const int tag = UPstream::msgType(),
418  const label comm = UPstream::worldComm
419  );
420 
421  //- Special variant that works with the info sorted into bins
422  //- according to local indices.
423  //
424  // E.g. think cellCells where
425  // cellCells[localCellI] is a list of global cells
427  (
428  const globalIndex&,
429  labelListList& cellCells,
430  List<Map<label>>& compactMap,
431  const int tag = UPstream::msgType(),
432  const label comm = UPstream::worldComm
433  );
434 
435  //- Construct from my elements to send.
436  // Assumes layout is my elements first followed by elements
437  // from all other processors in consecutive order.
438  explicit mapDistributeBase
439  (
441  const bool subHasFlip = false,
442  const bool constructHasFlip = false,
443  const label comm = UPstream::worldComm
444  );
445 
446  //- Construct from Istream
447  explicit mapDistributeBase(Istream& is);
448 
449 
450  // Static Functions
451 
452  //- Test for flip addressing, where flips are encoded as negative
453  //- indices and non-flips are encoded as positive non-zero indices.
454  //
455  // Exits early on the first detected zero or negative, which
456  // makes this more efficient than testing min(map) < 0.
457  //
458  // \note may return a false negative (ie, no flips detected)
459  // even when flip addressing is used, but the local map does not
460  // contain any flipped elements
461  static bool hasFlipAddressing(const labelUList& map);
462 
463  //- Test for flip addressing, where flips are encoded as negative
464  //- indices and non-flips are encoded as positive non-zero indices.
465  //
466  // See notes above.
467  static bool hasFlipAddressing(const labelListList& maps);
468 
469  //- Count the number of unmapped elements.
470  //
471  // \param elements The elements that are expected to be mapped
472  // \param maps The maps to scan
473  // \param hasFlip True if maps has flip addressing
474  // \return number of unmapped elements
475  static label countUnmapped
476  (
477  const labelUList& elements,
478  const labelListList& maps,
479  const bool hasFlip
480  );
481 
482 
483  // Member Functions
484 
485  // Access
486 
487  //- Constructed data size
488  label constructSize() const noexcept
489  {
490  return constructSize_;
491  }
492 
493  //- Constructed data size
494  label& constructSize() noexcept
495  {
496  return constructSize_;
497  }
498 
499  //- From subsetted data back to original data
500  const labelListList& subMap() const noexcept
501  {
502  return subMap_;
503  }
504 
505  //- From subsetted data back to original data
507  {
508  return subMap_;
509  }
510 
511  //- From subsetted data to new reconstructed data
512  const labelListList& constructMap() const noexcept
513  {
514  return constructMap_;
515  }
516 
517  //- From subsetted data to new reconstructed data
519  {
520  return constructMap_;
521  }
522 
523  //- Does subMap include a sign
524  bool subHasFlip() const noexcept
525  {
526  return subHasFlip_;
527  }
528 
529  //- Does subMap include a sign
530  bool& subHasFlip() noexcept
531  {
532  return subHasFlip_;
533  }
534 
535  //- Does constructMap include a sign
536  bool constructHasFlip() const noexcept
537  {
538  return constructHasFlip_;
539  }
540 
541  //- Does constructMap include a sign
542  bool& constructHasFlip() noexcept
543  {
544  return constructHasFlip_;
545  }
546 
547  //- The communicator used
548  label comm() const noexcept
549  {
550  return comm_;
551  }
552 
553  //- The number of sub-lists within the maps
554  label nMaps() const noexcept
555  {
556  return constructMap_.size();
557  }
558 
559  //- The sizes of the subMap lists
560  labelList subMapSizes() const;
561 
562  //- The sizes of the constructMap lists
564 
565 
566  // Schedule
567 
568  //- Calculate a communication schedule. See above.
570  (
571  const labelListList& subMap,
573  const int tag, // Message tag: msgType()
574  const label comm = UPstream::worldComm
575  );
576 
577  //- Return a schedule. Demand driven. See above.
578  const List<labelPair>& schedule() const;
579 
580  //- Return real or dummy schedule depending on the
581  //- communication type
583  (
584  const UPstream::commsTypes commsType
585  ) const;
587 
588  // Other
589 
590  //- Reset to zero size, only retaining communicator
591  void clear();
592 
593  //- Transfer the contents of the argument and annul the argument.
595 
596  //- Helper for construct from globalIndex. Renumbers element
597  // (in globalIndex numbering) into compact indices.
598  static label renumber
599  (
600  const globalIndex&,
601  const List<Map<label>>& compactMap,
602  const label globalElement
603  );
604 
605  //- Helper for renumbering the (compacted) map elements
606  //- using the supplied old-to-new mapping.
607  // Only compacts the maps, does not change the local layout.
608  //
609  // \param[in,out] mapElements The map to be renumbered
610  // \param oldToNew The old-to-new mapping
611  // \param hasFlip True if map has flip addressing
612  //
613  // \return max-size needed for new addressing (eg, constructSize)
614  static label renumberMap
615  (
616  labelListList& mapElements,
617  const labelUList& oldToNew,
618  const bool hasFlip
619  );
620 
621 
622  // Compaction
623 
624  //- Compact send/receive maps based on selection of
625  //- originating local (send) elements.
626  // Determines and removes the correspondingly unneeded elements
627  // in the send/receive maps.
628  // Only compacts the maps, does not change the local layout.
629  //
630  // \param allowedLocalElems Permissible local mapped elements
631  // (true/false). Can be longer/shorter than actual number
632  // of mapped elements.
633  // \param tag The message tag
634  // \param doRenumber Apply oldToNew internally to renumber
635  // entries (uses renumberMap) and adjust the constructSize
636  //
637  // \note generally preferable to compact based on remote data
638  // (ie, the actual receiver)
639  void compactLocalData
640  (
641  const bitSet& allowedLocalElems,
642  const int tag = UPstream::msgType(),
643  const bool doRenumber = false
644  );
645 
646  //- Compact send/receive maps based on selection of
647  //- remote (receive) elements.
648  // Determines and removes the correspondingly unneeded elements
649  // in the send/receive maps.
650  // Only compacts the maps, does not change the local layout.
651  //
652  // \param allowedRemoteElems Permissible remote mapped elements
653  // (true/false). Can be longer/shorter than actual number
654  // of mapped elements.
655  // \param tag The message tag
656  // \param doRenumber Apply oldToNew internally to renumber
657  // entries (uses renumberMap) and adjust the constructSize
659  (
660  const bitSet& allowedRemoteElems,
661  const int tag = UPstream::msgType(),
662  const bool doRenumber = false
663  );
664 
665 
666  //- Compact send/receive maps based on selection of
667  //- originating local (send) elements.
668  //- Returns compaction mappings for subMap and constructMap.
669  //
670  // \param allowedLocalElems Permissible local mapped elements
671  // (true/false). Can be longer/shorter than actual number
672  // of mapped elements.
673  // \param[out] oldToNewSub Old-to-new mapping: subMap
674  // Disabled if labelList::null(),
675  // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
676  // Disabled if labelList::null(),
677  // \param localSize The max index for subMap (-1: auto-detect)
678  // \param tag The message tag
679  //
680  // \note Applies oldToNew to renumber entries
681  // (uses renumberMap) and adjust constructSize
682  //
683  // \note generally preferable to compact based on remote data
684  // (ie, the actual receiver)
685  void compactLocalData
686  (
687  const bitSet& allowedLocalElems,
688  labelList& oldToNewSub,
689  labelList& oldToNewConstruct,
690  const label localSize = -1,
691  const int tag = UPstream::msgType()
692  );
693 
694  //- Compact send/receive maps based on selection of
695  //- remote (receive) elements.
696  //- Returns compaction mappings for subMap and constructMap.
697  //
698  // \param allowedRemoteElems Permissible remote mapped elements
699  // (true/false). Can be longer/shorter than actual number
700  // of mapped elements.
701  // \param[out] oldToNewSub Old-to-new mapping: subMap
702  // Disabled if labelList::null(),
703  // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
704  // Disabled if labelList::null(),
705  // \param localSize The max index for subMap (-1: auto-detect)
706  // \param tag The message tag
707  //
708  // \note Applies oldToNew to renumber entries
709  // (uses renumberMap) and adjust constructSize
710  void compactRemoteData
711  (
712  const bitSet& allowedRemoteElems,
713  labelList& oldToNewSub,
714  labelList& oldToNewConstruct,
715  const label localSize = -1,
716  const int tag = UPstream::msgType()
717  );
718 
719 
720  //- Compact send/receive maps based on selection of
721  //- originating local (send) and remote (receive) elements.
722  //
723  // The resulting compact numbering:
724  // - \c subMap (and \c oldToNewSub) :
725  // will follow the original ordering of \c localElements.
726  // - \c constructMap (and \c oldToNewConstruct) :
727  // will follow the original ordering of \c remoteElements.
728  // .
729  // \warning ill-defined behaviour if \c localElements
730  // or \c remoteElements contains duplicates.
731  void compactData
732  (
733  const labelUList& localElements,
734  const labelUList& remoteElements,
735  labelList& oldToNewSub,
736  labelList& oldToNewConstruct,
737  const label localSize = -1,
738  const int tag = UPstream::msgType()
739  );
740 
741  //- Compact send/receive maps based on selection of
742  //- originating local (send) elements.
743  //
744  // The resulting compact numbering:
745  // - \c subMap (and \c oldToNewSub) :
746  // will follow the original ordering of \c localElements.
747  // - \c constructMap (and \c oldToNewConstruct) :
748  // numbered in simple ascending order.
749  // .
750  // \warning ill-defined behaviour if \c localElements
751  // contains duplicates.
752  //
753  // \note generally preferable to compact based on remote data
754  // (ie, the actual receiver)
755  void compactLocalData
756  (
757  const labelUList& localElements,
758  labelList& oldToNewSub,
759  labelList& oldToNewConstruct,
760  const label localSize = -1,
761  const int tag = UPstream::msgType()
762  );
763 
764  //- Compact send/receive maps based on selection of
765  //- remote (receive) elements.
766  //
767  // The resulting compact numbering:
768  // - \c subMap (and \c oldToNewSub) :
769  // numbered in simple ascending order.
770  // - \c constructMap (and \c oldToNewConstruct) :
771  // will follow the original ordering of \c remoteElements.
772  // .
773  // \warning ill-defined behaviour if \c remoteElements
774  // contains duplicates.
775  void compactRemoteData
776  (
777  const labelUList& remoteElements,
778  labelList& oldToNewSub,
779  labelList& oldToNewConstruct,
780  const label localSize = -1,
781  const int tag = UPstream::msgType()
782  );
783 
784 
785  // Distribute
786 
787  //- Distribute data with specified negate operator (for flips).
788  //
789  // \note schedule currently only used for
790  // Pstream::commsTypes::scheduled, all others just use
791  // send-to-all, receive-from-all.
792  template<class T, class NegateOp>
793  static void distribute
794  (
795  const Pstream::commsTypes commsType,
796  const List<labelPair>& schedule,
797  const label constructSize,
798  const labelListList& subMap,
799  const bool subHasFlip,
801  const bool constructHasFlip,
802  List<T>& field,
803  const NegateOp& negOp,
804  const int tag = UPstream::msgType(),
805  const label comm = UPstream::worldComm
806  );
807 
808  //- Distribute data with specified combine operation
809  //
810  // If multiple processors writing to same
811  // position adds contributions using cop.
812  template<class T, class CombineOp, class NegateOp>
813  static void distribute
814  (
815  const Pstream::commsTypes commsType,
816  const List<labelPair>& schedule,
817  const label constructSize,
818  const labelListList& subMap,
819  const bool subHasFlip,
821  const bool constructHasFlip,
822  List<T>& field,
823  const T& nullValue,
824  const CombineOp& cop,
825  const NegateOp& negOp,
826  const int tag = UPstream::msgType(),
827  const label comm = UPstream::worldComm
828  );
829 
830 
831  //- Distribute data using default commsType
832  //- and the default flip/negate operator.
833  template<class T>
834  void distribute
835  (
836  List<T>& values,
837  const int tag = UPstream::msgType()
838  ) const;
839 
840  //- Distribute data using default commsType
841  //- and the default flip/negate operator.
842  template<class T>
843  void distribute
844  (
846  const int tag = UPstream::msgType()
847  ) const;
848 
849  //- Distribute data using default commsType
850  //- and the specified negate operator (for flips).
851  template<class T, class NegateOp>
852  void distribute
853  (
854  List<T>& values,
855  const NegateOp& negOp,
856  const int tag = UPstream::msgType()
857  ) const;
858 
859  //- Distribute data using specified commsType
860  //- and the specified negate operator (for flips).
861  // Accepts a nullValue to initialize unmapped elements
862  // (ie, when the constructSize is larger than the number of
863  // mapped elements).
864  template<class T, class NegateOp>
865  void distribute
866  (
867  const Pstream::commsTypes commsType,
868  List<T>& values,
869  const NegateOp& negOp,
870  const int tag = UPstream::msgType()
871  ) const;
872 
873  //- Distribute data using specified commsType
874  //- and the specified negate operator (for flips).
875  // Accepts a nullValue to initialize unmapped elements
876  // (ie, when the constructSize is larger than the number of
877  // mapped elements).
878  template<class T, class NegateOp>
879  void distribute
880  (
881  const Pstream::commsTypes commsType,
882  const T& nullValue,
883  List<T>& values,
884  const NegateOp& negOp,
885  const int tag = UPstream::msgType()
886  ) const;
887 
888 
889  //- Reverse distribute data using default commsType
890  //- and the default flip/negate operator
891  template<class T>
892  void reverseDistribute
893  (
894  const label constructSize,
895  List<T>& values,
896  const int tag = UPstream::msgType()
897  ) const;
898 
899  //- Reverse distribute data using default commsType
900  //- and the default flip/negate operator.
901  // Accepts a nullValue to initialize unmapped elements
902  // (ie, when the constructSize is larger than the subMap).
903  template<class T>
904  void reverseDistribute
905  (
906  const label constructSize,
907  const T& nullValue,
908  List<T>& values,
909  const int tag = UPstream::msgType()
910  ) const;
911 
912  //- Reverse distribute data using specified commsType
913  //- and the default flip/negate operator
914  template<class T>
915  void reverseDistribute
916  (
917  const Pstream::commsTypes commsType,
918  const label constructSize,
919  List<T>& values,
920  const int tag = UPstream::msgType()
921  ) const;
922 
923  //- Reverse distribute data using specified commsType
924  //- and the specified flip/negate operator.
925  template<class T, class NegateOp>
926  void reverseDistribute
927  (
928  const Pstream::commsTypes commsType,
929  const label constructSize,
930  List<T>& values,
931  const NegateOp& negOp,
932  const int tag = UPstream::msgType()
933  ) const;
934 
935  //- Reverse distribute data using specified commsType
936  //- and the default flip/negate operator.
937  // Accepts a nullValue to initialize unmapped elements
938  // (ie, when the constructSize is larger than the subMap).
939  template<class T>
940  void reverseDistribute
941  (
942  const Pstream::commsTypes commsType,
943  const label constructSize,
944  const T& nullValue,
945  List<T>& values,
946  const int tag = UPstream::msgType()
947  ) const;
948 
949 
950  //- Do all sends using PstreamBuffers
951  template<class T>
952  void send(PstreamBuffers& pBufs, const List<T>& field) const;
953 
954  //- Do all receives using PstreamBuffers
955  template<class T>
956  void receive(PstreamBuffers& pBufs, List<T>& field) const;
957 
958 
959  // Low-level. Non-blocking. TBD: receive map is usually contiguous
960  // - receive into slices
961 
962  //- Start all sends and receives (always non-blocking)
963  template<class T, class negateOp>
964  static void send
965  (
966  const labelListList& subMap,
967  const bool subHasFlip,
969  const bool constructHasFlip,
970  const UList<T>& field,
971  labelRange& requests,
972  PtrList<List<T>>& sendFields,
973  PtrList<List<T>>& recvFields,
974  const negateOp& negOp,
975  const int tag,
976  const label comm
977  );
978 
979  //- Start all sends and receives (always non-blocking)
980  template<class T>
981  void send
982  (
983  const UList<T>& field,
984  labelRange& requests,
985  PtrList<List<T>>& sendFields,
986  PtrList<List<T>>& recvFields,
987  const int tag = UPstream::msgType()
988  ) const;
989 
990  //- Wait for requests to finish and consume
991  template<class T, class CombineOp, class negateOp>
992  static void receive
993  (
994  const label constructSize,
996  const bool constructHasFlip,
997  const UPtrList<List<T>>& sendFields,
998  const UPtrList<List<T>>& recvFields,
999  const labelRange& requests,
1000  List<T>& field,
1001  const CombineOp& cop,
1002  const negateOp& negOp,
1003  const int tag,
1004  const label comm
1005  );
1006 
1007  //- Wait for requests to finish and consume
1008  template<class T>
1009  void receive
1010  (
1011  const labelRange& requests,
1012  const UPtrList<List<T>>& sendFields,
1013  const UPtrList<List<T>>& recvFields,
1014  List<T>& field,
1015  const int tag = UPstream::msgType()
1016  ) const;
1017 
1018 
1019  // Other
1020 
1021  //- Debug: print layout. Can only be used on maps with sorted
1022  // storage (local data first, then non-local data)
1023  void printLayout(Ostream& os) const;
1024 
1025 
1026  // Member Operators
1027 
1028  //- Copy assignment
1029  void operator=(const mapDistributeBase& rhs);
1030 
1031  //- Move assignment
1032  void operator=(mapDistributeBase&& rhs);
1033 
1034 
1035  // IOstream Operators
1036 
1037  //- Return info proxy,
1038  //- used to print summary information to a stream
1040  {
1041  return *this;
1042  }
1043 
1044  //- Read entries from dictionary format
1045  void readDict(const dictionary& dict);
1046 
1047  //- Write entries in dictionary format
1048  void writeEntries(Ostream& os) const;
1049 
1050  //- Read plain content (not dictionary) from Istream
1052 
1053  //- Write plain content (not dictionary) to Ostream
1054  friend Ostream& operator<<(Ostream&, const mapDistributeBase&);
1055 
1056 
1057  // Housekeeping
1058 
1059  //- No correction for topo change
1060  void updateMesh(const mapPolyMesh&)
1061  {
1063  }
1064 
1065  //- OpenFOAM-v2112 and earlier naming for compactRemoteData()
1066  //- using boolList.
1067  void compact
1068  (
1069  const boolList& remoteElemUsed,
1070  const int tag = UPstream::msgType()
1071  );
1072 
1073  //- OpenFOAM-v2112 and earlier naming for compactRemoteData().
1074  //- using boolList.
1075  void compact
1076  (
1077  const boolList& remoteElemUsed,
1078  const label localSize,
1079  labelList& oldToNewSub,
1080  labelList& oldToNewConstruct,
1081  const int tag = UPstream::msgType()
1082  );
1083 };
1084 
1085 
1086 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1087 
1088 } // End namespace Foam
1089 
1090 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1091 
1092 #ifdef NoRepository
1093  #include "mapDistributeBaseTemplates.C"
1094 #endif
1095 
1096 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1097 
1098 #endif
1099 
1100 // ************************************************************************* //
void calcCompactAddressing(const globalIndex &globalNumbering, const labelUList &elements, List< Map< label >> &compactMap) const
Construct per processor compact addressing of the global elements.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
static label countUnmapped(const labelUList &elements, const labelListList &maps, const bool hasFlip)
Count the number of unmapped elements.
void compactLocalData(const bitSet &allowedLocalElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of originating local (send) elements.
rDeltaTY field()
static label renumber(const globalIndex &, const List< Map< label >> &compactMap, const label globalElement)
Helper for construct from globalIndex. Renumbers element.
commsTypes
Communications types.
Definition: UPstream.H:74
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
void send(PstreamBuffers &pBufs, const List< T > &field) const
Do all sends using PstreamBuffers.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:51
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend Ostream & operator<<(Ostream &, const mapDistributeBase &)
Write plain content (not dictionary) to Ostream.
label constructSize() const noexcept
Constructed data size.
label comm() const noexcept
The communicator used.
void compactRemoteData(const bitSet &allowedRemoteElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of remote (receive) elements.
label nMaps() const noexcept
The number of sub-lists within the maps.
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1184
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:411
InfoProxy< mapDistributeBase > info() const noexcept
Return info proxy, used to print summary information to a stream.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
mapDistributeBase()
Default construct (uses worldComm)
static void flipAndCombine(const labelUList &map, const bool hasFlip, const UList< T > &rhs, const CombineOp &cop, const NegateOp &negOp, List< T > &lhs)
friend Istream & operator>>(Istream &, mapDistributeBase &)
Read plain content (not dictionary) from Istream.
bool subHasFlip() const noexcept
Does subMap include a sign.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:62
static T accessAndFlip(const UList< T > &values, const label index, const bool hasFlip, const NegateOp &negOp)
Lookup a field value at specified index and return its value after any flip negation operations...
const List< labelPair > & whichSchedule(const UPstream::commsTypes commsType) const
Return real or dummy schedule depending on the communication type.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
static bool hasFlipAddressing(const labelUList &map)
Test for flip addressing, where flips are encoded as negative indices and non-flips are encoded as po...
void readDict(const dictionary &dict)
Read entries from dictionary format.
static void exchangeMasks(const UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Synchronize send/recv mask buffers as a &#39;copy&#39; operation.
void compact(const boolList &remoteElemUsed, const int tag=UPstream::msgType())
OpenFOAM-v2112 and earlier naming for compactRemoteData() using boolList.
Istream & operator>>(Istream &, directionInfo &)
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
void reverseDistribute(const label constructSize, List< T > &values, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType and the default flip/negate operator.
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:100
void updateMesh(const mapPolyMesh &)
No correction for topo change.
void operator=(const mapDistributeBase &rhs)
Copy assignment.
Class containing processor-to-processor mapping information.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
bool constructHasFlip() const noexcept
Does constructMap include a sign.
OBJstream os(runTime.globalPath()/outputName)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void receive(PstreamBuffers &pBufs, List< T > &field) const
Do all receives using PstreamBuffers.
static void unionCombineMasks(UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Bi-direction sync of send/recv buffers using bitwise &#39;&=&#39; combine operation.
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
void exchangeAddressing(const int tag, const globalIndex &globalNumbering, labelList &elements, List< Map< label >> &compactMap, labelList &compactStart)
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
labelList subMapSizes() const
The sizes of the subMap lists.
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &field, const NegateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute data with specified negate operator (for flips).
void clear()
Reset to zero size, only retaining communicator.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
ClassName("mapDistributeBase")
static void checkReceivedSize(const label proci, const label expectedSize, const label receivedSize)
Fatal if expected and received size are not equal.
static label getMappedSize(const labelListList &maps, const bool hasFlip)
Scan the maps for the max addressed index.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
List< label > labelList
A List of labels.
Definition: List.H:62
const labelListList & subMap() const noexcept
From subsetted data back to original data.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:666
List< bool > boolList
A List of bools.
Definition: List.H:60
labelList constructMapSizes() const
The sizes of the constructMap lists.
void writeEntries(Ostream &os) const
Write entries in dictionary format.
Namespace for OpenFOAM.
static label renumberMap(labelListList &mapElements, const labelUList &oldToNew, const bool hasFlip)
Helper for renumbering the (compacted) map elements using the supplied old-to-new mapping...