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-2019 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"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 namespace fileOperations
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class collatedFileOperation Declaration
57 \*---------------------------------------------------------------------------*/
58 
60 :
62 {
63 protected:
64 
65  // Protected data
66 
67  //- Any communicator allocated by me
68  const label myComm_;
69 
70  //- Threaded writer
71  mutable OFstreamCollator writer_;
72 
73  // For non-parallel operation
74 
75  //- Number of processors (overall)
76  label nProcs_;
77 
78  //- Ranks of IO handlers
79  const labelList ioRanks_;
80 
81 
82  // Private Member Functions
83 
84  static labelList ioRanks();
85 
86  //- Is proci master of communicator (in parallel) or master of
87  // the io ranks (non-parallel)
88  bool isMasterRank(const label proci) const;
89 
90  //- Append to processors/ file
91  bool appendObject
92  (
93  const regIOobject& io,
94  const fileName& pathName,
98  ) const;
99 
100 
101 public:
102 
103  //- Runtime type information
104  TypeName("collated");
105 
106 
107  // Static data
108 
109  //- Max size of thread buffer size. This is the overall size of
110  // all files to be written. Starts blocking if not enough size.
111  // Read as float to enable easy specification of large sizes.
112  static float maxThreadFileBufferSize;
113 
114 
115  // Constructors
116 
117  //- Construct null
118  collatedFileOperation(const bool verbose);
119 
120  //- Construct from user communicator
122  (
123  const label comm,
124  const labelList& ioRanks,
125  const word& typeName,
126  const bool verbose
127  );
128 
129 
130  //- Destructor
131  virtual ~collatedFileOperation();
132 
133 
134  // Member Functions
135 
136  // (reg)IOobject functionality
137 
138  //- Generate disk file name for object. Opposite of filePath.
139  virtual fileName objectPath
140  (
141  const IOobject& io,
142  const word& typeName
143  ) const;
144 
145  //- Writes a regIOobject (so header, contents and divider).
146  // Returns success state.
147  virtual bool writeObject
148  (
149  const regIOobject&,
153  const bool write = true
154  ) const;
155 
156  // Other
157 
158  //- Forcibly wait until all output done. Flush any cached data
159  virtual void flush() const;
160 
161  //- Actual name of processors dir
162  virtual word processorsDir(const IOobject&) const;
163 
164  //- Actual name of processors dir
165  virtual word processorsDir(const fileName&) const;
166 
167  //- Set number of processor directories/results. Only used in
168  // decomposePar
169  virtual void setNProcs(const label nProcs);
170 };
171 
172 
173 /*---------------------------------------------------------------------------*\
174  Class collatedFileOperationInitialise Declaration
175 \*---------------------------------------------------------------------------*/
178 :
180 {
181 public:
182 
183  // Constructors
184 
185  //- Construct from components
186  collatedFileOperationInitialise(int& argc, char**& argv)
187  :
189  {}
190 
191 
192  //- Destructor
194  {}
195 
196 
197  // Member Functions
198 
199  //- Needs threading
200  virtual bool needsThreading() const
201  {
202  return
204  > 0;
205  }
206 };
207 
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace fileOperations
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
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"))
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
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
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
bool appendObject(const regIOobject &io, const fileName &pathName, IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Append to processors/ file.
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:206
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:55
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.
Namespace for OpenFOAM.