Skip to content

Commit fda8ca2

Browse files
committed
amrex::FileStream
Implement our own file stream class that is somewhat similar to std::fstream. It can be used by amrex::NFilesIter in mesh and particle data I/O. By default amrex::NFilesIter still uses std::fstream. To use amrex::FileStream, one needs to use `USE_OWN_FILE_STREAM=TRUE` for GNU Make and `AMReX_OWN_FILE_STREAM=ON` for CMake. amrex::FileStream::Read has not been tested and currently it is not being used for reading MultiFab and particles.
1 parent a6394da commit fda8ca2

24 files changed

+1037
-226
lines changed

Docs/sphinx_documentation/source/BuildingAMReX.rst

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,52 @@ list of important variables.
2828

2929
.. table:: Important make variables
3030

31-
+-----------------+-------------------------------------+--------------------+
32-
| Variable | Value | Default |
33-
+=================+=====================================+====================+
34-
| AMREX_HOME | Path to amrex | environment |
35-
+-----------------+-------------------------------------+--------------------+
36-
| COMP | gnu, cray, ibm, intel, intel-llvm, | |
37-
| | intel-classic, llvm, or pgi | none |
38-
+-----------------+-------------------------------------+--------------------+
39-
| CXXSTD | C++ standard (``c++17``, ``c++20``) | compiler default, |
40-
| | | at least ``c++17`` |
41-
+-----------------+-------------------------------------+--------------------+
42-
| DEBUG | TRUE or FALSE | FALSE |
43-
+-----------------+-------------------------------------+--------------------+
44-
| DIM | 1 or 2 or 3 | 3 |
45-
+-----------------+-------------------------------------+--------------------+
46-
| PRECISION | DOUBLE or FLOAT | DOUBLE |
47-
+-----------------+-------------------------------------+--------------------+
48-
| TEST | TRUE or FALSE | FALSE |
49-
+-----------------+-------------------------------------+--------------------+
50-
| USE_ASSERTION | TRUE or FALSE | FALSE |
51-
+-----------------+-------------------------------------+--------------------+
52-
| USE_MPI | TRUE or FALSE | FALSE |
53-
+-----------------+-------------------------------------+--------------------+
54-
| USE_OMP | TRUE or FALSE | FALSE |
55-
+-----------------+-------------------------------------+--------------------+
56-
| USE_CUDA | TRUE or FALSE | FALSE |
57-
+-----------------+-------------------------------------+--------------------+
58-
| USE_HIP | TRUE or FALSE | FALSE |
59-
+-----------------+-------------------------------------+--------------------+
60-
| USE_SYCL | TRUE or FALSE | FALSE |
61-
+-----------------+-------------------------------------+--------------------+
62-
| USE_RPATH | TRUE or FALSE | FALSE |
63-
+-----------------+-------------------------------------+--------------------+
64-
| WARN_ALL | TRUE or FALSE | TRUE for DEBUG |
65-
| | | FALSE otherwise |
66-
+-----------------+-------------------------------------+--------------------+
67-
| AMREX_CUDA_ARCH | CUDA arch such as 70 | 70 if not set |
68-
| or CUDA_ARCH | | or detected |
69-
+-----------------+-------------------------------------+--------------------+
70-
| AMREX_AMD_ARCH | AMD GPU arch such as gfx908 | none if the |
71-
| or AMD_ARCH | | machine is unknown |
72-
+-----------------+-------------------------------------+--------------------+
73-
| USE_GPU_RDC | TRUE or FALSE | TRUE |
74-
+-----------------+-------------------------------------+--------------------+
31+
+---------------------+-------------------------------------+--------------------+
32+
| Variable | Value | Default |
33+
+=====================+=====================================+====================+
34+
| AMREX_HOME | Path to amrex | environment |
35+
+---------------------+-------------------------------------+--------------------+
36+
| COMP | gnu, cray, ibm, intel, intel-llvm, | |
37+
| | intel-classic, llvm, or pgi | none |
38+
+---------------------+-------------------------------------+--------------------+
39+
| CXXSTD | C++ standard (``c++17``, ``c++20``) | compiler default, |
40+
| | | at least ``c++17`` |
41+
+---------------------+-------------------------------------+--------------------+
42+
| DEBUG | TRUE or FALSE | FALSE |
43+
+---------------------+-------------------------------------+--------------------+
44+
| DIM | 1 or 2 or 3 | 3 |
45+
+---------------------+-------------------------------------+--------------------+
46+
| PRECISION | DOUBLE or FLOAT | DOUBLE |
47+
+---------------------+-------------------------------------+--------------------+
48+
| TEST | TRUE or FALSE | FALSE |
49+
+---------------------+-------------------------------------+--------------------+
50+
| USE_ASSERTION | TRUE or FALSE | FALSE |
51+
+---------------------+-------------------------------------+--------------------+
52+
| USE_MPI | TRUE or FALSE | FALSE |
53+
+---------------------+-------------------------------------+--------------------+
54+
| USE_OMP | TRUE or FALSE | FALSE |
55+
+---------------------+-------------------------------------+--------------------+
56+
| USE_CUDA | TRUE or FALSE | FALSE |
57+
+---------------------+-------------------------------------+--------------------+
58+
| USE_HIP | TRUE or FALSE | FALSE |
59+
+---------------------+-------------------------------------+--------------------+
60+
| USE_SYCL | TRUE or FALSE | FALSE |
61+
+---------------------+-------------------------------------+--------------------+
62+
| USE_RPATH | TRUE or FALSE | FALSE |
63+
+---------------------+-------------------------------------+--------------------+
64+
| WARN_ALL | TRUE or FALSE | TRUE for DEBUG |
65+
| | | FALSE otherwise |
66+
+---------------------+-------------------------------------+--------------------+
67+
| AMREX_CUDA_ARCH | CUDA arch such as 70 | 70 if not set |
68+
| or CUDA_ARCH | | or detected |
69+
+---------------------+-------------------------------------+--------------------+
70+
| AMREX_AMD_ARCH | AMD GPU arch such as gfx908 | none if the |
71+
| or AMD_ARCH | | machine is unknown |
72+
+---------------------+-------------------------------------+--------------------+
73+
| USE_GPU_RDC | TRUE or FALSE | TRUE |
74+
+---------------------+-------------------------------------+--------------------+
75+
| USE_OWN_FILE_STREAM | TRUE or FALSE | FALSE |
76+
+---------------------+-------------------------------------+--------------------+
7577

