globalIndex.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "globalIndex.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  const label localSize,
33  const int tag,
34  const label comm,
35  const bool parallel
36 )
37 :
38  offsets_(Pstream::nProcs(comm)+1)
39 {
40  labelList localSizes(Pstream::nProcs(comm), 0);
41  localSizes[Pstream::myProcNo(comm)] = localSize;
42  if (parallel)
43  {
44  Pstream::gatherList(localSizes, tag, comm);
45  Pstream::scatterList(localSizes, tag, comm);
46  }
47 
48  label offset = 0;
49  offsets_[0] = 0;
50  for (label proci = 0; proci < Pstream::nProcs(comm); proci++)
51  {
52  label oldOffset = offset;
53  offset += localSizes[proci];
54 
55  if (offset < oldOffset)
56  {
58  << "Overflow : sum of sizes " << localSizes
59  << " exceeds capability of label (" << labelMax
60  << "). Please recompile with larger datatype for label."
61  << exit(FatalError);
62  }
63  offsets_[proci+1] = offset;
64  }
65 }
66 
67 
69 :
70  offsets_(Pstream::nProcs()+1)
71 {
72  labelList localSizes(Pstream::nProcs(), 0);
73  localSizes[Pstream::myProcNo()] = localSize;
76 
77  label offset = 0;
78  offsets_[0] = 0;
79  for (label proci = 0; proci < Pstream::nProcs(); proci++)
80  {
81  label oldOffset = offset;
82  offset += localSizes[proci];
83 
84  if (offset < oldOffset)
85  {
87  << "Overflow : sum of sizes " << localSizes
88  << " exceeds capability of label (" << labelMax
89  << "). Please recompile with larger datatype for label."
90  << exit(FatalError);
91  }
92  offsets_[proci+1] = offset;
93  }
94 }
95 
96 
98 :
99  offsets_(offsets)
100 {}
101 
102 
104 {
105  is >> offsets_;
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
110 
112 {
113  return is >> gi.offsets_;
114 }
115 
116 
118 {
119  return os << gi.offsets_;
120 }
121 
122 
123 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Inter-processor communications stream.
Definition: Pstream.H:56
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
label localSize() const
My local size.
Definition: globalIndexI.H:60
globalIndex()
Construct null.
Definition: globalIndexI.H:30
label offset(const label proci) const
Start of proci data.
Definition: globalIndexI.H:48
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
error FatalError
static const label labelMax
Definition: label.H:62