decomposedBlockData.H
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) 2017-2026 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 Class
25  Foam::decomposedBlockData
26 
27 Description
28  decomposedBlockData is a List<char> with IO on the master processor only.
29 
30 SourceFiles
31  decomposedBlockData.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef decomposedBlockData_H
36 #define decomposedBlockData_H
37 
38 #include "IOList.H"
39 #include "regIOobject.H"
40 #include "UPstream.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class decomposedBlockData Declaration
49 \*---------------------------------------------------------------------------*/
50 
52 :
53  public regIOobject,
54  public List<char>
55 {
56 protected:
57 
58  // Protected data
59 
60  //- Type to use for gather
62 
63  //- Communicator for all parallel comms
64  const label comm_;
65 
66 
67  // Protected Member Functions
68 
69  //- Helper: determine number of processors whose recvSizes fits
70  // ito maxBufferSize
71  static label calcNumProcs
72  (
73  const label comm,
74  const off_t maxBufferSize,
75  const labelUList& recvSizes,
76  const label startProci
77  );
78 
79  //- Read data into *this. ISstream is only valid on master.
80  static bool readBlocks
81  (
82  const label comm,
83  autoPtr<ISstream>& isPtr,
85  const UPstream::commsTypes commsType
86  );
87 
88 
89 public:
90 
91  TypeName("decomposedBlockData");
92 
93 
94  // Constructors
95 
96  //- Construct given an IOobject
98  (
99  const label comm,
100  const IOobject&,
102  );
103 
104  //- Construct given an IOobject and for READ_IF_MODIFIED a List<char>
106  (
107  const label comm,
108  const IOobject&,
109  const UList<char>&,
111  );
112 
113  //- Move construct by transferring the IOList contents
115  (
116  const label comm,
117  const IOobject&,
118  List<char>&&,
120  );
121 
122 
123  //- Destructor
124  virtual ~decomposedBlockData();
125 
126 
127  // Member Functions
128 
129  //- Read object
130  virtual bool read();
131 
132  //- Write separated content. Assumes content is the serialised data
133  // and that the master data contains a header
134  virtual bool writeData(Ostream&) const;
135 
136  //- Write using given format, version and compression
137  virtual bool writeObject
138  (
142  const bool write
143  ) const;
144 
145 
146  // Helpers
147 
148  //- Read header. Call only on master.
149  static bool readMasterHeader(IOobject&, Istream&);
150 
151  //- Read selected block (non-seeking) + header information
153  (
154  const label blocki,
155  Istream& is,
156  IOobject& headerIO
157  );
158 
159  //- Read master header information (into headerIO) and return
160  // data in stream. Note: isPtr is only valid on master.
162  (
163  const label comm,
164  const fileName& fName,
165  autoPtr<ISstream>& isPtr,
166  IOobject& headerIO,
167  const UPstream::commsTypes commsType
168  );
169 
170  //- Helper: gather single label. Note: using native Pstream.
171  // datas sized with num procs but undefined contents on
172  // slaves
173  static void gather
174  (
175  const label comm,
176  const label data,
177  labelList& datas
178  );
179 
180  //- Helper: gather data from (subset of) slaves. Returns
181  // recvData : received data
182  // recvOffsets : offset in data. recvOffsets is nProcs+1
183  static void gatherSlaveData
184  (
185  const label comm,
186  const UList<char>& data,
187  const labelUList& recvSizes,
188 
189  const label startProc,
190  const label nProcs,
191 
192  List<int>& recvOffsets,
193  List<char>& recvData
194  );
195 
196  //- Write *this. Ostream only valid on master. Returns starts of
197  // processor blocks
198  static bool writeBlocks
199  (
200  const label comm,
201  autoPtr<OSstream>& osPtr,
202  List<std::streamoff>& start,
203  const UList<char>& masterData,
204 
205  const labelUList& recvSizes,
206 
207  // optional slave data (on master)
208  const PtrList<SubList<char>>& slaveData,
209 
210  const UPstream::commsTypes,
211  const bool syncReturnState = true
212  );
213 
214  //- Detect number of blocks in a file
215  static label numBlocks(const fileName&);
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace Foam
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 #endif
226 
227 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
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:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A List obtained as a section of another List.
Definition: SubList.H:56
T * data()
Return a pointer to the first data element,.
Definition: UListI.H:149
commsTypes
Types of communications.
Definition: UPstream.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
decomposedBlockData is a List<char> with IO on the master processor only.
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &start, const UList< char > &masterData, const labelUList &recvSizes, const PtrList< SubList< char >> &slaveData, const UPstream::commsTypes, const bool syncReturnState=true)
Write *this. Ostream only valid on master. Returns starts of.
static void gatherSlaveData(const label comm, const UList< char > &data, const labelUList &recvSizes, const label startProc, const label nProcs, List< int > &recvOffsets, List< char > &recvData)
Helper: gather data from (subset of) slaves. Returns.
virtual bool writeData(Ostream &) const
Write separated content. Assumes content is the serialised data.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
TypeName("decomposedBlockData")
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
const label comm_
Communicator for all parallel comms.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
static label numBlocks(const fileName &)
Detect number of blocks in a file.
decomposedBlockData(const label comm, const IOobject &, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &data, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits.
virtual bool read()
Read object.
const UPstream::commsTypes commsType_
Type to use for gather.
virtual ~decomposedBlockData()
Destructor.
A class for handling file names.
Definition: fileName.H:82
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
virtual bool write(const bool write=true) const
Write using setting from DB.
Namespace for OpenFOAM.
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