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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::fileOperations::collatedFileOperation
29
30Description
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
41See also
42 masterUncollatedFileOperation
43
44SourceFiles
45 collatedFileOperation.C
46
47\*---------------------------------------------------------------------------*/
48
49#ifndef fileOperations_collatedFileOperation_H
50#define fileOperations_collatedFileOperation_H
51
53#include "OFstreamCollator.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
59namespace fileOperations
60{
61
62/*---------------------------------------------------------------------------*\
63 Class collatedFileOperation Declaration
64\*---------------------------------------------------------------------------*/
67:
69{
70protected:
71
72 // Protected Data
73
74 //- Any communicator allocated by me
75 const label myComm_;
76
77 //- Threaded 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
107public:
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\*---------------------------------------------------------------------------*/
182:
184{
185public:
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// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is a simple container for options an IOstream can normally have.
Threaded file writer.
A class for handling file names.
Definition: fileName.H:76
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
virtual ~collatedFileOperationInitialise()=default
Destructor.
virtual bool needsThreading() const
Requires threading for non-zero maxThreadFileBufferSize.
collatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
virtual void setNProcs(const label nProcs)
const label myComm_
Any communicator allocated by me.
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
const labelList ioRanks_
Ranks of IO handlers.
label nProcs_
Number of processors (overall)
TypeName("collated")
Runtime type information.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
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).
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73