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-2020 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 
36 See also
37  masterUncollatedFileOperation
38 
39 SourceFiles
40  collatedFileOperation.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef fileOperations_collatedFileOperation_H
45 #define fileOperations_collatedFileOperation_H
46 
48 #include "OFstreamCollator.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 namespace fileOperations
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class collatedFileOperation Declaration
60 \*---------------------------------------------------------------------------*/
61 
63 :
65 {
66 protected:
67 
68  // Protected data
69 
70  //- Any communicator allocated by me
71  const label myComm_;
72 
73  //- Threaded writer
74  mutable OFstreamCollator writer_;
75 
76  // For non-parallel operation
77 
78  //- Number of processors (overall)
79  label nProcs_;
80 
81  //- Ranks of IO handlers
82  const labelList ioRanks_;
83 
84 
85  // Private Member Functions
86 
87  static labelList ioRanks();
88 
89  //- Is proci master of communicator (in parallel) or master of
90  // the io ranks (non-parallel)
91  bool isMasterRank(const label proci) const;
92 
93  //- Append to processors/ file
94  bool appendObject
95  (
96  const regIOobject& io,
97  const fileName& pathName,
98  IOstreamOption streamOpt
99  ) const;
100 
101 
102 public:
103 
104  //- Runtime type information
105  TypeName("collated");
106 
107 
108  // Static data
109 
110  //- Max size of thread buffer size. This is the overall size of
111  // all files to be written. Starts blocking if not enough size.
112  // Read as float to enable easy specification of large sizes.
113  static float maxThreadFileBufferSize;
114 
115 
116  // Constructors
117 
118  //- Construct null
119  collatedFileOperation(bool verbose);
120 
121  //- Construct from user communicator
123  (
124  const label comm,
125  const labelList& ioRanks,
126  const word& typeName,
127  bool verbose
128  );
129 
130 
131  //- Destructor
132  virtual ~collatedFileOperation();
133 
134 
135  // Member Functions
136 
137  // (reg)IOobject functionality
138 
139  //- Generate disk file name for object. Opposite of filePath.
140  virtual fileName objectPath
141  (
142  const IOobject& io,
143  const word& typeName
144  ) const;
145 
146  //- Writes a regIOobject (so header, contents and divider).
147  // Returns success state.
148  virtual bool writeObject
149  (
150  const regIOobject&,
151  IOstreamOption streamOpt = IOstreamOption(),
152  const bool valid = true
153  ) const;
154 
155  // Other
156 
157  //- Forcibly wait until all output done. Flush any cached data
158  virtual void flush() const;
159 
160  //- Actual name of processors dir
161  virtual word processorsDir(const IOobject&) const;
162 
163  //- Actual name of processors dir
164  virtual word processorsDir(const fileName&) const;
165 
166  //- Set number of processor directories/results. Only used in
167  // decomposePar
168  virtual void setNProcs(const label nProcs);
169 };
170 
171 
172 /*---------------------------------------------------------------------------*\
173  Class collatedFileOperationInitialise Declaration
174 \*---------------------------------------------------------------------------*/
175 
177 :
179 {
180 public:
181 
182  // Constructors
183 
184  //- Construct from components
185  collatedFileOperationInitialise(int& argc, char**& argv)
186  :
188  {}
189 
190 
191  //- Destructor
192  virtual ~collatedFileOperationInitialise() = default;
193 
194 
195  // Member Functions
196 
197  //- Needs threading
198  virtual bool needsThreading() const
199  {
200  return
202  > 0;
203  }
204 };
205 
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 } // End namespace fileOperations
210 } // End namespace Foam
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::fileOperations::collatedFileOperation::maxThreadFileBufferSize
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
Definition: collatedFileOperation.H:112
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileOperations::collatedFileOperation::~collatedFileOperation
virtual ~collatedFileOperation()
Destructor.
Definition: collatedFileOperation.C:412
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fileOperations::collatedFileOperation::ioRanks
static labelList ioRanks()
Definition: collatedFileOperation.C:79
fileOperationInitialise.H
Foam::fileOperations::collatedFileOperation::processorsDir
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
Definition: collatedFileOperation.C:690
Foam::fileOperations::collatedFileOperation::writer_
OFstreamCollator writer_
Threaded writer.
Definition: collatedFileOperation.H:73
Foam::fileOperations::collatedFileOperationInitialise::collatedFileOperationInitialise
collatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
Definition: collatedFileOperation.H:184
Foam::fileOperations::collatedFileOperationInitialise::~collatedFileOperationInitialise
virtual ~collatedFileOperationInitialise()=default
Destructor.
Foam::fileOperations::collatedFileOperation::ioRanks_
const labelList ioRanks_
Ranks of IO handlers.
Definition: collatedFileOperation.H:81
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:424
Foam::fileOperations::collatedFileOperation::appendObject
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processors/ file.
Definition: collatedFileOperation.C:118
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:1059
Foam::fileOperations::collatedFileOperation::setNProcs
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
Definition: collatedFileOperation.C:698
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
Is proci master of communicator (in parallel) or master of.
Definition: collatedFileOperation.C:95
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:454
Foam::fileOperations::collatedFileOperation
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
Definition: collatedFileOperation.H:61
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstreamCollator
Threaded file writer.
Definition: OFstreamCollator.H:71
Foam::fileOperations::collatedFileOperation::nProcs_
label nProcs_
Number of processors (overall)
Definition: collatedFileOperation.H:78
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::fileOperations::masterUncollatedFileOperation
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Definition: masterUncollatedFileOperation.H:85
masterUncollatedFileOperation.H
Foam::fileOperations::collatedFileOperationInitialise
Definition: collatedFileOperation.H:175
Foam::List< label >
Foam::fileOperations::collatedFileOperationInitialise::needsThreading
virtual bool needsThreading() const
Needs threading.
Definition: collatedFileOperation.H:197
Foam::fileOperations::masterUncollatedFileOperationInitialise
Definition: masterUncollatedFileOperation.H:777
Foam::fileOperations::collatedFileOperation::collatedFileOperation
collatedFileOperation(bool verbose)
Construct null.
Definition: collatedFileOperation.C:241
Foam::fileOperations::collatedFileOperation::myComm_
const label myComm_
Any communicator allocated by me.
Definition: collatedFileOperation.H:70
Foam::fileOperations::collatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: collatedFileOperation.C:612
OFstreamCollator.H
Foam::fileOperations::collatedFileOperation::TypeName
TypeName("collated")
Runtime type information.