Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::mapDistributeBase
29
30Description
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
37Note:
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
67SourceFiles
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
86namespace Foam
87{
88
89// Forward Declarations
90class bitSet;
91class dictionary;
92class globalIndex;
93class PstreamBuffers;
94class mapPolyMesh;
96
99
100template<>
102
104/*---------------------------------------------------------------------------*\
105 Class mapDistributeBase Declaration
106\*---------------------------------------------------------------------------*/
107
109{
110public:
111
112 //- The map layout (eg, of the constructMap)
113 enum class layoutTypes : char
114 {
115 linear,
117 };
118
119
120private:
121
122 // Private Data
123
124 //- Size of reconstructed data
125 label constructSize_;
126
127 //- Maps from subsetted data back to original data
128 labelListList subMap_;
129
130 //- Maps from subsetted data to new reconstructed data
131 labelListList constructMap_;
132
133 //- Whether subMap includes flip or not
134 bool subHasFlip_;
135
136 //- Whether constructMap includes flip or not
137 bool constructHasFlip_;
138
139 //- Communicator to use for parallel operations
140 label comm_;
141
142 //- Schedule
143 mutable autoPtr<List<labelPair>> schedulePtr_;
144
145
146protected:
147
148 // Protected Member Functions
149
150 //- Fatal if expected != received size
151 static void checkReceivedSize
152 (
153 const label proci,
154 const label expectedSize,
155 const label receivedSize
156 );
157
158 //- Scan the maps for the max addressed index.
159 //
160 // \param maps The maps to scan
161 // \param hasFlip True if maps has flip addressing
162 // \return max-size needed for addressing (eg, constructSize)
163 static label getMappedSize
164 (
165 const labelListList& maps,
166 const bool hasFlip
167 );
168
169 //- Construct per processor compact addressing of the global elements
170 // needed. The ones from the local processor are not included since
171 // these are always all needed.
173 (
174 const globalIndex& globalNumbering,
175 const labelUList& elements,
176 List<Map<label>>& compactMap
177 ) const;
178
180 (
181 const globalIndex& globalNumbering,
182 const labelListList& elements,
183 List<Map<label>>& compactMap
184 ) const;
185
187 (
188 const int tag,
189 const globalIndex& globalNumbering,
190 labelList& elements,
191 List<Map<label>>& compactMap,
192 labelList& compactStart
193 );
195 (
196 const int tag,
197 const globalIndex& globalNumbering,
198 labelListList& elements,
199 List<Map<label>>& compactMap,
200 labelList& compactStart
201 );
202
203 //- Synchronize send/recv mask buffers as a 'copy' operation.
204 // Somewhat similar to Pstream::exchangeContainer
205 //
206 // The masks must be properly sized by the caller, which avoids
207 // a needless all-to-all for the sizes and the sizing is already
208 // given by the maps.
209 static void exchangeMasks
210 (
211 const UList<bitSet>& sendMasks,
212 UList<bitSet>& recvMasks,
213 const int tag,
214 const label comm
215 );
216
217 //- Bi-direction sync of send/recv buffers using bitwise '&='
218 //- combine operation.
219 //
220 // The masks must be properly sized by the caller, which avoids
221 // a needless all-to-all for the sizes and the sizing is already
222 // given by the maps.
223 static void unionCombineMasks
224 (
225 UList<bitSet>& sendMasks,
226 UList<bitSet>& recvMasks,
227 const int tag,
228 const label comm
229 );
230
231
232 //- Combine field values (after any flip negation operation)
233 //- into the specified mapped target locations
234 template<class T, class CombineOp, class NegateOp>
235 static void flipAndCombine
236 (
238 UList<T>& lhs,
240 const UList<T>& rhs,
242 const labelUList& map,
244 const bool hasFlip,
246 const CombineOp& cop,
248 const NegateOp& negOp
249 );
250
251 //- Lookup field values at specified map indices and save
252 //- after any flip negation operations
253 template<class T, class NegateOp>
254 static void accessAndFlip
255 (
257 UList<T>& output,
259 const UList<T>& values,
261 const labelUList& map,
263 const bool hasFlip,
265 const NegateOp& negOp
266 );
267
268 //- Lookup field values at specified indices and return
269 //- after any flip negation operations
270 template<class T, class NegateOp>
272 (
274 const UList<T>& values,
276 const labelUList& map,
278 const bool hasFlip,
280 const NegateOp& negOp
281 );
282
283
284private:
285
286 // Private Member Functions
287
288 //- Helper for compactData (private: filescope only!)
289 // Establishes the exact send/recv elements used after masking.
290 //
291 // \param allowedLocalElems Permissible local mapped elements
292 // (true/false). Can be longer/shorter than actual number
293 // of mapped elements.
294 // \param allowedRemoteElems Permissible remote mapped elements
295 // (true/false). Can be longer/shorter than actual number
296 // of mapped elements.
297 // \param[out] sendMasks Mask of local elements sent to procs.
298 // \param[out] recvMasks Mask of remote elements received
299 // from procs
300 // \param tag The message tag
301 void calcCompactDataRequirements
303 const bitSet& allowedLocalElems,
304 const bitSet& allowedRemoteElems,
305 List<bitSet>& sendMasks, // [out]
306 List<bitSet>& recvMasks, // [out]
307 const int tag
308 );
309
310 //- Helper for compactLocalData (private: filescope only!)
311 // Establishes the exact send/recv elements used after masking.
312 //
313 // \param allowedLocalElems Permissible local mapped elements
314 // (true/false). Can be longer/shorter than actual number
315 // of mapped elements.
316 // \param[out] sendMasks Mask of local elements sent to procs.
317 // \param[out] recvMasks Mask of remote elements received by proc.
318 // from procs
319 // \param tag The message tag
320 void calcCompactLocalDataRequirements
321 (
322 const bitSet& allowedLocalElems,
323 List<bitSet>& sendMasks, // [out]
324 List<bitSet>& recvMasks, // [out]
325 const int tag
326 );
327
328 //- Helper for compactRemoteData (private: filescope only!)
329 // Establishes the exact send/recv elements used after masking.
330 //
331 // \param allowedRemoteElems Permissible remote mapped elements
332 // (true/false). Can be longer/shorter than actual number
333 // of mapped elements.
334 // \param[out] sendMasks Mask of local elements sent to procs.
335 // \param[out] recvMasks Mask of remote elements received by proc.
336 // \param tag The message tag
337 void calcCompactRemoteDataRequirements
338 (
339 const bitSet& allowedRemoteElems,
340 List<bitSet>& sendMasks, // [out]
341 List<bitSet>& recvMasks, // [out]
342 const int tag
343 );
344
345 //- Implementation for compact{Local,Remote}Data (private).
346 // Also renumbers the subMap/constructMap if oldToNew maps
347 // are notNull().
348 //
349 // No communication
350 void compactData
351 (
352 const UList<bitSet>& sendMasks,
353 const UList<bitSet>& recvMasks,
354 labelList& oldToNewSub,
355 labelList& oldToNewConstruct,
356 const label localSize = -1
357 );
358
359 //- Wrapper for compactData (private) that supplies oldToNew
360 //- maps for renumbering if doRenumber is true.
361 // No communication
362 void compactDataImpl
363 (
364 const UList<bitSet>& sendMasks,
365 const UList<bitSet>& recvMasks,
366 const bool doRenumber
367 );
368
369
370 //- Helper for renumbering compacted map elements and updating the
371 //- supplied old-to-new mapping to account for the visit order of
372 //- the original elements
373 //
374 // \param origElements The original elements visited (eg, meshPoints)
375 // \param[in,out] oldToNew The old-to-new mapping
376 // \param[in,out] mapElements The map to be renumbered
377 // \param hasFlip True if map has flip addressing
378 static void renumberVisitOrder
379 (
380 const labelUList& origElements,
381 labelList& oldToNew,
382 labelListList& maps,
383 const bool hasFlip
384 );
385
386
387public:
388
389 // Declare name of the class and its debug switch
390 ClassName("mapDistributeBase");
391
392
393 // Constructors
394
395 //- Default construct (uses worldComm)
397
398 //- Default construct with specified communicator
399 explicit mapDistributeBase(const label comm) noexcept;
400
401 //- Copy construct
403
404 //- Move construct
406
407 //- Read construct from dictionary
408 explicit mapDistributeBase
409 (
410 const dictionary& dict,
411 const label comm = UPstream::worldComm
412 );
413
414 //- Move construct from components
416 (
417 const label constructSize,
420 const bool subHasFlip = false,
421 const bool constructHasFlip = false,
422 const label comm = UPstream::worldComm
423 );
424
425 //- Construct from reverse addressing: per data item the send
426 //- processor and the receive processor.
427 //
428 // \note data is not sorted per processor - cannot use printLayout!
430 (
431 const labelUList& sendProcs,
432 const labelUList& recvProcs,
433 const label comm = UPstream::worldComm
434 );
435
436 //- Construct from list of (possibly) remote elements in globalIndex
437 //- numbering (or -1).
438 //
439 // Determines compact numbering (see above) and distribute map
440 // to get data into this ordering and renumbers the elements to
441 // be in compact numbering.
443 (
444 const globalIndex&,
445 labelList& elements,
446 List<Map<label>>& compactMap,
447 const int tag = UPstream::msgType(),
448 const label comm = UPstream::worldComm
449 );
450
451 //- Special variant that works with the info sorted into bins
452 //- according to local indices.
453 //
454 // E.g. think cellCells where
455 // cellCells[localCellI] is a list of global cells
457 (
458 const globalIndex&,
459 labelListList& cellCells,
460 List<Map<label>>& compactMap,
461 const int tag = UPstream::msgType(),
462 const label comm = UPstream::worldComm
463 );
464
465 //- Construct from my elements to send, targetting the specified
466 //- constructMap layout
467 explicit mapDistributeBase
468 (
469 const layoutTypes constructLayout,
471 const bool subHasFlip = false,
472 const bool constructHasFlip = false,
473 const label comm = UPstream::worldComm
474 );
475
476 //- Construct from my elements to send.
477 // Assumes layout is my elements first followed by elements
478 // from all other processors in consecutive order.
479 explicit mapDistributeBase
480 (
482 const bool subHasFlip = false,
483 const bool constructHasFlip = false,
484 const label comm = UPstream::worldComm
485 );
486
487 //- Construct from multiple maps and processor collation
488 // Assumes all local data first. Sorts contributions of maps
489 // in processor order i.e. constructed map has all local data first.
490 // Returns
491 // - startOfLocal : per input map the start of the local data. Extends
492 // one beyond number of maps so overall local size
493 // is startOfLocal.last()
494 // - compactMaps : per input map from slot position in the input map
495 // to new slot position. (note there is no information
496 // returned about which processor it is from)
498 (
499 const UPtrList<const mapDistributeBase>& maps,
500 const labelList& localRanks,
501 const label newComm,
502 const labelListList& newToOldRanks, // from rank in newComm to
503 // ranks in (old)comm
504 labelList& startOfLocal, // per map start of local data
505 List<Map<label>>& compactMaps // per map old slot to new slot
506 );
507
508 //- Construct from Istream
509 explicit mapDistributeBase(Istream& is);
510
511
512 // Static Functions
513
514 //- Test for flip addressing, where flips are encoded as negative
515 //- indices and non-flips are encoded as positive non-zero indices.
516 //
517 // Exits early on the first detected zero or negative, which
518 // makes this more efficient than testing min(map) < 0.
519 //
520 // \note may return a false negative (ie, no flips detected)
521 // even when flip addressing is used, but the local map does not
522 // contain any flipped elements
523 static bool hasFlipAddressing(const labelUList& map);
524
525 //- Test for flip addressing, where flips are encoded as negative
526 //- indices and non-flips are encoded as positive non-zero indices.
527 //
528 // See notes above.
529 static bool hasFlipAddressing(const labelListList& maps);
530
531 //- Count the number of unmapped elements.
532 //
533 // \param elements The elements that are expected to be mapped
534 // \param maps The maps to scan
535 // \param hasFlip True if maps has flip addressing
536 // \return number of unmapped elements
537 static label countUnmapped
538 (
539 const labelUList& elements,
540 const labelListList& maps,
541 const bool hasFlip
542 );
543
544
545 // Member Functions
546
547 // Access
548
549 //- Constructed data size
550 label constructSize() const noexcept
551 {
552 return constructSize_;
553 }
554
555 //- Constructed data size
556 label& constructSize() noexcept
557 {
558 return constructSize_;
559 }
560
561 //- From subsetted data back to original data
562 const labelListList& subMap() const noexcept
563 {
564 return subMap_;
565 }
566
567 //- From subsetted data back to original data
569 {
570 return subMap_;
571 }
572
573 //- From subsetted data to new reconstructed data
574 const labelListList& constructMap() const noexcept
575 {
576 return constructMap_;
577 }
578
579 //- From subsetted data to new reconstructed data
581 {
582 return constructMap_;
583 }
584
585 //- Does subMap include a sign
586 bool subHasFlip() const noexcept
587 {
588 return subHasFlip_;
589 }
590
591 //- Does subMap include a sign
592 bool& subHasFlip() noexcept
593 {
594 return subHasFlip_;
595 }
596
597 //- Does constructMap include a sign
598 bool constructHasFlip() const noexcept
599 {
600 return constructHasFlip_;
601 }
602
603 //- Does constructMap include a sign
605 {
606 return constructHasFlip_;
607 }
608
609 //- The communicator used
610 label comm() const noexcept
611 {
612 return comm_;
613 }
614
615 //- The number of sub-lists within the maps
616 label nMaps() const noexcept
617 {
618 return constructMap_.size();
619 }
620
621 //- The sizes of the subMap lists
622 labelList subMapSizes() const;
623
624 //- The sizes of the constructMap lists
626
627 //- The sum of the subMap list sizes
628 label subMapTotalSize() const noexcept;
629
630 //- The sum of the constructMap list sizes
631 label constructMapTotalSize() const noexcept;
632
633
634 // Schedule
635
636 //- Calculate a communication schedule. See above.
637 static List<labelPair> schedule
638 (
639 const labelListList& subMap,
641 const int tag, // Message tag: msgType()
642 const label comm = UPstream::worldComm
643 );
644
645 //- Return a schedule. Demand driven. See above.
646 const List<labelPair>& schedule() const;
647
648 //- Return real or dummy schedule depending on the
649 //- communication type
651 (
652 const UPstream::commsTypes commsType
653 ) const;
654
655
656 // Other
658 //- Reset to zero size, only retaining communicator
659 void clear();
660
661 //- Transfer the contents of the argument and annul the argument.
663
664 //- Helper for construct from globalIndex. Renumbers element
665 // (in globalIndex numbering) into compact indices.
666 static label renumber
667 (
668 const globalIndex&,
669 const label comm,
670 const List<Map<label>>& compactMap,
671 const label globalElement
672 );
674 //- Helper for renumbering the (compacted) map elements
675 //- using the supplied old-to-new mapping.
676 // Only compacts the maps, does not change the local layout.
677 //
678 // \param[in,out] mapElements The map to be renumbered
679 // \param oldToNew The old-to-new mapping
680 // \param hasFlip True if map has flip addressing
681 //
682 // \return max-size needed for new addressing (eg, constructSize)
683 static label renumberMap
684 (
685 labelListList& mapElements,
686 const labelUList& oldToNew,
687 const bool hasFlip
688 );
690 //- Helper for renumbering the map elements. Assumes local elements
691 //- are first, followed by any remote. Local elements get offset,
692 //- remote elements are mapped.
693 //
694 // \param[in,out] map The map to be renumbered
695 // \param localSize elements < localSize are offset
696 // \param offset offset
697 // \param cMap map for non-local elements
698 // \param hasFlip True if map has flip addressing
699 //
700 // \return max-size needed for new addressing (eg, constructSize)
701 static label renumberMap
702 (
703 labelList& map,
704 const label localSize,
705 const label offset,
706 const Map<label>& cMap,
707 const bool hasFlip
708 );
709
710 //- Helper for a list of maps. Calls above renumberMap for all elements
711 static label renumberMap
712 (
713 labelListList& mapElements,
714 const label localSize,
715 const label offset,
716 const Map<label>& cMap,
717 const bool hasFlip
718 );
719
720
721 // Compaction
722
723 //- Compact send/receive maps based on selection of
724 //- originating local (send) elements.
725 // Determines and removes the correspondingly unneeded elements
726 // in the send/receive maps.
727 // Only compacts the maps, does not change the local layout.
728 //
729 // \param allowedLocalElems Permissible local mapped elements
730 // (true/false). Can be longer/shorter than actual number
731 // of mapped elements.
732 // \param tag The message tag
733 // \param doRenumber Apply oldToNew internally to renumber
734 // entries (uses renumberMap) and adjust the constructSize
735 //
736 // \note generally preferable to compact based on remote data
737 // (ie, the actual receiver)
739 (
740 const bitSet& allowedLocalElems,
741 const int tag = UPstream::msgType(),
742 const bool doRenumber = false
743 );
744
745 //- Compact send/receive maps based on selection of
746 //- remote (receive) elements.
747 // Determines and removes the correspondingly unneeded elements
748 // in the send/receive maps.
749 // Only compacts the maps, does not change the local layout.
750 //
751 // \param allowedRemoteElems Permissible remote mapped elements
752 // (true/false). Can be longer/shorter than actual number
753 // of mapped elements.
754 // \param tag The message tag
755 // \param doRenumber Apply oldToNew internally to renumber
756 // entries (uses renumberMap) and adjust the constructSize
758 (
759 const bitSet& allowedRemoteElems,
760 const int tag = UPstream::msgType(),
761 const bool doRenumber = false
762 );
763
764
765 //- Compact send/receive maps based on selection of
766 //- originating local (send) elements.
767 //- Returns compaction mappings for subMap and constructMap.
768 //
769 // \param allowedLocalElems Permissible local mapped elements
770 // (true/false). Can be longer/shorter than actual number
771 // of mapped elements.
772 // \param[out] oldToNewSub Old-to-new mapping: subMap
773 // Disabled if labelList::null(),
774 // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
775 // Disabled if labelList::null(),
776 // \param localSize The max index for subMap (-1: auto-detect)
777 // \param tag The message tag
778 //
779 // \note Applies oldToNew to renumber entries
780 // (uses renumberMap) and adjust constructSize
781 //
782 // \note generally preferable to compact based on remote data
783 // (ie, the actual receiver)
785 (
786 const bitSet& allowedLocalElems,
787 labelList& oldToNewSub,
788 labelList& oldToNewConstruct,
789 const label localSize = -1,
790 const int tag = UPstream::msgType()
791 );
792
793 //- Compact send/receive maps based on selection of
794 //- remote (receive) elements.
795 //- Returns compaction mappings for subMap and constructMap.
796 //
797 // \param allowedRemoteElems Permissible remote mapped elements
798 // (true/false). Can be longer/shorter than actual number
799 // of mapped elements.
800 // \param[out] oldToNewSub Old-to-new mapping: subMap
801 // Disabled if labelList::null(),
802 // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
803 // Disabled if labelList::null(),
804 // \param localSize The max index for subMap (-1: auto-detect)
805 // \param tag The message tag
806 //
807 // \note Applies oldToNew to renumber entries
808 // (uses renumberMap) and adjust constructSize
810 (
811 const bitSet& allowedRemoteElems,
812 labelList& oldToNewSub,
813 labelList& oldToNewConstruct,
814 const label localSize = -1,
815 const int tag = UPstream::msgType()
816 );
817
818
819 //- Compact send/receive maps based on selection of
820 //- originating local (send) and remote (receive) elements.
821 //
822 // The resulting compact numbering:
823 // - \c subMap (and \c oldToNewSub) :
824 // will follow the original ordering of \c localElements.
825 // - \c constructMap (and \c oldToNewConstruct) :
826 // will follow the original ordering of \c remoteElements.
827 // .
828 // \warning ill-defined behaviour if \c localElements
829 // or \c remoteElements contains duplicates.
830 void compactData
831 (
832 const labelUList& localElements,
833 const labelUList& remoteElements,
834 labelList& oldToNewSub,
835 labelList& oldToNewConstruct,
836 const label localSize = -1,
837 const int tag = UPstream::msgType()
838 );
839
840 //- Compact send/receive maps based on selection of
841 //- originating local (send) elements.
842 //
843 // The resulting compact numbering:
844 // - \c subMap (and \c oldToNewSub) :
845 // will follow the original ordering of \c localElements.
846 // - \c constructMap (and \c oldToNewConstruct) :
847 // numbered in simple ascending order.
848 // .
849 // \warning ill-defined behaviour if \c localElements
850 // contains duplicates.
851 //
852 // \note generally preferable to compact based on remote data
853 // (ie, the actual receiver)
855 (
856 const labelUList& localElements,
857 labelList& oldToNewSub,
858 labelList& oldToNewConstruct,
859 const label localSize = -1,
860 const int tag = UPstream::msgType()
861 );
862
863 //- Compact send/receive maps based on selection of
864 //- remote (receive) elements.
865 //
866 // The resulting compact numbering:
867 // - \c subMap (and \c oldToNewSub) :
868 // numbered in simple ascending order.
869 // - \c constructMap (and \c oldToNewConstruct) :
870 // will follow the original ordering of \c remoteElements.
871 // .
872 // \warning ill-defined behaviour if \c remoteElements
873 // contains duplicates.
875 (
876 const labelUList& remoteElements,
877 labelList& oldToNewSub,
878 labelList& oldToNewConstruct,
879 const label localSize = -1,
880 const int tag = UPstream::msgType()
881 );
882
883
884 // Distribute
885
886 //- Distribute combine data with specified combine operation
887 //- and negate operator (for flips).
888 //
889 // If multiple processors write to same position,
890 // contributions are added using the combine cop.
891 //
892 // \note schedule only used for UPstream::commsTypes::scheduled,
893 // others just use send-to-all, receive-from-all.
894 template<class T, class CombineOp, class NegateOp>
895 static void distribute
896 (
897 const UPstream::commsTypes commsType,
898 const UList<labelPair>& schedule,
899 const label constructSize,
900 const labelListList& subMap,
901 const bool subHasFlip,
903 const bool constructHasFlip,
904 List<T>& field,
905 const T& nullValue,
906 const CombineOp& cop,
907 const NegateOp& negOp,
908 const int tag = UPstream::msgType(),
909 const label comm = UPstream::worldComm
910 );
911
912 //- Distribute combine data with specified combine operation
913 //- and negate operator (for flips).
914 //
915 // If multiple processors write to same position,
916 // contributions are added using the combine cop.
917 //
918 // \note schedule only used for UPstream::commsTypes::scheduled,
919 // others just use send-to-all, receive-from-all.
920 template<class T, class CombineOp, class NegateOp>
921 static void distribute
922 (
923 const UPstream::commsTypes commsType,
924 const UList<labelPair>& schedule,
925
926 const UList<T>& inField, // input field
927 const labelListList& subMap,
928 const bool subHasFlip,
929
930 List<T>& field, // output field
931 const label constructSize,
933 const bool constructHasFlip,
934 const T& nullValue,
935 const CombineOp& cop,
936 const NegateOp& negOp,
937
938 const int tag = UPstream::msgType(),
939 const label comm = UPstream::worldComm
940 );
941
942 //- Distribute assign data with specified negate operator (for flips).
943 //- Uses assignment for combine operation.
944 //
945 // \note schedule only used for UPstream::commsTypes::scheduled,
946 // others just use send-to-all, receive-from-all.
947 template<class T, class NegateOp>
948 static void distribute
949 (
950 const UPstream::commsTypes commsType,
951 const UList<labelPair>& schedule,
952 const label constructSize,
953 const labelListList& subMap,
954 const bool subHasFlip,
956 const bool constructHasFlip,
957 List<T>& field,
958 const NegateOp& negOp,
959 const int tag = UPstream::msgType(),
960 const label comm = UPstream::worldComm
961 );
962
963
964 // Distribute (simpler interface)
965
966 //- Distribute List data using default commsType
967 //- and the default flip/negate operator.
968 template<class T>
969 void distribute
970 (
971 List<T>& values,
972 const int tag = UPstream::msgType()
973 ) const;
974
975 //- Distribute DynamicList data using default commsType
976 //- and the default flip/negate operator.
977 template<class T>
978 void distribute
979 (
980 DynamicList<T>& values,
981 const int tag = UPstream::msgType()
982 ) const;
983
984 //- Distribute List data using specified commsType
985 //- and the default flip/negate operator.
986 template<class T>
987 void distribute
988 (
989 const UPstream::commsTypes commsType,
990 List<T>& values,
991 const int tag = UPstream::msgType()
992 ) const;
993
994 //- Distribute DynamicList data using specified commsType
995 //- and the default flip/negate operator.
996 template<class T>
997 void distribute
998 (
999 const UPstream::commsTypes commsType,
1000 DynamicList<T>& values,
1001 const int tag = UPstream::msgType()
1002 ) const;
1003
1004 //- Distribute data using default commsType
1005 //- and the specified negate operator (for flips).
1006 template<class T, class NegateOp>
1007 void distribute
1008 (
1009 List<T>& values,
1010 const NegateOp& negOp,
1011 const int tag = UPstream::msgType()
1012 ) const;
1013
1014 //- Distribute data using specified commsType
1015 //- and the specified negate operator (for flips).
1016 // Accepts a nullValue to initialize unmapped elements
1017 // (ie, when the constructSize is larger than the number of
1018 // mapped elements).
1019 template<class T, class NegateOp>
1020 void distribute
1021 (
1022 const UPstream::commsTypes commsType,
1023 List<T>& values,
1024 const NegateOp& negOp,
1025 const int tag = UPstream::msgType()
1026 ) const;
1027
1028 //- Distribute data using specified commsType
1029 //- and the specified negate operator (for flips).
1030 // Accepts a nullValue to initialize unmapped elements
1031 // (ie, when the constructSize is larger than the number of
1032 // mapped elements).
1033 template<class T, class NegateOp>
1034 void distribute
1035 (
1036 const UPstream::commsTypes commsType,
1037 const T& nullValue,
1038 List<T>& values,
1039 const NegateOp& negOp,
1040 const int tag = UPstream::msgType()
1041 ) const;
1042
1043
1044 // Reverse Distribute (simpler interface)
1045
1046 //- Reverse distribute data using default commsType
1047 //- and the default flip/negate operator
1048 template<class T>
1050 (
1051 const label constructSize,
1052 List<T>& values,
1053 const int tag = UPstream::msgType()
1054 ) const;
1055
1056 //- Reverse distribute data using default commsType
1057 //- and the default flip/negate operator.
1058 // Accepts a nullValue to initialize unmapped elements
1059 // (ie, when the constructSize is larger than the subMap).
1060 template<class T>
1062 (
1063 const label constructSize,
1064 const T& nullValue,
1065 List<T>& values,
1066 const int tag = UPstream::msgType()
1067 ) const;
1068
1069 //- Reverse distribute data using specified commsType
1070 //- and the default flip/negate operator
1071 template<class T>
1073 (
1074 const UPstream::commsTypes commsType,
1075 const label constructSize,
1076 List<T>& values,
1077 const int tag = UPstream::msgType()
1078 ) const;
1079
1080 //- Reverse distribute data using specified commsType
1081 //- and the specified flip/negate operator.
1082 template<class T, class NegateOp>
1084 (
1085 const UPstream::commsTypes commsType,
1086 const label constructSize,
1087 List<T>& values,
1088 const NegateOp& negOp,
1089 const int tag = UPstream::msgType()
1090 ) const;
1091
1092 //- Reverse distribute data using specified commsType
1093 //- and the default flip/negate operator.
1094 // Accepts a nullValue to initialize unmapped elements
1095 // (ie, when the constructSize is larger than the subMap).
1096 template<class T>
1098 (
1099 const UPstream::commsTypes commsType,
1100 const label constructSize,
1101 const T& nullValue,
1102 List<T>& values,
1103 const int tag = UPstream::msgType()
1104 ) const;
1105
1106
1107 // Send/Receive
1108
1109 //- Do all sends using PstreamBuffers
1110 template<class T>
1111 void send(PstreamBuffers& pBufs, const UList<T>& field) const;
1112
1113 //- Do all receives using PstreamBuffers
1114 template<class T>
1115 void receive(PstreamBuffers& pBufs, List<T>& field) const;
1116
1117
1118 // Low-level. Non-blocking. TBD: receive map is usually contiguous
1119 // - receive into slices
1120
1121 //- Start all sends and receives (always non-blocking)
1122 template<class T, class negateOp>
1123 static void send
1124 (
1125 const labelListList& subMap,
1126 const bool subHasFlip,
1128 const bool constructHasFlip,
1129 const UList<T>& field,
1130 labelRange& sendRequests,
1131 PtrList<List<T>>& sendFields,
1132 labelRange& recvRequests,
1133 PtrList<List<T>>& recvFields,
1134 const negateOp& negOp,
1135 const int tag,
1136 const label comm
1137 );
1138
1139 //- Start all sends and receives (always non-blocking)
1140 template<class T>
1141 void send
1142 (
1143 const UList<T>& field,
1144 labelRange& sendRequests,
1145 PtrList<List<T>>& sendFields,
1146 labelRange& recvRequests,
1147 PtrList<List<T>>& recvFields,
1148 const int tag = UPstream::msgType()
1149 ) const;
1150
1151 //- Wait for (receive) requests to finish and consume
1152 template<class T, class CombineOp, class negateOp>
1153 static void receive
1154 (
1155 const label constructSize,
1157 const bool constructHasFlip,
1158 const labelRange& requests,
1159 const UPtrList<List<T>>& recvFields,
1160 List<T>& field,
1161 const CombineOp& cop,
1162 const negateOp& negOp,
1163 const int tag,
1164 const label comm
1165 );
1166
1167 //- Wait for (receive) requests to finish and consume
1168 template<class T>
1169 void receive
1170 (
1171 const labelRange& requests,
1172 const UPtrList<List<T>>& recvFields,
1173 List<T>& field,
1174 const int tag = UPstream::msgType()
1175 ) const;
1176
1177
1178 // Other
1179
1180 //- Debug: print layout. Can only be used on maps with sorted
1181 // storage (local data first, then non-local data)
1182 void printLayout(Ostream& os) const;
1183
1184
1185 // Member Operators
1186
1187 //- Copy assignment
1188 void operator=(const mapDistributeBase& rhs);
1189
1190 //- Move assignment
1191 void operator=(mapDistributeBase&& rhs);
1192
1193
1194 // IOstream Operators
1195
1196 //- Return info proxy,
1197 //- used to print summary information to a stream
1199 {
1200 return *this;
1201 }
1202
1203 //- Read entries from dictionary format
1204 void readDict(const dictionary& dict);
1205
1206 //- Write entries in dictionary format
1207 void writeEntries(Ostream& os) const;
1208
1209 //- Read plain content (not dictionary) from Istream
1211
1212 //- Write plain content (not dictionary) to Ostream
1213 friend Ostream& operator<<(Ostream&, const mapDistributeBase&);
1214
1215
1216 // Housekeeping
1217
1218 //- No correction for topo change
1219 void updateMesh(const mapPolyMesh&)
1220 {
1222 }
1223
1224 //- OpenFOAM-v2112 and earlier naming for compactRemoteData()
1225 //- using boolList.
1226 void compact
1227 (
1228 const boolList& remoteElemUsed,
1229 const int tag = UPstream::msgType()
1230 );
1231
1232 //- OpenFOAM-v2112 and earlier naming for compactRemoteData().
1233 //- using boolList.
1234 void compact
1235 (
1236 const boolList& remoteElemUsed,
1237 const label localSize,
1238 labelList& oldToNewSub,
1239 labelList& oldToNewConstruct,
1240 const int tag = UPstream::msgType()
1241 );
1242};
1243
1244
1245// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1246
1247} // End namespace Foam
1248
1249// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1250
1251#ifdef NoRepository
1253#endif
1254
1255// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1256
1257#endif
1258
1259// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Buffers for inter-processor communications streams (UOPstream, UIPstream).
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Inter-processor communications stream.
Definition UPstream.H:69
static int & msgType() noexcept
Message tag of standard messages.
Definition UPstream.H:1926
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
Central-differencing interpolation scheme class.
Definition linear.H:54
Class containing processor-to-processor mapping information.
friend Ostream & operator<<(Ostream &, const mapDistributeBase &)
Write plain content (not dictionary) to Ostream.
mapDistributeBase() noexcept
Default construct (uses worldComm).
static void accessAndFlip(UList< T > &output, const UList< T > &values, const labelUList &map, const bool hasFlip, const NegateOp &negOp)
Lookup field values at specified map indices and save after any flip negation operations.
const List< labelPair > & whichSchedule(const UPstream::commsTypes commsType) const
Return real or dummy schedule depending on the communication type.
bool & constructHasFlip() noexcept
Does constructMap include a sign.
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.
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.
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
void send(PstreamBuffers &pBufs, const UList< T > &field) const
Do all sends using PstreamBuffers.
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
ClassName("mapDistributeBase")
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
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.
static List< labelPair > schedule(const labelListList &subMap, const labelListList &constructMap, const int tag, const label comm=UPstream::worldComm)
Calculate a communication schedule. See above.
label nMaps() const noexcept
The number of sub-lists within the maps.
bool constructHasFlip() const noexcept
Does constructMap include a sign.
static List< T > accessAndFlip(const UList< T > &values, const labelUList &map, const bool hasFlip, const NegateOp &negOp)
Lookup field values at specified indices and return after any flip negation operations.
const labelListList & subMap() const noexcept
From subsetted data back to original data.
void calcCompactAddressing(const globalIndex &globalNumbering, const labelUList &elements, List< Map< label > > &compactMap) const
Construct per processor compact addressing of the global elements.
void readDict(const dictionary &dict)
Read entries from dictionary format.
friend Istream & operator>>(Istream &, mapDistributeBase &)
Read plain content (not dictionary) from Istream.
void writeEntries(Ostream &os) const
Write entries in dictionary format.
static void checkReceivedSize(const label proci, const label expectedSize, const label receivedSize)
Fatal if expected != received size.
bool subHasFlip() const noexcept
Does subMap include a sign.
labelList constructMapSizes() const
The sizes of the constructMap lists.
void receive(PstreamBuffers &pBufs, List< T > &field) const
Do all receives using PstreamBuffers.
void exchangeAddressing(const int tag, const globalIndex &globalNumbering, labelList &elements, List< Map< label > > &compactMap, labelList &compactStart)
static label renumber(const globalIndex &, const label comm, const List< Map< label > > &compactMap, const label globalElement)
Helper for construct from globalIndex. Renumbers element.
static void distribute(const UPstream::commsTypes commsType, const UList< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &field, const T &nullValue, const CombineOp &cop, const NegateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute combine data with specified combine operation and negate operator (for flips).
labelList subMapSizes() const
The sizes of the subMap lists.
static label countUnmapped(const labelUList &elements, const labelListList &maps, const bool hasFlip)
Count the number of unmapped elements.
bool & subHasFlip() noexcept
Does subMap include a sign.
static label getMappedSize(const labelListList &maps, const bool hasFlip)
Scan the maps for the max addressed index.
void compact(const boolList &remoteElemUsed, const int tag=UPstream::msgType())
OpenFOAM-v2112 and earlier naming for compactRemoteData() using boolList.
labelListList & subMap() noexcept
From subsetted data back to original data.
label comm() const noexcept
The communicator used.
static void flipAndCombine(UList< T > &lhs, const UList< T > &rhs, const labelUList &map, const bool hasFlip, const CombineOp &cop, const NegateOp &negOp)
Combine field values (after any flip negation operation) into the specified mapped target locations.
static void exchangeMasks(const UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Synchronize send/recv mask buffers as a 'copy' operation.
void clear()
Reset to zero size, only retaining communicator.
void updateMesh(const mapPolyMesh &)
No correction for topo change.
static bool hasFlipAddressing(const labelUList &map)
Test for flip addressing, where flips are encoded as negative indices and non-flips are encoded as po...
label subMapTotalSize() const noexcept
The sum of the subMap list sizes.
InfoProxy< mapDistributeBase > info() const noexcept
Return info proxy, used to print summary information to a stream.
static void unionCombineMasks(UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Bi-direction sync of send/recv buffers using bitwise '&=' combine operation.
label & constructSize() noexcept
Constructed data size.
label constructMapTotalSize() const noexcept
The sum of the constructMap list sizes.
layoutTypes
The map layout (eg, of the constructMap).
@ localFirst
Local processor first, others in linear order.
labelListList & constructMap() noexcept
From subsetted data to new reconstructed data.
label constructSize() const noexcept
Constructed data size.
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.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
rDeltaTY field()
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
OBJstream os(runTime.globalPath()/outputName)
surface1 clear()
Namespace for OpenFOAM.
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values within a list.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
List< bool > boolList
A List of bools.
Definition List.H:60
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dictionary dict