decomposedBlockData.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) 2017-2018 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::decomposedBlockData
28 
29 Description
30  decomposedBlockData is a List<char> with IO on the master processor only.
31 
32 SourceFiles
33  decomposedBlockData.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef decomposedBlockData_H
38 #define decomposedBlockData_H
39 
40 #include "IOList.H"
41 #include "regIOobject.H"
42 #include "UPstream.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class decomposedBlockData Declaration
51 \*---------------------------------------------------------------------------*/
52 
54 :
55  public regIOobject,
56  public List<char>
57 {
58 protected:
59 
60  // Protected data
61 
62  //- Type to use for gather
64 
65  //- Communicator for all parallel comms
66  const label comm_;
67 
68 
69  // Protected member functions
70 
71  //- Helper: determine number of processors whose recvSizes fits
72  // ito maxBufferSize
73  static label calcNumProcs
74  (
75  const label comm,
76  const off_t maxBufferSize,
77  const labelUList& recvSizes,
78  const label startProci
79  );
80 
81  //- Read data into *this. ISstream is only valid on master.
82  static bool readBlocks
83  (
84  const label comm,
85  autoPtr<ISstream>& isPtr,
87  const UPstream::commsTypes commsType
88  );
89 
90 
91 public:
92 
93  TypeName("decomposedBlockData");
94 
95 
96  // Constructors
97 
98  //- Construct given an IOobject
100  (
101  const label comm,
102  const IOobject& io,
104  );
105 
106  //- Construct given an IOobject and for READ_IF_MODIFIED a List<char>
108  (
109  const label comm,
110  const IOobject& io,
111  const UList<char>& list,
113  );
114 
115  //- Construct by transferring the List contents
117  (
118  const label comm,
119  const IOobject& io,
120  List<char>&& list,
122  );
123 
124 
125  //- Destructor
126  virtual ~decomposedBlockData();
127 
128 
129  // Member functions
130 
131  //- Read object
132  virtual bool read();
133 
134  //- Write separated content. Assumes content is the serialised data
135  // and that the master data contains a header
136  virtual bool writeData(Ostream&) const;
137 
138  //- Write using given format, version and compression
139  virtual bool writeObject
140  (
144  const bool valid
145  ) const;
146 
147 
148  // Helpers
149 
150  //- Read header. Call only on master.
151  static bool readMasterHeader(IOobject&, Istream&);
152 
153  //- Helper: write FoamFile IOobject header
154  static void writeHeader
155  (
156  Ostream& os,
159  const word& type,
160  const string& note,
161  const fileName& location,
162  const word& name
163  );
164 
165  //- Read selected block (non-seeking) + header information
167  (
168  const label blocki,
169  Istream& is,
170  IOobject& headerIO
171  );
172 
173  //- Read master header information (into headerIO) and return
174  // data in stream. Note: isPtr is only valid on master.
176  (
177  const label comm,
178  const fileName& fName,
179  autoPtr<ISstream>& isPtr,
180  IOobject& headerIO,
181  const UPstream::commsTypes commsType
182  );
183 
184  //- Helper: gather single label. Note: using native Pstream.
185  // datas sized with num procs but undefined contents on
186  // slaves
187  static void gather
188  (
189  const label comm,
190  const label data,
191  labelList& datas
192  );
193 
194  //- Helper: gather data from (subset of) slaves. Returns
195  // recvData : received data
196  // recvOffsets : offset in data. recvOffsets is nProcs+1
197  static void gatherSlaveData
198  (
199  const label comm,
200  const UList<char>& data,
201  const labelUList& recvSizes,
202 
203  const label startProc,
204  const label nProcs,
205 
206  List<int>& recvOffsets,
207  List<char>& recvData
208  );
209 
210  //- Write *this. Ostream only valid on master. Returns starts of
211  // processor blocks
212  static bool writeBlocks
213  (
214  const label comm,
215  autoPtr<OSstream>& osPtr,
217  const UList<char>& masterData,
218 
219  const labelUList& recvSizes,
220 
221  // optional slave data (on master)
222  const PtrList<SubList<char>>& slaveData,
223 
224  const UPstream::commsTypes,
225  const bool syncReturnState = true
226  );
227 
228  //- Detect number of blocks in a file
229  static label numBlocks(const fileName&);
230 };
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace Foam
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
regIOobject.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::decomposedBlockData::comm_
const label comm_
Communicator for all parallel comms.
Definition: decomposedBlockData.H:65
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
UPstream.H
Foam::decomposedBlockData::readBlock
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
Definition: decomposedBlockData.C:243
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::decomposedBlockData::calcNumProcs
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits.
Definition: decomposedBlockData.C:766
Foam::decomposedBlockData::writeBlocks
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.
Definition: decomposedBlockData.C:806
Foam::decomposedBlockData::~decomposedBlockData
virtual ~decomposedBlockData()
Destructor.
Definition: decomposedBlockData.C:164
IOList.H
format
word format(conversionProperties.get< word >("format"))
Foam::label
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:62
Foam::decomposedBlockData::readMasterHeader
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
Definition: decomposedBlockData.C:170
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::decomposedBlockData::writeHeader
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.
Definition: decomposedBlockData.C:196
Foam::decomposedBlockData::TypeName
TypeName("decomposedBlockData")
Foam::decomposedBlockData::gather
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
Definition: decomposedBlockData.C:667
Foam::decomposedBlockData::gatherSlaveData
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.
Definition: decomposedBlockData.C:706
Foam::decomposedBlockData::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write using given format, version and compression.
Definition: decomposedBlockData.C:1109
Foam::decomposedBlockData::commsType_
const UPstream::commsTypes commsType_
Type to use for gather.
Definition: decomposedBlockData.H:62
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::UPstream::commsTypes::scheduled
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::decomposedBlockData::decomposedBlockData
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
Definition: decomposedBlockData.C:51
Foam::decomposedBlockData::writeData
virtual bool writeData(Ostream &) const
Write separated content. Assumes content is the serialised data.
Definition: decomposedBlockData.C:1033
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decomposedBlockData
decomposedBlockData is a List<char> with IO on the master processor only.
Definition: decomposedBlockData.H:52
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Foam::IOobject::note
const string & note() const
Return the optional note.
Definition: IOobjectI.H:76
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:66
Foam::decomposedBlockData::readBlocks
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.
Definition: decomposedBlockData.C:339
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::UList< label >
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
Foam::decomposedBlockData::read
virtual bool read()
Read object.
Definition: decomposedBlockData.C:1018
Foam::decomposedBlockData::numBlocks
static label numBlocks(const fileName &)
Detect number of blocks in a file.
Definition: decomposedBlockData.C:1143