collatedFileOperation.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 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fileOperations::collatedFileOperation
29 
30 Description
31  Version of masterUncollatedFileOperation that collates regIOobjects
32  into a container in the processors/ subdirectory.
33 
34  Uses threading if maxThreadFileBufferSize != 0.
35  > 0 : Can use mpi inside thread to collect data if buffer is not
36  large enough. Does need full thread support inside MPI.
37 
38  < 0 : special : -maxThreadFileBufferSize is guaranteed large enough
39  for all writing. Initialises MPI without thread support.
40 
41 See also
42  masterUncollatedFileOperation
43 
44 SourceFiles
45  collatedFileOperation.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef fileOperations_collatedFileOperation_H
50 #define fileOperations_collatedFileOperation_H
51 
53 #include "OFstreamCollator.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace fileOperations
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class collatedFileOperation Declaration
64 \*---------------------------------------------------------------------------*/
65 
67 :
69 {
70  // Private Data
71 
72  //- Communicator allocated/managed by us
73  label managedComm_;
74 
75 
76  // Private Member Functions
77 
78  //- Any initialisation steps after constructing
79  void init(bool verbose);
80 
81 protected:
82 
83  // Protected Data
84 
85  //- Threaded writer
86  mutable OFstreamCollator writer_;
87 
88  // For non-parallel operation
89 
90  //- Number of processors (overall)
91  label nProcs_;
92 
93  //- Ranks of IO handlers
95 
96 
97  // Protected Member Functions
98 
99  //- Print banner information, optionally with io ranks
100  void printBanner(const bool printRanks = false) const;
101 
102  //- Is proci master of communicator (in parallel) or master of
103  //- the io ranks (non-parallel)
104  bool isMasterRank(const label proci) const;
105 
106  //- Append to processorsNN/ file
107  bool appendObject
108  (
109  const regIOobject& io,
110  const fileName& pathName,
111  IOstreamOption streamOpt
112  ) const;
113 
114 
115 public:
116 
117  //- Runtime type information
118  TypeName("collated");
119 
120 
121  // Static Data
122 
123  //- Max size of thread buffer size. This is the overall size of
124  // all files to be written. Starts blocking if not enough size.
125  // Read as float to enable easy specification of large sizes.
126  static float maxThreadFileBufferSize;
127 
128 
129  // Constructors
130 
131  //- Default construct
132  explicit collatedFileOperation(bool verbose);
133 
134  //- Construct from user communicator
136  (
137  const label comm,
138  const labelList& ioRanks,
139  const word& typeName,
140  bool verbose
141  );
143 
144  //- Destructor
145  virtual ~collatedFileOperation();
146 
147 
148  // Member Functions
149 
150  // (reg)IOobject functionality
151 
152  //- Generate disk file name for object. Opposite of filePath.
153  virtual fileName objectPath
154  (
155  const IOobject& io,
156  const word& typeName
157  ) const;
158 
159  //- Writes a regIOobject (so header, contents and divider).
160  // Returns success state.
161  virtual bool writeObject
162  (
163  const regIOobject&,
164  IOstreamOption streamOpt = IOstreamOption(),
165  const bool valid = true
166  ) const;
167 
168  // Other
169 
170  //- Forcibly wait until all output done. Flush any cached data
171  virtual void flush() const;
172 
173  //- Actual name of processors dir
174  virtual word processorsDir(const IOobject&) const;
175 
176  //- Actual name of processors dir
177  virtual word processorsDir(const fileName&) const;
178 
179  //- Set number of processor directories/results.
180  //- Only used in decomposePar
181  virtual void setNProcs(const label nProcs);
182 };
183 
184 
185 /*---------------------------------------------------------------------------*\
186  Class collatedFileOperationInitialise Declaration
187 \*---------------------------------------------------------------------------*/
188 
190 :
192 {
193 public:
194 
195  // Constructors
196 
197  //- Construct from components
198  collatedFileOperationInitialise(int& argc, char**& argv)
199  :
201  {}
202 
203 
204  //- Destructor
205  virtual ~collatedFileOperationInitialise() = default;
206 
207 
208  // Member Functions
209 
210  //- Requires threading for non-zero maxThreadFileBufferSize
211  virtual bool needsThreading() const
212  {
214  }
215 };
216 
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 } // End namespace fileOperations
221 } // End namespace Foam
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 #endif
226 
227 // ************************************************************************* //
Threaded file writer.
const labelList ioRanks_
Ranks of IO handlers.
A class for handling file names.
Definition: fileName.H:71
TypeName("collated")
Runtime type information.
OFstreamCollator writer_
Threaded writer.
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
collatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
virtual ~collatedFileOperationInitialise()=default
Destructor.
collatedFileOperation(bool verbose)
Default construct.
A simple container for options an IOstream can normally have.
virtual bool needsThreading() const
Requires threading for non-zero maxThreadFileBufferSize.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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 Foam::string.
Definition: word.H:63
bool isMasterRank(const label proci) const
Is proci master of communicator (in parallel) or master of the io ranks (non-parallel) ...
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
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 decomposePar.
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
label nProcs_
Number of processors (overall)
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
Namespace for OpenFOAM.