Loading...
Searching...
No Matches
UPstreamFile.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) 2025 Mark Olesen
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::UPstream::File
28
29Description
30 An opaque wrapper for MPI_File methods
31 without any \c <mpi.h> header dependency.
32
33Note
34 Not included as part of UPstream.H - only include locally as required
35
36SourceFiles
37 UPstreamFile.txx
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_UPstreamFile_H
42#define Foam_UPstreamFile_H
43
44#include "fileName.H"
45#include "UPstream.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
52/*---------------------------------------------------------------------------*\
53 Class UPstream::File Declaration
54\*---------------------------------------------------------------------------*/
55
57{
58 // Forward Declaration
59 class Impl;
60
61
62 // Private Data
63
64 //- Implementation wrapper of MPI_File etc
65 std::unique_ptr<Impl> file_;
66
67
68protected:
69
70 // Protected Method Functions
71
72 //- MPI_File_write [non-collective] : write data
73 bool write_data
74 (
76 const void* buffer,
78 std::streamsize count,
79 const UPstream::dataTypes dataTypeId
80 );
81
82 //- MPI_File_write_at [non-collective] : write data at specified offset
83 bool write_data_at
84 (
86 std::streamsize offset,
88 const void* buffer,
90 std::streamsize count,
91 const UPstream::dataTypes dataTypeId
92 );
93
94 //- MPI_File_write_all [collective] : write data
96 (
98 const void* buffer,
100 std::streamsize count,
101 const UPstream::dataTypes dataTypeId
102 );
103
104 //- MPI_File_write_at_all [collective] :
105 //- write data at specified offset
107 (
109 std::streamsize offset,
111 const void* buffer,
113 std::streamsize count,
114 const UPstream::dataTypes dataTypeId
115 );
116
117
118public:
119
120 // Generated Methods
121
122 //- No copy construct
123 File(const File&&) = delete;
124
125 //- Move construct
126 File(File&&) noexcept;
127
128 //- No copy assignment
129 File& operator=(const File&) = delete;
131 //- Move assignment
133
134
135 // Constructors
136
137 //- Default construct
138 File();
139
140 //- Destructor. Non-default in header (incomplete types)
141 ~File();
142
143
144 // Static Member Functions
146 //- True if MPI/IO appears to be supported
147 static bool supported();
148
149
150 // Member Functions
151
152 // Access
153
154 //- The name of the open stream
155 const fileName& name() const;
156
157 //- True if allocated and open has been called
158 bool is_open() const;
159
160
161 // Basics
162
163 //- MPI_File_open [collective] :
164 //- open file in write-only mode, no-append
165 bool open_write
166 (
168 const int communicator,
170 const fileName& pathname,
172 IOstreamOption::atomicType = IOstreamOption::NON_ATOMIC
173 );
174
175 //- MPI_File_close [collective]
176 bool close();
177
178 //- Set the (output) file size [collective]
179 bool set_size(std::streamsize num_bytes);
180
181
182 // Writing
183
184 //- MPI_File_write [non-collective] : write data.
185 // A no-op and return true if content is empty
186 inline bool write(std::string_view sv);
187
188 //- MPI_File_write [non-collective] : write data.
189 // A no-op and return true if buffer is nullptr or count is zero
190 template<class Type>
191 inline bool write
192 (
194 const Type* buffer,
196 std::streamsize count
197 );
198
199 //- MPI_File_write_at [non-collective] : write data at specified offset.
200 // A no-op and return true if content is empty
201 inline bool write_at(std::streamsize offset, std::string_view sv);
202
203 //- MPI_File_write_at [non-collective] : write data at specified offset.
204 // A no-op and return true if buffer is nullptr or count is zero
205 template<class Type>
206 inline bool write_at
207 (
209 std::streamsize offset,
211 const Type* buffer,
213 std::streamsize count
214 );
215
216 //- MPI_File_write_all [collective] : write data
217 inline bool write_all(std::string_view sv);
219 //- MPI_File_write_all [collective] : write data
220 template<class Type>
221 inline bool write_all
222 (
224 const Type* buffer,
226 std::streamsize count
227 );
228
229 //- MPI_File_write_at_all [collective] :
230 //- write data at specified offset
231 inline bool write_at_all
232 (
234 std::streamsize offset,
236 std::string_view sv
237 );
238
239 //- MPI_File_write_at_all [collective] :
240 //- write data at specified offset
241 template<class Type>
242 inline bool write_at_all
243 (
245 std::streamsize offset,
247 const Type* buffer,
249 std::streamsize count
250 );
251};
252
253
254// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255
256} // End namespace Foam
257
258
259// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261#include "UPstreamFile.txx"
262
263// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264
265#endif
267// ************************************************************************* //
A simple container for options an IOstream can normally have.
An opaque wrapper for MPI_File methods without any <mpi.h> header dependency.
bool write_at(std::streamsize offset, std::string_view sv)
MPI_File_write_at [non-collective] : write data at specified offset.
bool is_open() const
True if allocated and open has been called.
bool open_write(const int communicator, const fileName &pathname, IOstreamOption::atomicType=IOstreamOption::NON_ATOMIC)
MPI_File_open [collective] : open file in write-only mode, no-append.
bool write_data_at_all(std::streamsize offset, const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_at_all [collective] : write data at specified offset.
bool close()
MPI_File_close [collective].
File(const File &&)=delete
No copy construct.
bool write_all(std::string_view sv)
MPI_File_write_all [collective] : write data.
const fileName & name() const
The name of the open stream.
static bool supported()
True if MPI/IO appears to be supported.
bool set_size(std::streamsize num_bytes)
Set the (output) file size [collective].
File(File &&) noexcept
Move construct.
File()
Default construct.
bool write_data_at(std::streamsize offset, const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_at [non-collective] : write data at specified offset.
File & operator=(const File &)=delete
No copy assignment.
bool write_at_all(std::streamsize offset, std::string_view sv)
MPI_File_write_at_all [collective] : write data at specified offset.
bool write(std::string_view sv)
MPI_File_write [non-collective] : write data.
bool write_data_all(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write_all [collective] : write data.
bool write_data(const void *buffer, std::streamsize count, const UPstream::dataTypes dataTypeId)
MPI_File_write [non-collective] : write data.
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition UPstream.H:2546
dataTypes
Mapping of some fundamental and aggregate types to MPI data types.
Definition UPstream.H:107
A class for handling file names.
Definition fileName.H:75
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265