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 protected:
71 
72  // Protected Data
73 
74  //- Any communicator allocated by me
75  const label myComm_;
76 
77  //- Threaded writer
78  mutable OFstreamCollator writer_;
79 
80  // For non-parallel operation
81 
82  //- Number of processors (overall)
83  label nProcs_;
84 
85  //- Ranks of IO handlers
86  const labelList ioRanks_;
87 
88 
89  // Protected Member Functions
90 
91  //- Print banner information, optionally with io ranks
92  void printBanner(const bool printRanks = false) const;
93 
94  //- Is proci master of communicator (in parallel) or master of
95  //- the io ranks (non-parallel)
96  bool isMasterRank(const label proci) const;
97 
98  //- Append to processorsNN/ file
99  bool appendObject
100  (
101  const regIOobject& io,
102  const fileName& pathName,
103  IOstreamOption streamOpt
104  ) const;
105 
106 
107 public:
108 
109  //- Runtime type information
110  TypeName("collated");
111 
112 
113  // Static Data
114 
115  //- Max size of thread buffer size. This is the overall size of
116  // all files to be written. Starts blocking if not enough size.
117  // Read as float to enable easy specification of large sizes.
118  static float maxThreadFileBufferSize;
119 
120 
121  // Constructors
122 
123  //- Default construct
124  explicit collatedFileOperation(bool verbose);
125 
126  //- Construct from user communicator
128  (
129  const label comm,
130  const labelList& ioRanks,
131  const word& typeName,
132  bool verbose
133  );
134 
135 
136  //- Destructor
137  virtual ~collatedFileOperation();
138 
139 
140  // Member Functions
141 
142  // (reg)IOobject functionality
143 
144  //- Generate disk file name for object. Opposite of filePath.
145  virtual fileName objectPath
146  (
147  const IOobject& io,
148  const word& typeName
149  ) const;
150 
151  //- Writes a regIOobject (so header, contents and divider).
152  // Returns success state.
153  virtual bool writeObject
154  (
155  const regIOobject&,
156  IOstreamOption streamOpt = IOstreamOption(),
157  const bool valid = true
158  ) const;
159 
160  // Other
161 
162  //- Forcibly wait until all output done. Flush any cached data
163  virtual void flush() const;
164 
165  //- Actual name of processors dir
166  virtual word processorsDir(const IOobject&) const;
167 
168  //- Actual name of processors dir
169  virtual word processorsDir(const fileName&) const;
170 
171  //- Set number of processor directories/results.
172  //- Only used in decomposePar
173  virtual void setNProcs(const label nProcs);
174 };
175 
176 
177 /*---------------------------------------------------------------------------*\
178  Class collatedFileOperationInitialise Declaration
179 \*---------------------------------------------------------------------------*/
180 
182 :
184 {
185 public:
186 
187  // Constructors
188 
189  //- Construct from components
190  collatedFileOperationInitialise(int& argc, char**& argv)
191  :
193  {}
194 
195 
196  //- Destructor
197  virtual ~collatedFileOperationInitialise() = default;
198 
199 
200  // Member Functions
201 
202  //- Requires threading for non-zero maxThreadFileBufferSize
203  virtual bool needsThreading() const
204  {
206  }
207 };
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 } // End namespace fileOperations
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #endif
218 
219 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::fileOperations::collatedFileOperation::maxThreadFileBufferSize
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
Definition: collatedFileOperation.H:117
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileOperations::collatedFileOperation::~collatedFileOperation
virtual ~collatedFileOperation()
Destructor.
Definition: collatedFileOperation.C:311
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileOperations::collatedFileOperation::processorsDir
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
Definition: collatedFileOperation.C:597
Foam::fileOperations::collatedFileOperation::writer_
OFstreamCollator writer_
Threaded writer.
Definition: collatedFileOperation.H:77
Foam::fileOperations::collatedFileOperationInitialise::collatedFileOperationInitialise
collatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
Definition: collatedFileOperation.H:189
Foam::fileOperations::collatedFileOperationInitialise::~collatedFileOperationInitialise
virtual ~collatedFileOperationInitialise()=default
Destructor.
Foam::fileOperations::collatedFileOperation::ioRanks_
const labelList ioRanks_
Ranks of IO handlers.
Definition: collatedFileOperation.H:85
Foam::fileOperations::collatedFileOperation::objectPath
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
Definition: collatedFileOperation.C:326
Foam::fileOperations::collatedFileOperation::appendObject
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
Definition: collatedFileOperation.C:188
Foam::fileOperation::nProcs
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
Definition: fileOperation.C:1193
Foam::fileOperations::collatedFileOperation::setNProcs
virtual void setNProcs(const label nProcs)
Definition: collatedFileOperation.C:605
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::fileOperations::collatedFileOperation::isMasterRank
bool isMasterRank(const label proci) const
Definition: collatedFileOperation.C:165
Foam::fileOperations::collatedFileOperation::writeObject
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
Definition: collatedFileOperation.C:356
Foam::fileOperations::collatedFileOperation
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
Definition: collatedFileOperation.H:65
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstreamCollator
Threaded file writer.
Definition: OFstreamCollator.H:70
Foam::fileOperations::collatedFileOperation::nProcs_
label nProcs_
Number of processors (overall)
Definition: collatedFileOperation.H:82
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::fileOperations::masterUncollatedFileOperation
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Definition: masterUncollatedFileOperation.H:84
masterUncollatedFileOperation.H
Foam::fileOperations::collatedFileOperationInitialise
Definition: collatedFileOperation.H:180
Foam::fileOperations::collatedFileOperation::printBanner
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
Definition: collatedFileOperation.C:80
Foam::List< label >
Foam::fileOperation::ioRanks
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
Definition: fileOperation.C:222
Foam::fileOperations::collatedFileOperationInitialise::needsThreading
virtual bool needsThreading() const
Requires threading for non-zero maxThreadFileBufferSize.
Definition: collatedFileOperation.H:202
Foam::fileOperations::masterUncollatedFileOperationInitialise
Definition: masterUncollatedFileOperation.H:776
Foam::fileOperations::collatedFileOperation::collatedFileOperation
collatedFileOperation(bool verbose)
Default construct.
Definition: collatedFileOperation.C:259
Foam::fileOperations::collatedFileOperation::myComm_
const label myComm_
Any communicator allocated by me.
Definition: collatedFileOperation.H:74
Foam::fileOperations::collatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: collatedFileOperation.C:519
OFstreamCollator.H
Foam::fileOperations::collatedFileOperation::TypeName
TypeName("collated")
Runtime type information.