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-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 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  //- Construct by transferring the IOList contents
115  (
116  const label comm,
117  const IOobject&,
118  const Xfer<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 valid
143  ) const;
144 
145 
146  // Helpers
147 
148  //- Read header. Call only on master.
149  static bool readMasterHeader(IOobject&, Istream&);
150 
151  //- Helper: write FoamFile IOobject header
152  static void writeHeader
153  (
154  Ostream& os,
155  const IOstream::versionNumber version,
157  const word& type,
158  const string& note,
159  const fileName& location,
160  const word& name
161  );
162 
163  //- Read selected block (non-seeking) + header information
165  (
166  const label blocki,
167  Istream& is,
168  IOobject& headerIO
169  );
170 
171  //- Read master header information (into headerIO) and return
172  // data in stream. Note: isPtr is only valid on master.
174  (
175  const label comm,
176  const fileName& fName,
177  autoPtr<ISstream>& isPtr,
178  IOobject& headerIO,
179  const UPstream::commsTypes commsType
180  );
181 
182  //- Helper: gather single label. Note: using native Pstream.
183  // datas sized with num procs but undefined contents on
184  // slaves
185  static void gather
186  (
187  const label comm,
188  const label data,
189  labelList& datas
190  );
191 
192  //- Helper: gather data from (subset of) slaves. Returns
193  // recvData : received data
194  // recvOffsets : offset in data. recvOffsets is nProcs+1
195  static void gatherSlaveData
196  (
197  const label comm,
198  const UList<char>& data,
199  const labelUList& recvSizes,
200 
201  const label startProc,
202  const label nProcs,
203 
204  List<int>& recvOffsets,
205  List<char>& recvData
206  );
207 
208  //- Write *this. Ostream only valid on master. Returns starts of
209  // processor blocks
210  static bool writeBlocks
211  (
212  const label comm,
213  autoPtr<OSstream>& osPtr,
214  List<std::streamoff>& start,
215  const UList<char>& masterData,
216 
217  const labelUList& recvSizes,
218 
219  // optional slave data (on master)
220  const PtrList<SubList<char>>& slaveData,
221 
222  const UPstream::commsTypes,
223  const bool syncReturnState = true
224  );
225 
226  //- Detect number of blocks in a file
227  static label numBlocks(const fileName&);
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #endif
238 
239 // ************************************************************************* //
decomposedBlockData(const label comm, const IOobject &, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
virtual ~decomposedBlockData()
Destructor.
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.
virtual bool read()
Read object.
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
const word & name() const
Return name.
Definition: IOobject.H:297
A class for handling file names.
Definition: fileName.H:69
virtual bool writeData(Ostream &) const
Write separated content. Assumes content is the serialised data.
const label comm_
Communicator for all parallel comms.
const UPstream::commsTypes commsType_
Type to use for gather.
commsTypes
Types of communications.
Definition: UPstream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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 label numBlocks(const fileName &)
Detect number of blocks in a file.
word format(conversionProperties.lookup("format"))
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:315
A List obtained as a section of another List.
Definition: SubList.H:53
A class for handling words, derived from string.
Definition: word.H:59
static void writeHeader(Ostream &os, const IOstream::versionNumber version, const IOstream::streamFormat format, const word &type, const string &note, const fileName &location, const word &name)
Helper: write FoamFile IOobject header.
decomposedBlockData is a List<char> with IO on the master processor only.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
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.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write using given format, version and compression.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
TypeName("decomposedBlockData")
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.