globalIndex.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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::globalIndex
29
30Description
31 Calculates a unique integer (label so might not have enough room - 2G max)
32 for processor + local index. E.g.
33
34 globalIndex globalFaces(mesh.nFaces());
35 label globalFacei = globalFaces.toGlobal(facei);
36
37SourceFiles
38 globalIndex.C
39 globalIndexI.H
40 globalIndexTemplates.C
41
42\*---------------------------------------------------------------------------*/
43
44#ifndef Foam_globalIndex_H
45#define Foam_globalIndex_H
46
47#include "Pstream.H"
48#include "CompactListList.H"
49#include "DynamicList.H"
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53namespace Foam
54{
55
56// Forward Declarations
57class globalIndex;
58class labelRange;
59
60Istream& operator>>(Istream& is, globalIndex& gi);
61Ostream& operator<<(Ostream& os, const globalIndex& gi);
62
63
64/*---------------------------------------------------------------------------*\
65 Class globalIndex Declaration
66\*---------------------------------------------------------------------------*/
68class globalIndex
69{
70 // Private Data
71
72 //- Start of proci. Size is nProcs()+1. (so like CompactListList)
73 labelList offsets_;
74
75
76 // Private Member Functions
77
78 //- Sort and bin. validBins contains bins with non-zero size.
80 bin
81 (
82 const labelUList& offsets,
83 const labelUList& globalIds,
84 labelList& order,
85 DynamicList<label>& validBins
86 );
87
88 //- Report overflow at specified index
89 static void reportOverflowAndExit
90 (
91 const label idx,
92 const labelUList& localLens = labelUList::null()
93 );
94
95public:
96
97 // Public Data Types
98
99 //- Disambiguation tag (list construction dispatch)
100 enum accessType : char { OFFSETS, SIZES };
101
102 //- Dispatch tag
103 struct gatherOnly{};
104
105 //- Dispatch tag
106 struct gatherNone{};
107
108
109 // Constructors
110
111 //- Default construct
112 globalIndex() = default;
113
114 //- Copy construct from a list of offsets.
115 //- No communication required
116 inline explicit globalIndex(const labelUList& listOffsets);
117
118 //- Move construct from a list of offsets.
119 //- No communication required
120 inline explicit globalIndex(labelList&& listOffsets);
121
122 //- Copy construct from a list of offsets or sizes.
123 //- No communication required
124 inline globalIndex
125 (
126 const labelUList& offsetsOrSizes,
127 enum accessType accType
128 );
129
130 //- Construct from local size, using gather/broadcast
131 //- with default/specified communicator if parallel.
132 inline explicit globalIndex
133 (
134 const label localSize,
135 const label comm = UPstream::worldComm,
136 const bool parallel = UPstream::parRun()
137 );
138
139 //- Construct by gathering local sizes without rescattering.
140 //- This 'one-sided' globalIndex will be empty on non-master processes.
141 //
142 // \note can be used when Pstream::parRun() is false.
143 inline globalIndex
144 (
145 const label localSize,
147 const label comm = UPstream::worldComm
148 );
149
150 //- Construct with a single size entry.
151 //- No communication required
152 inline globalIndex
153 (
154 const label localSize,
156 const label comm = -1
157 );
158
159 //- Construct from Istream.
160 //- No communication required
161 explicit globalIndex(Istream& is);
162
163
164 // Member Functions
165
166 //- Check for default constructed or global sum == 0
167 inline bool empty() const;
168
169 //- Global sum of localSizes. Same as totalSize()
170 inline label size() const;
171
172 //- Global sum of localSizes.
173 inline label totalSize() const;
174
175 //- The local sizes. Same as localSizes()
176 inline labelList sizes() const;
177
178 //- The local starts
179 inline const labelUList localStarts() const;
180
181 //- The local sizes
182 labelList localSizes() const;
183
184 //- Global max of localSizes
185 inline label maxSize() const;
186
187 //- Const-access to the offsets
188 inline const labelList& offsets() const noexcept;
189
190
191 // Dimensions
192
193 //- The number of processors covered by the offsets
194 inline label nProcs() const noexcept;
195
196 //- Range of process indices for all addressed offsets (processes)
197 inline labelRange allProcs() const noexcept;
198
199 //- Range of process indices for addressed sub-offsets (processes)
200 inline labelRange subProcs() const noexcept;
201
202
203 // Edit
204
205 //- Write-access to the offsets, for changing after construction
206 inline labelList& offsets() noexcept;
207
208 //- Reset from local size, using gather/broadcast
209 //- with default/specified communicator if parallel.
210 void reset
211 (
212 const label localSize,
213 const label comm = UPstream::worldComm,
214 const bool parallel = UPstream::parRun()
215 );
216
217 //- Reset by gathering local sizes without rescattering.
218 //- This 'one-sided' globalIndex will be empty on non-master processes.
219 //
220 // \note can be used when Pstream::parRun() is false.
221 void reset
222 (
223 const label localSize,
224 const globalIndex::gatherOnly,
225 const label comm = UPstream::worldComm
226 );
227
228 //- Reset from list of local sizes,
229 //- with optional check for label overflow.
230 //- No communication required
231 void reset
232 (
233 const labelUList& localLens,
234 const bool checkOverflow = false
235 );
236
237 //- Alter local size for given processor
238 void setLocalSize(const label proci, const label len);
239
240
241 // Queries
242
243 // Queries relating to my processor (using world communicator)
244
245 //- My local start
246 inline label localStart() const;
247
248 //- My local size
249 inline label localSize() const;
250
251 //- The max of localSizes, excluding current processor
252 inline label maxNonLocalSize() const;
253
254 //- Return start/size range of local processor data
255 inline labelRange range() const;
256
257 //- Return start/size ranges for all data
258 List<labelRange> ranges() const;
259
260 //- Is on local processor
261 inline bool isLocal(const label i) const;
262
263 //- From local to global index
264 inline label toGlobal(const label i) const;
265
266 //- From local to global index
267 inline labelList toGlobal(const labelUList& labels) const;
268
269 //- From local to global index (inplace)
270 inline void inplaceToGlobal(labelUList& labels) const;
271
272 //- From global to local on current processor.
273 // FatalError if not on local processor.
274 inline label toLocal(const label i) const;
275
276
277 // Global (off-processor) queries
278
279 //- Start of proci data
280 inline label localStart(const label proci) const;
281
282 //- Size of proci data
283 inline label localSize(const label proci) const;
284
285 //- The max of localSizes, excluding the specified processor
286 label maxNonLocalSize(const label proci) const;
287
288 //- Return start/size range of proci data
289 inline labelRange range(const label proci) const;
290
291 //- Is on processor proci
292 inline bool isLocal(const label proci, const label i) const;
293
294 //- From local to global on proci
295 inline label toGlobal(const label proci, const label i) const;
296
297 //- From local to global on proci
298 inline labelList toGlobal
299 (
300 const label proci,
301 const labelUList& labels
302 ) const;
303
304 //- From local to global index on proci (inplace)
305 inline void inplaceToGlobal
306 (
307 const label proci,
308 labelUList& labels
309 ) const;
310
311
312 //- From global to local on proci
313 inline label toLocal(const label proci, const label i) const;
314
315 //- Which processor does global id come from?
316 // Does an initial check for isLocal first (assumed to occur
317 // reasonably frequently) followed by a binary search.
318 //- Fatal for out of range ids (eg, negative or >= totalSize()
319 inline label whichProcID(const label i) const;
320
321
322 // Iteration
323
324 //- Forward input iterator with const access
325 class const_iterator
326 {
327 //- The parent class for which this is an iterator
328 const globalIndex* parent_;
329
330 //- The index into the parent
331 label proci_;
332
333
334 public:
335
336 // Constructors
337
338 //- Construct from globalIndex list at given index
339 explicit const_iterator
340 (
341 const globalIndex* globalIdx,
342 const label proci = 0
343 ) noexcept;
344
345
346 // Member Operators
347
348 //- The associated local proc
349 inline label proci() const noexcept;
350
351 //- The local start
352 inline label start() const;
353
354 //- The local size
355 inline label size() const;
356
357 //- The local range
358 inline labelRange range() const;
359
360 //- The local range
361 inline labelRange operator*() const;
362
363 inline const_iterator& operator++();
364 inline const_iterator operator++(int);
365
366 inline const_iterator& operator--();
367 inline const_iterator operator--(int);
368
369 inline bool operator==(const const_iterator& iter) const noexcept;
370 inline bool operator!=(const const_iterator& iter) const noexcept;
371 };
372
373
374 //- A const_iterator set to the beginning
375 inline const_iterator cbegin() const noexcept;
376
377 //- A const_iterator set to beyond the end
378 inline const const_iterator cend() const noexcept;
379
380 //- A const_iterator set to the beginning
381 inline const_iterator begin() const noexcept;
382
383 //- A const_iterator set to beyond the end
384 inline const const_iterator end() const noexcept;
385
386
387 // Helper Functions
388
389 //- Calculate offsets from a list of local sizes,
390 //- with optional check for label overflow
391 static labelList calcOffsets
392 (
393 const labelUList& localLens,
394 const bool checkOverflow = false
395 );
396
397 //- Calculate offsets from list of lists,
398 //- with optional check for label overflow
399 template<class SubListType>
400 static labelList calcListOffsets
401 (
402 const List<SubListType>& lists,
403 const bool checkOverflow = false
404 );
405
406 //- Calculate ranges (offset/size) from a list of local sizes,
407 //- with optional check for label overflow
408 static List<labelRange> calcRanges
409 (
410 const labelUList& localLens,
411 const bool checkOverflow = false
412 );
413
414 //- Collect single values in processor order on master (== procIDs[0]).
415 // Handles contiguous/non-contiguous data.
416 template<class ProcIDsContainer, class Type>
417 static void gatherValues
418 (
419 const label comm,
420 const ProcIDsContainer& procIDs,
421 const Type& localValue,
422 List<Type>& allValues,
423 const int tag = UPstream::msgType(),
424 const UPstream::commsTypes = UPstream::commsTypes::nonBlocking
425 );
426
427 //- Collect data in processor order on master (== procIDs[0]).
428 // Handles contiguous/non-contiguous data, skips empty fields.
429 template<class ProcIDsContainer, class Type>
430 static void gather
431 (
432 const labelUList& offsets,
433 const label comm,
434 const ProcIDsContainer& procIDs,
435 const UList<Type>& fld,
436 List<Type>& allFld,
437 const int tag = UPstream::msgType(),
438 const UPstream::commsTypes = UPstream::commsTypes::nonBlocking
439 );
440
441 //- Collect indirect data in processor order on master
442 // Handles contiguous/non-contiguous data, skips empty fields.
443 template<class Type, class Addr>
444 static void gather
445 (
446 const labelUList& offsets,
447 const label comm,
448 const UList<int>& procIDs,
449 const IndirectListBase<Type, Addr>& fld,
450 List<Type>& allFld,
451 const int tag = UPstream::msgType(),
452 const UPstream::commsTypes = UPstream::commsTypes::nonBlocking
453 );
454
455
456 // Misc low-level gather routines
457
458 //- Inplace collect in processor order on master (== procIDs[0]).
459 // Note: adjust naming?
460 template<class ProcIDsContainer, class Type>
461 static void gather
462 (
463 const labelUList& offsets,
464 const label comm,
465 const ProcIDsContainer& procIDs,
466 List<Type>& fld,
467 const int tag = UPstream::msgType(),
468 const UPstream::commsTypes ct = UPstream::commsTypes::nonBlocking
469 )
470 {
471 List<Type> allData;
472 gather(offsets, comm, procIDs, fld, allData, tag, ct);
473 if (Pstream::myProcNo(comm) == procIDs[0])
474 {
475 fld.transfer(allData);
476 }
477 }
478
479 //- Collect data in processor order on master (== procIDs[0]).
480 // \note the globalIndex offsets needed on master only.
481 template<class ProcIDsContainer, class Type>
482 void gather
483 (
484 const label comm,
485 const ProcIDsContainer& procIDs,
486 const UList<Type>& fld,
487 List<Type>& allFld,
488 const int tag = UPstream::msgType(),
490 ) const
491 {
492 gather(offsets_, comm, procIDs, fld, allFld, tag, ct);
493 }
494
495 //- Inplace collect in processor order on master (== procIDs[0]).
496 // \note the globalIndex offsets needed on master only.
497 // Note: adjust naming?
498 template<class ProcIDsContainer, class Type>
499 void gather
500 (
501 const label comm,
502 const ProcIDsContainer& procIDs,
503 List<Type>& fld,
504 const int tag = UPstream::msgType(),
506 ) const
507 {
508 gather(offsets_, comm, procIDs, fld, tag, ct);
509 }
510
511
512 // Gather
513
514 //- Collect data in processor order on master
515 //- (in serial: performs a simple copy).
516 // Communication with default/specified communicator, message tag.
517 template<class Type>
518 void gather
519 (
520 const UList<Type>& sendData,
521 List<Type>& allData,
522 const int tag = UPstream::msgType(),
524 const label comm = UPstream::worldComm
525 ) const;
526
527 //- Collect data indirectly in processor order on master
528 //- (in serial: performs a simple copy).
529 // Communication with default/specified communicator, message tag.
530 template<class Type, class Addr>
531 void gather
532 (
533 const IndirectListBase<Type, Addr>& sendData,
534 List<Type>& allData,
535 const int tag = UPstream::msgType(),
537 const label comm = UPstream::worldComm
538 ) const;
539
540 //- Collect data in processor order on master
541 //- (in serial: performs a simple copy).
542 // Communication with default/specified communicator, message tag.
543 //
544 // \return output (master), zero-sized on non-master
545 template<class Type, class OutputContainer = List<Type>>
546 OutputContainer gather
547 (
548 const UList<Type>& sendData,
549 const int tag = UPstream::msgType(),
551 const label comm = UPstream::worldComm
552 ) const;
553
554 //- Collect data indirectly in processor order on master.
555 // Communication with default/specified communicator, message tag.
556 //
557 // \return output (master), zero-sized on non-master
558 template<class Type, class Addr, class OutputContainer = List<Type>>
559 OutputContainer gather
560 (
561 const IndirectListBase<Type, Addr>& sendData,
562 const int tag = UPstream::msgType(),
564 const label comm = UPstream::worldComm
565 ) const;
566
567 //- Inplace collect data in processor order on master
568 //- (in serial: a no-op).
569 // Communication with default/specified communicator, message tag.
570 // After the gather, the field is zero-sized on the slaves.
571 template<class Type>
572 void gatherInplace
573 (
575 const int tag = UPstream::msgType(),
577 const label comm = UPstream::worldComm
578 ) const;
579
580 //- Use MPI_Gatherv call for contiguous data when possible
581 //- (in serial: performs a simple copy).
582 // Communication with default/specified communicator.
583 // \attention The nProcs for globalIndex and communicator
584 // must match!!
585 //
586 // The allData is output (master), zero-sized on non-master
587 template<class Type, class OutputContainer = List<Type>>
588 void mpiGather
589 (
590 const UList<Type>& sendData,
591 OutputContainer& allData,
592 const label comm = UPstream::worldComm,
593
594 // For fallback routines:
596 const int tag = UPstream::msgType()
597 ) const;
598
599 //- Use MPI_Gatherv call for contiguous data when possible
600 //- (in serial: performs a simple copy).
601 // Communication with default/specified communicator.
602 // \attention The nProcs for globalIndex and communicator
603 // must match!!
604 //
605 // \return output (master), zero-sized on non-master
606 template<class Type, class OutputContainer = List<Type>>
607 OutputContainer mpiGather
608 (
609 const UList<Type>& sendData,
610 const label comm = UPstream::worldComm,
611
612 // For fallback routines:
614 const int tag = UPstream::msgType()
615 ) const;
616
617 //- Use MPI_Gatherv call to inplace collect contiguous data
618 //- when possible.
619 //- (in serial: a no-op).
620 // Communication with default/specified communicator.
621 // \attention The nProcs for globalIndex and communicator
622 // must match!!
623 //
624 // After the gather, the field is zero-sized on non-master.
625 template<class Type>
627 (
629 const label comm = UPstream::worldComm,
630
631 // For fallback routines:
633 const int tag = UPstream::msgType()
634 ) const;
635
636
637 // Gather Operations
638
639 //- Use MPI_Gatherv call to collect contiguous data when possible
640 //- (in serial: performs a simple copy).
641 // Communication with default/specified communicator.
642 //
643 // The allData is output (master), zero-sized on non-master
644 template<class Type, class OutputContainer = List<Type>>
645 static void mpiGatherOp
646 (
647 const UList<Type>& sendData,
648 OutputContainer& allData,
649 const label comm = UPstream::worldComm,
650
651 // For fallback routines:
653 const int tag = UPstream::msgType()
654 );
655
656 //- Use MPI_Gatherv call to collect contiguous data when possible
657 //- (in serial: performs a simple copy).
658 // Communication with default/specified communicator.
659 //
660 // \return output (master), zero-sized on non-master
661 template<class Type, class OutputContainer = List<Type>>
662 static OutputContainer mpiGatherOp
663 (
664 const UList<Type>& sendData,
665 const label comm = UPstream::worldComm,
666
667 // For fallback routines:
669 const int tag = UPstream::msgType()
670 );
671
672 //- Use MPI_Gatherv call to inplace collect contiguous data
673 //- when possible.
674 //- (in serial: a no-op).
675 // Communication with default/specified communicator.
676 //
677 // After the gather, the field is zero-sized on non-master.
678 template<class Type>
679 static void mpiGatherInplaceOp
680 (
682 const label comm = UPstream::worldComm,
683
684 // For fallback routines:
686 const int tag = UPstream::msgType()
687 );
688
689 //- Collect data in processor order on master
690 //- (in serial: performs a simple copy).
691 // Communication with default/specified communicator, message tag.
692 //
693 // The allFld is output (master), zero-sized on non-master
694 template<class Type>
695 static void gatherOp
696 (
697 const UList<Type>& sendData,
698 List<Type>& allData,
699 const int tag = UPstream::msgType(),
701 const label comm = UPstream::worldComm
702 );
703
704 //- Collect data in processor order on master
705 //- (in serial: performs a simple copy).
706 // Communication with default/specified communicator, message tag.
707 //
708 // The allFld is output (master), zero-sized on non-master
709 template<class Type, class Addr>
710 static void gatherOp
711 (
712 const IndirectListBase<Type, Addr>& sendData,
713 List<Type>& allData,
714 const int tag = UPstream::msgType(),
716 const label comm = UPstream::worldComm
717 );
718
719 //- Collect and return data in processor order on master
720 //- (in serial: performs a simple copy).
721 // Communication with default/specified communicator, message tag.
722 //
723 // \return output (master), zero-sized on non-master
724 template<class Type, class OutputContainer = List<Type>>
725 static OutputContainer gatherOp
726 (
727 const UList<Type>& sendData,
728 const int tag = UPstream::msgType(),
730 const label comm = UPstream::worldComm
731 );
732
733 //- Collect and return data in processor order on master
734 //- (in serial: performs a simple copy).
735 // Communication with default/specified communicator, message tag.
736 //
737 // \return output (master), zero-sized on non-master
738 template<class Type, class Addr, class OutputContainer = List<Type>>
739 static OutputContainer gatherOp
740 (
741 const IndirectListBase<Type, Addr>& sendData,
742 const int tag = UPstream::msgType(),
744 const label comm = UPstream::worldComm
745 );
746
747 //- Inplace collect data in processor order on master
748 //- (in serial: a no-op).
749 // Communication with default/specified communicator, message tag.
750 //
751 // After the gather, the field is zero-sized on the slaves.
752 template<class Type>
753 static void gatherInplaceOp
754 (
756 const int tag = UPstream::msgType(),
758 const label comm = UPstream::worldComm
759 );
760
761
762 // Scatter
763
764 //- Distribute data in processor order.
765 // Requires fld to be correctly sized!
766 // Communication with default/specified communicator, message tag.
767 template<class ProcIDsContainer, class Type>
768 static void scatter
769 (
770 const labelUList& offsets,
771 const label comm,
772 const ProcIDsContainer& procIDs,
773 const UList<Type>& allFld,
775 const int tag = UPstream::msgType(),
777 );
778
779 //- Distribute data in processor order.
780 // Requires fld to be correctly sized!
781 // Communication with default/specified communicator, message tag.
782 // \note the globalIndex offsets needed on master only.
783 template<class ProcIDsContainer, class Type>
784 void scatter
785 (
786 const label comm,
787 const ProcIDsContainer& procIDs,
788 const UList<Type>& allFld,
790 const int tag = UPstream::msgType(),
791 const UPstream::commsTypes ct =
793 ) const
794 {
795 scatter(offsets_, comm, procIDs, allFld, fld, tag, ct);
796 }
797
798 //- Distribute data in processor order.
799 // Requires fld to be correctly sized!
800 // Communication with default/specified communicator, message tag.
801 // \note the globalIndex offsets needed on master only.
802 template<class Type>
803 void scatter
804 (
805 const UList<Type>& allData,
806 UList<Type>& localData,
807 const int tag = UPstream::msgType(),
809 const label comm = UPstream::worldComm
810 ) const;
811
812 //- Distribute data in processor order
813 //- (in serial: performs a simple copy).
814 // Communication with default/specified communicator, message tag.
815 // \note the globalIndex offsets needed on master only.
816 template<class Type, class OutputContainer = List<Type>>
817 OutputContainer scatter
818 (
819 const UList<Type>& allData,
820 const int tag = UPstream::msgType(),
822 const label comm = UPstream::worldComm
823 ) const;
824
825
826 // Scatter
827
828 //- Get (potentially remote) data.
829 //- Elements required given as global indices
830 // Communication with default/specified communicator, message tag.
831 template<class Type, class CombineOp>
832 void get
833 (
834 List<Type>& allFld,
835 const labelUList& globalIds,
836 const CombineOp& cop,
837 const label comm = UPstream::worldComm,
838 const int tag = UPstream::msgType()
839 ) const;
840
841
842 // IOstream Operators
845 friend Ostream& operator<<(Ostream& os, const globalIndex& gi);
846
847
848 // Housekeeping
849
850 //- Construct from local size, using gather/broadcast
851 //- with default/specified communicator if parallel.
852 FOAM_DEPRECATED_FOR(2022-03, "construct without message tag")
854 (
855 const label localSize,
856 const int tag, // message tag (unused)
857 const label comm, // communicator
858 const bool parallel // use parallel comms
859 )
860 {
862 }
863
864 //- Reset from local size, using gather/broadcast
865 //- with default/specified communicator if parallel.
866 FOAM_DEPRECATED_FOR(2022-03, "reset without message tag")
867 void reset
868 (
869 const label localSize,
870 const int tag, // message tag (unused)
871 const label comm, // communicator
872 const bool parallel // use parallel comms
873 )
874 {
876 }
877
878 //- Prefer localStart() to avoid confusing with offsets()
879 FOAM_DEPRECATED_FOR(2022-02, "use localStart()")
880 label offset(const label proci) const { return localStart(proci); }
881};
882
883
884// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
885
886} // End namespace Foam
887
888// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
889
890#include "globalIndexI.H"
891
892// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
893
894#ifdef NoRepository
895 #include "globalIndexTemplates.C"
896#endif
897
898// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
899
900#endif
901
902// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Inter-processor communications stream.
Definition: UPstream.H:59
commsTypes
Types of communications.
Definition: UPstream.H:67
@ nonBlocking
"nonBlocking"
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
void gather(const label comm, const ProcIDsContainer &procIDs, const UList< Type > &fld, List< Type > &allFld, const int tag=UPstream::msgType(), const UPstream::commsTypes ct=UPstream::commsTypes::nonBlocking) const
Collect data in processor order on master (== procIDs[0]).
Definition: globalIndex.H:482
static void gatherInplaceOp(List< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const label comm=UPstream::worldComm)
Inplace collect data in processor order on master (in serial: a no-op).
static void mpiGatherInplaceOp(List< Type > &fld, const label comm=UPstream::worldComm, const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const int tag=UPstream::msgType())
Use MPI_Gatherv call to inplace collect contiguous data when possible. (in serial: a no-op).
label maxSize() const
Global max of localSizes.
Definition: globalIndexI.H:213
globalIndex()=default
Default construct.
label localSize() const
My local size.
Definition: globalIndexI.H:207
accessType
Disambiguation tag (list construction dispatch)
Definition: globalIndex.H:99
void get(List< Type > &allFld, const labelUList &globalIds, const CombineOp &cop, const label comm=UPstream::worldComm, const int tag=UPstream::msgType()) const
Get (potentially remote) data. Elements required given as global indices.
friend Ostream & operator<<(Ostream &os, const globalIndex &gi)
labelRange range() const
Return start/size range of local processor data.
Definition: globalIndexI.H:232
label size() const
Global sum of localSizes. Same as totalSize()
Definition: globalIndexI.H:132
void reset(const label localSize, const label comm=UPstream::worldComm, const bool parallel=UPstream::parRun())
Definition: globalIndex.C:207
FOAM_DEPRECATED_FOR(2022-03, "construct without message tag") globalIndex(const label localSize
Construct from local size, using gather/broadcast with default/specified communicator if parallel.
List< labelRange > ranges() const
Return start/size ranges for all data.
Definition: globalIndex.C:315
label localStart() const
My local start.
Definition: globalIndexI.H:195
bool empty() const
Check for default constructed or global sum == 0.
Definition: globalIndexI.H:119
label nProcs() const noexcept
The number of processors covered by the offsets.
Definition: globalIndexI.H:144
labelList & offsets() noexcept
Write-access to the offsets, for changing after construction.
Definition: globalIndexI.H:173
FOAM_DEPRECATED_FOR(2022-02, "use localStart()") label offset(const label proci) const
Prefer localStart() to avoid confusing with offsets()
Definition: globalIndex.H:878
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:260
const labelUList localStarts() const
The local starts.
Definition: globalIndexI.H:179
static void gather(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &fld, List< Type > &allFld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Collect data in processor order on master (== procIDs[0]).
void inplaceToGlobal(labelUList &labels) const
From local to global index (inplace)
Definition: globalIndexI.H:303
void gatherInplace(List< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const label comm=UPstream::worldComm) const
Inplace collect data in processor order on master (in serial: a no-op).
static void scatter(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &allFld, UList< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Distribute data in processor order.
const int const label comm
Definition: globalIndex.H:856
labelRange subProcs() const noexcept
Range of process indices for addressed sub-offsets (processes)
Definition: globalIndexI.H:159
label maxNonLocalSize() const
The max of localSizes, excluding current processor.
Definition: globalIndexI.H:220
void gather(const label comm, const ProcIDsContainer &procIDs, List< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes ct=UPstream::commsTypes::nonBlocking) const
Inplace collect in processor order on master (== procIDs[0]).
Definition: globalIndex.H:499
void setLocalSize(const label proci, const label len)
Alter local size for given processor.
Definition: globalIndex.C:274
void mpiGather(const UList< Type > &sendData, OutputContainer &allData, const label comm=UPstream::worldComm, const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const int tag=UPstream::msgType()) const
Use MPI_Gatherv call for contiguous data when possible (in serial: performs a simple copy).
static void mpiGatherOp(const UList< Type > &sendData, OutputContainer &allData, const label comm=UPstream::worldComm, const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const int tag=UPstream::msgType())
Use MPI_Gatherv call to collect contiguous data when possible (in serial: performs a simple copy).
label totalSize() const
Global sum of localSizes.
Definition: globalIndexI.H:125
FOAM_DEPRECATED_FOR(2022-03, "reset without message tag") void reset(const label localSize
Reset from local size, using gather/broadcast with default/specified communicator if parallel.
labelList sizes() const
The local sizes. Same as localSizes()
Definition: globalIndexI.H:138
const int const label const bool parallel
Definition: globalIndex.H:859
static void gatherOp(const UList< Type > &sendData, List< Type > &allData, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const label comm=UPstream::worldComm)
Collect data in processor order on master (in serial: performs a simple copy).
labelList localSizes() const
The local sizes.
Definition: globalIndex.C:292
labelRange allProcs() const noexcept
Range of process indices for all addressed offsets (processes)
Definition: globalIndexI.H:151
void scatter(const label comm, const ProcIDsContainer &procIDs, const UList< Type > &allFld, UList< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes ct=UPstream::commsTypes::nonBlocking) const
Distribute data in processor order.
Definition: globalIndex.H:784
label toLocal(const label i) const
From global to local on current processor.
Definition: globalIndexI.H:325
friend Istream & operator>>(Istream &is, globalIndex &gi)
static void gatherValues(const label comm, const ProcIDsContainer &procIDs, const Type &localValue, List< Type > &allValues, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Which processor does global id come from?
void mpiGatherInplace(List< Type > &fld, const label comm=UPstream::worldComm, const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const int tag=UPstream::msgType()) const
Use MPI_Gatherv call to inplace collect contiguous data when possible. (in serial: a no-op).
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:244
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
int myProcNo() const noexcept
Return processor number.
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:223
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52