7678

7779
.. raw:: latex
@@ -551,6 +553,8 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
551553
| AMReX_INLINE_LIMIT | Inline limit. Relevant only when | 43210 | Non-negative number |
552554
| | AMReX_COMPILER_DEFAULT_INLINE is NO. | | |
553555
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
556+
| AMReX_OWN_FILE_STREAM | Use AMReX's own file stream in I/O | NO | YES, NO |
557+
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
554558
.. raw:: latex
555559

556560
\end{center}

Src/Base/AMReX.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace amrex
136136
//! Print out message to cerr and exit via amrex::Abort().
137137
void Error (const std::string& msg);
138138

139-
void Error_host (const char* type, const char* msg);
139+
void Error_host (const char* type, const char* msg, bool can_throw = true);
140140

141141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
142142
void Error (const char* msg = nullptr) {

Src/Base/AMReX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ amrex::Warning (const std::string& msg)
239239
}
240240

241241
void
242-
amrex::Error_host (const char* type, const char * msg)
242+
amrex::Error_host (const char* type, const char * msg, bool can_throw)
243243
{
244244
amrex::ignore_unused(type);
245245
#ifdef AMREX_USE_COVERITY
246246
amrex_coverity_abort();
247247
#else
248248
if (system::error_handler) {
249249
system::error_handler(msg);
250-
} else if (system::throw_exception) {
250+
} else if (system::throw_exception && can_throw) {
251251
throw RuntimeError(msg);
252252
} else {
253253
write_lib_id(type);

Src/Base/AMReX_FabConv.H

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <AMReX_BLassert.H>
99
#include <AMReX_REAL.H>
1010
#include <AMReX_INT.H>
11+
#include <AMReX_FileStream.H>
1112

1213
#include <iosfwd>
1314

@@ -182,6 +183,10 @@ public:
182183
Long nitems,
183184
std::istream& is,
184185
const RealDescriptor& id);
186+
static void convertToNativeFormat (Real* out,
187+
Long nitems,
188+
amrex::FileStream& is,
189+
const RealDescriptor& id);
185190

186191
/**
187192
* \brief Convert nitems Reals in native format to RealDescriptor format
@@ -191,6 +196,10 @@ public:
191196
Long nitems,
192197
const Real* in,
193198
const RealDescriptor& od);
199+
static void convertFromNativeFormat (amrex::FileStream& os,
200+
Long nitems,
201+
const Real* in,
202+
const RealDescriptor& od);
194203
/**
195204
* \brief Convert nitems Reals in native format to RealDescriptor format.
196205
* The out array is assumed to be large enough to hold the
@@ -209,6 +218,10 @@ public:
209218
Long nitems,
210219
const float* in,
211220
const RealDescriptor& od);
221+
static void convertFromNativeFloatFormat (amrex::FileStream& os,
222+
Long nitems,
223+
const float* in,
224+
const RealDescriptor& od);
212225

213226
/**
214227
* \brief Convert nitems doubles in native format to RealDescriptor format
@@ -218,6 +231,10 @@ public:
218231
Long nitems,
219232
const double* in,
220233
const RealDescriptor& od);
234+
static void convertFromNativeDoubleFormat (amrex::FileStream& os,
235+
Long nitems,
236+
const double* in,
237+
const RealDescriptor& od);
221238

222239
/**
223240
* \brief Read nitems from istream in RealDescriptor format and
@@ -228,6 +245,10 @@ public:
228245
Long nitems,
229246
std::istream& is,
230247
const RealDescriptor& id);
248+
static void convertToNativeFloatFormat (float* out,
249+
Long nitems,
250+
amrex::FileStream& is,
251+
const RealDescriptor& id);
231252

232253
/**
233254
* \brief Read nitems from istream in RealDescriptor format and
@@ -238,6 +259,10 @@ public:
238259
Long nitems,
239260
std::istream& is,
240261
const RealDescriptor& id);
262+
static void convertToNativeDoubleFormat (double* out,
263+
Long nitems,
264+
amrex::FileStream& is,
265+
const RealDescriptor& id);
241266

242267
private:
243268

0 commit comments

Comments
 (0)