collatedFileOperation.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-2020 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::fileOperations::collatedFileOperation
26 
27 Description
28  Version of masterUncollatedFileOperation that collates regIOobjects
29  into a container in the processors/ subdirectory.
30 
31  Uses threading if maxThreadFileBufferSize > 0.
32 
33 See also
34  masterUncollatedFileOperation
35 
36 SourceFiles
37  collatedFileOperation.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef fileOperations_collatedFileOperation_H
42 #define fileOperations_collatedFileOperation_H
43 
45 #include "OFstreamCollator.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 namespace fileOperations
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class collatedFileOperation Declaration
56 \*---------------------------------------------------------------------------*/
57 
59 :
61 {
62 protected:
63 
64  // Protected data
65 
66  //- Any communicator allocated by me
67  const label myComm_;
68 
69  //- Threaded writer
70  mutable OFstreamCollator writer_;
71 
72  // For non-parallel operation
73 
74  //- Number of processors (overall)
75  label nProcs_;
76 
77  //- Ranks of IO handlers
78  const labelList ioRanks_;
79 
80 
81  // Private Member Functions
82 
83  static labelList ioRanks();
84 
85  //- Is proci master of communicator (in parallel) or master of
86  // the io ranks (non-parallel)
87  bool isMasterRank(const label proci) const;
88 
89  //- Append to processors/ file
90  bool appendObject
91  (
92  const regIOobject& io,
93  const fileName& filePath,
97  ) const;
98 
99 
100 public:
101 
102  //- Runtime type information
103  TypeName("collated");
104 
105 
106  // Static data
107 
108  //- Max size of thread buffer size. This is the overall size of
109  // all files to be written. Starts blocking if not enough size.
110  // Read as float to enable easy specification of large sizes.
111  static float maxThreadFileBufferSize;
112 
113 
114  // Constructors
115 
116  //- Construct null
117  collatedFileOperation(const bool verbose);
118 
119  //- Construct from user communicator
121  (
122  const label comm,
123  const labelList& ioRanks,
124  const word& typeName,
125  const bool verbose
126  );
127 
128 
129  //- Destructor
130  virtual ~collatedFileOperation();
131 
132 
133  // Member Functions
134 
135  // (reg)IOobject functionality
136 
137  //- Generate disk file name for object. Opposite of filePath.
138  virtual fileName objectPath
139  (
140  const IOobject& io,
141  const word& typeName
142  ) const;
143 
144  //- Writes a regIOobject (so header, contents and divider).
145  // Returns success state.
146  virtual bool writeObject
147  (
148  const regIOobject&,
152  const bool write = true
153  ) const;
154 
155  // Other
156 
157  //- Forcibly wait until all output done. Flush any cached data
158  virtual void flush() const;
159 
160  //- Actual name of processors dir
161  virtual word processorsDir(const IOobject&) const;
162 
163  //- Actual name of processors dir
164  virtual word processorsDir(const fileName&) const;
165 
166  //- Set number of processor directories/results. Only used in
167  // decomposePar
168  virtual void setNProcs(const label nProcs);
169 };
170 
171 
172 /*---------------------------------------------------------------------------*\
173  Class collatedFileOperationInitialise Declaration
174 \*---------------------------------------------------------------------------*/
177 :
179 {
180 public:
181 
182  // Constructors
183 
184  //- Construct from components
185  collatedFileOperationInitialise(int& argc, char**& argv)
186  :
188  {}
189 
190 
191  //- Destructor
193  {}
194 
195 
196  // Member Functions
197 
198  //- Needs threading
199  virtual bool needsThreading() const
200  {
201  return
203  > 0;
204  }
205 };
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace fileOperations
211 } // End namespace Foam
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #endif
216 
217 // ************************************************************************* //
Threaded file writer.
const labelList ioRanks_
Ranks of IO handlers.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
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
A class for handling file names.
Definition: fileName.H:79
TypeName("collated")
Runtime type information.
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool write=true) const
Writes a regIOobject (so header, contents and divider).
OFstreamCollator writer_
Threaded writer.
collatedFileOperation(const bool verbose)
Construct null.
word format(conversionProperties.lookup("format"))
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
A class for handling words, derived from string.
Definition: word.H:59
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
bool isMasterRank(const label proci) const
Is proci master of communicator (in parallel) or master of.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName) const
Search for an object. checkGlobal : also check undecomposed case.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
const label myComm_
Any communicator allocated by me.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
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:52
label nProcs_
Number of processors (overall)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
bool appendObject(const regIOobject &io, const fileName &filePath, IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Append to processors/ file.
Namespace for OpenFOAM.