Loading...
Searching...
No Matches
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-2025 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 Can use MPI-IO for the backend (when backend_ == 1),
35 which can be defined by the "collated.backend" optimisation switch.
36
37 Uses threading if maxThreadFileBufferSize != 0.
38 > 0 : Can use mpi inside thread to collect data if buffer is not
39 large enough. Does need full thread support inside MPI.
40
41 < 0 : special : -maxThreadFileBufferSize is guaranteed large enough
42 for all writing. Initialises MPI without thread support.
43
44See also
45 masterUncollatedFileOperation
46
47SourceFiles
48 collatedFileOperation.C
49
50\*---------------------------------------------------------------------------*/
51
52#ifndef Foam_fileOperations_collatedFileOperation_H
53#define Foam_fileOperations_collatedFileOperation_H
54
57#include "OFstreamCollator.H"
58
59// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60
61namespace Foam
62{
63namespace fileOperations
64{
66/*---------------------------------------------------------------------------*\
67 Class collatedFileOperation Declaration
68\*---------------------------------------------------------------------------*/
69
71:
73{
74 // Private Enumeration
75
76 //- Preferred backend for collated format
77 enum backendTypes : int
78 {
79 BACKEND_LEGACY = 0,
80 BACKEND_MPI_IO = 1,
81 };
82
83
84 // Private Data
85
86 //- Communicator allocated/managed by us
87 mutable label managedComm_;
88
89
90 // Private Member Functions
91
92 //- Any initialisation steps after constructing
93 void init(bool verbose);
94
95 //- Writes a regIOobject (so header, contents and divider).
96 // Returns success state.
97 bool writeObject_legacy
98 (
99 const fileName& pathName,
100 const regIOobject&,
101 IOstreamOption streamOpt,
102 const bool writeOnProc
103 ) const;
104
105 //- Writes a regIOobject (so header, contents and divider).
106 // Returns success state.
107 bool writeObject_mpiio
108 (
109 const fileName& pathName,
110 const regIOobject&,
111 IOstreamOption streamOpt,
112 const bool writeOnProc
113 ) const;
114
115
116protected:
117
118 // Protected Data
119
120 //- Threaded writer
122
123
124 // Protected Member Functions
125
126 //- Print banner information, optionally with io ranks
127 void printBanner(const bool withRanks = false) const;
128
129 //- Append to processorsNN/ file
131 (
132 const regIOobject& io,
133 const fileName& pathName,
134 IOstreamOption streamOpt
135 ) const;
136
137public:
138
139 //- Runtime type information
140 TypeName("collated");
141
142
143 // Static Data
144
145 //- The type of backend to be used
146 static int backend_;
147
148 //- Max size of thread buffer size. This is the overall size of
149 // all files to be written. Starts blocking if not enough size.
150 // Read as float to enable easy specification of large sizes.
151 static float maxThreadFileBufferSize;
152
153
154 // Constructors
156 //- Default construct
157 explicit collatedFileOperation(bool verbose = false);
158
159 //- Construct from communicator with specified io-ranks
160 explicit collatedFileOperation
161 (
162 const Tuple2<label, labelList>& commAndIORanks,
163 const bool distributedRoots,
164 bool verbose = false
165 );
166
167
168 //- Destructor
169 virtual ~collatedFileOperation();
170
172 // Member Functions
173
174 //- Transfer ownership of communicator to this fileOperation.
175 //- Use with caution
176 virtual void storeComm() const;
177
178
179 // (reg)IOobject functionality
180
181 //- Generate disk file name for object. Opposite of filePath.
182 virtual fileName objectPath
183 (
184 const IOobject& io,
185 const word& typeName
186 ) const;
187
188 //- Writes a regIOobject (so header, contents and divider).
189 // Returns success state.
190 virtual bool writeObject
191 (
192 const regIOobject&,
193 IOstreamOption streamOpt = IOstreamOption(),
194 const bool writeOnProc = true
195 ) const;
196
197
198 // Other
199
200 //- Forcibly wait until all output done. Flush any cached data
201 virtual void flush() const;
202
203 //- Actual name of processors dir
204 virtual word processorsDir(const IOobject&) const;
205
206 //- Actual name of processors dir
207 virtual word processorsDir(const fileName&) const;
208};
209
210
211/*---------------------------------------------------------------------------*\
212 Class fileOperationInitialise_collated Declaration
213\*---------------------------------------------------------------------------*/
214
215//- A fileOperation initialiser for collated file handlers.
216//- Requires threading for non-zero maxThreadFileBufferSize.
218:
220{
221public:
222
223 // Constructors
224
225 //- Construct from components
226 fileOperationInitialise_collated(int& argc, char**& argv)
227 :
228 fileOperationInitialise(argc, argv)
229 {}
230
231
232 //- Destructor
233 virtual ~fileOperationInitialise_collated() = default;
234
235
236 // Member Functions
237
238 //- The (MPI) threading requirement depends on buffering
239 virtual bool needsThreading() const
240 {
242 }
243};
244
245
246// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247
248} // End namespace fileOperations
249} // End namespace Foam
250
251// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252
253#endif
254
255// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
Threaded file writer.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
A class for handling file names.
Definition fileName.H:75
static int backend_
The type of backend to be used.
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.
collatedFileOperation(bool verbose=false)
Default construct.
TypeName("collated")
Runtime type information.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
void printBanner(const bool withRanks=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.
A fileOperation initialiser for collated file handlers. Requires threading for non-zero maxThreadFile...
virtual bool needsThreading() const
The (MPI) threading requirement depends on buffering.
virtual ~fileOperationInitialise_collated()=default
Destructor.
fileOperationInitialise_collated(int &argc, char **&argv)
Construct from components.
fileOperationInitialise(int &argc, char **&argv)
Construct from components.
masterUncollatedFileOperation(bool verbose=false)
Default construct.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
A class for handling words, derived from Foam::string.
Definition word.H:66
const auto & io
Namespace for implementations of a fileOperation.
Definition regIOobject.H:60
Namespace for OpenFOAM.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68