MAIA bb96820c
Multiphysics at AIA
|
#include <parallelio_pnetcdf.h>
Classes | |
struct | NcDimProxy |
Public Member Functions | |
ParallelIoPNetcdf (const MString &fileName, MInt fileMode, const MPI_Comm &mpiComm) | |
Creates a new object to read and write big data files. [MPI] More... | |
~ParallelIoPNetcdf () override | |
Calls close(). [MPI] More... | |
void | close () |
Close the file (normally called by the destructor but needs to be explicitely called earlier in specific cases, e.g. when. More... | |
template<> | |
void | b_setAttribute (const MString *value, const MString &name, const MString &datasetName, const size_type totalCount) |
Set an attribute in the file (string version). More... | |
template<> | |
void | b_writeArray (const MString *array, const MString &name, const size_type noDims, MPI_Offset *start, MPI_Offset *count, MPI_Offset memoryStride, const size_type noChunks, MPI_Offset diskStride) |
Writes array data to file (string version). [MPI] More... | |
template<> | |
void | b_writeScalar (const MString &scalar, const MString &name) |
Writes scalar data to file (string version). [MPI] More... | |
template<> | |
void | b_readArray (MString *array, const MString &name, const size_type noDims, MPI_Offset *start, MPI_Offset *count, MPI_Offset memoryStride, const size_type noChunks, MPI_Offset diskStride) |
Read array data from file (string version). [MPI] More... | |
template<> | |
void | b_readScalar (MString *scalar, const MString &name) |
Read scalar data from file (float version). [MPI] More... | |
template<> | |
void | b_getAttribute (MString *const value, const MString &name, const MString &datasetName, const size_type totalCount) |
Retrieve an attribute from file (string version). More... | |
Public Member Functions inherited from ParallelIoBase< ParallelIoPNetcdf > | |
MBool | hasDataset (const MString &name, MInt dimension) |
Check if the file contains an dataset with the given name and dimension. More... | |
MBool | hasDataset (const MString &name, const MString &path) |
MBool | hasDataset (const MString &name) |
Check if the file contains an dataset with the given name. More... | |
MBool | hasObject (const MString &path) |
MInt | getDatasetType (const MString &name) |
Returns the data type of an array. More... | |
std::vector< MString > | getDatasetNames (const size_type dimensions=-1) |
Returns a vector with the names of all existing datasets with given dimensionality in the file. More... | |
std::vector< MString > | getDatasetNames (const MString &path) |
std::vector< MString > | getGroupNames (const MString &path) |
size_type | getDatasetNoDims (const MString &name) |
Get the number of dimensions of a dataset with given name. More... | |
size_type | getDatasetNoDims (const MString &name, const MString &path) |
std::vector< size_type > | getArrayDims (const MString &name) |
Get the lengths of all dimensions of a dataset with given name. More... | |
size_type | getArraySize (const MString &name, const size_type dimensionId=0) |
Get the length of an array in the file. More... | |
void | getArraySize (const MString &name, const MString &path, size_type *datasetSize) |
MBool | hasAttribute (const MString &name, const MString &path="") |
Check if a given attribute exists in the file. More... | |
maiabd_type | getAttributeType (const MString &name, const MString &datasetName="") |
Returns the data type of an attribute in the file. More... | |
void | defineArray (maiabd_type type, const MString &name, size_type totalCount) |
Create a new array in the file. More... | |
void | defineArray (maiabd_type type, const MString &name, size_type noDims, size_type *totalCount) |
Create a new array in the file. More... | |
void | defineArray (maiabd_type type, const std::vector< MString > &name, size_type totalCount) |
Create multiple new arrays in the file. More... | |
void | defineArray (maiabd_type type, const MString &datasetName, const MString &name, size_type noDims, size_type *totalCount) |
Creates new array in the file. More... | |
void | defineScalar (maiabd_type type, const MString &name) |
Create a new scalar in the file. More... | |
void | writeArray (const T *array, const MString &name, size_type memoryStride=-1, size_type diskStride=-1) |
Write array data to file. [MPI] More... | |
void | writeArray (const T *array, const std::vector< MString > &names, size_type memoryStride=-1, size_type diskStride=-1) |
Write array data to file (multi-array version). [MPI] More... | |
void | writeArray (const T *array, const MString &path, const MString &name, const size_type noDims, size_type *offset, size_type *localCount) |
Write multidimensional array data to file. [MPI] More... | |
void | writeArray (const T *array, const MString &path, const MString &name, const size_type noDims, size_type *offset, size_type *localCount, size_type *ghost) |
Write multidimensional array data to file [ghost cell version]. [MPI] More... | |
void | writeScalar (T scalar, const MString &name) |
Write scalar data to file. [MPI] More... | |
void | setAttribute (const T &value, const MString &name, const MString &datasetName="") |
Set a file or dataset attribute. [MPI] More... | |
void | setAttribute (const MChar *value, const MString &name, const MString &datasetName="") |
void | setAttributes (const T *value, const MString &name, size_type totalCount, const MString &datasetName="") |
void | readArray (T *array, const MString &name, size_type memoryStride=-1, size_type diskStride=-1) |
Read array data from file. [MPI] More... | |
void | readArray (std::vector< T > &array, const MString &name, size_type memoryStride=-1, size_type diskStride=-1) |
void | readArray (T *array, const std::vector< MString > &names, size_type memoryStride=-1, size_type diskStride=-1) |
Read array data from file (multi-array version). [MPI] More... | |
void | readArray (T *array, const MString &datasetName, const MString &name, const size_type noDims, const size_type *offset, const size_type *localCount) |
Read array data from file. [MPI] More... | |
void | readArray (T *array, const MString &datasetName, const MString &name, const size_type noDims, const size_type *localCount) |
Read array data from file [no offset version]. [MPI] More... | |
void | readScalar (T *scalar, const MString &name) |
Read scalar data from file. [MPI] More... | |
void | getAttribute (T *value, const MString &name, const MString &datasetName="") |
Retrieve a file or dataset attribute. More... | |
void | getAttribute (T *value, const MString &name, const size_type totalCount, const MString &datasetName="") |
void | getAttributeCount (const MString &name, size_type *totalCount, const MString &datasetName="") |
void | setOffset (const size_type localCount, const size_type offset, const size_type noDims, const size_type noChunks) |
Set the local and global counts, as well the local offset for array operations. More... | |
void | setOffset (const size_type localCount, const size_type offset, const size_type noDims) |
Set the local and global counts, as well the local offset for array operations (overload). More... | |
void | setOffset (size_type localCount, size_type offset) |
Set the local and global counts, as well the local offset for array operations (overload). More... | |
Private Types | |
using | NcDimMap = std::map< size_type, NcDimProxy > |
Private Member Functions | |
void | b_ncEndDef () |
Leave the define mode (NetCDF-specific). [MPI] More... | |
void | b_ncRedef () |
Enter define mode (NetCDF-specific). [MPI] More... | |
void | b_saveHeader () |
Adds all additional header information that are needed in the file. More... | |
void | b_addAdditionalHeader () |
Write additional headers to file (e.g. grid file name, creation date etc.). [MPI] More... | |
void | b_writeAdditionalData () |
Write additional data to file (NetCDF-specific). [MPI] More... | |
void | b_defineArray (maiabd_type type, const MString &name, size_type noDims, size_type *totalCount) |
Defines an array in the file. [MPI] More... | |
void | b_defineArray (maiabd_type, const MString &, const MString &, const size_type, const size_type *) |
void | b_defineScalar (maiabd_type type, const MString &name) |
Defines a scalar in the file. [MPI] More... | |
MBool | b_hasDataset (const MString &name, const size_type dimension) |
Check if the file contains a dataset with the given name and number of dimensions. More... | |
MBool | b_hasDataset (const MString &name, const MString &path) |
MBool | b_hasObject (const MString &path) |
MInt | b_getDatasetType (const MString &name) |
Returns the data type of a dataset in the file (can be array, multi-D array or scalar). More... | |
void | b_getDatasetNames (std::vector< MString > &names, const size_type dimension) |
Returns a vector of all existing datasets with the given number of dimensions in the file (if any). [MPI] More... | |
void | b_getDatasetNames (std::vector< MString > &names, const MString &path) |
void | b_getGroupNames (std::vector< MString > &names, const MString &path) |
size_type | b_getDatasetNoDims (const MString &name) |
Get number of dimensions of a dataset with the given name. More... | |
size_type | b_getDatasetNoDims (const MString &path, const MString &name) |
size_type | b_getDatasetSize (const MString &name, const size_type dimensionId=0) |
Get the length of one dimension of an arbitrary array in the file. More... | |
void | b_getDatasetSize (const MString &name, const MString &path, size_type noDims, size_type *data) |
MBool | b_hasAttribute (const MString &name, const MString &datasetName="") |
Check if a given attribute exists in the file. More... | |
MInt | b_getAttributeType (const MString &name, const MString &datasetName="") |
Returns the data type of an attribute in the file. More... | |
void | b_printFileHints () |
Print PNetCDF file hints to cerr. More... | |
template<class T > | |
void | b_writeArray (const T *const array, const MString &name, const size_type noDims, MPI_Offset *start, MPI_Offset *count, MPI_Offset memoryStride, const size_type noChunks, MPI_Offset diskStride) |
Writes array data to file (generic version). [MPI] More... | |
template<class T > | |
void | b_writeArray (const T *, const MString &, const MString &, const size_type, const size_type *, const size_type *, const size_type *) |
template<class T > | |
void | b_writeScalar (const T scalar, const MString &name) |
Writes scalar data to file (generic version). [MPI] More... | |
template<class T > | |
void | b_readArray (T *array, const MString &name, const size_type noDims, MPI_Offset *start, MPI_Offset *count, MPI_Offset memoryStride, const size_type noChunks, MPI_Offset diskStride) |
Read array data from file (generic version). [MPI] More... | |
template<class T > | |
void | b_readArray (T *, const MString &, const MString &, const size_type, const size_type *, const size_type *) |
template<class T > | |
void | b_readScalar (T *scalar, const MString &name) |
Read scalar data from file (generic version). [MPI] More... | |
template<class T > | |
void | b_setAttribute (const T *value, const MString &name, const MString &datasetName="", const size_type totalCount=1) |
Set an attribute in the file (generic version). More... | |
template<class T > | |
void | b_getAttribute (T *const value, const MString &name, const MString &datasetName="", const size_type totalCount=1) |
Retrieve an attribute from file (generic version). More... | |
void | b_getAttributeCount (const MString &name, size_type *totalCount, const MString &datasetName="") |
Static Private Member Functions | |
static MBool | b_isValidFile (const MString &name, const MPI_Comm &mpiComm) |
Check if specified file is a valid HDF5 file (i.e. can be opened). [MPI] More... | |
static const MString | b_fileExt () |
Returns backend-specific ending of filename (either ".Netcdf" or ".Hdf5") More... | |
static void | b_error (MInt status, const MString &name, const MString &location) |
Check the status code of a HDF5 operation and output a meaningful message. More... | |
Private Attributes | |
friend | ParallelIoBase< ParallelIoPNetcdf > |
MInt | b_ncId = -1 |
MBool | b_ncDataMode = false |
NcDimMap | b_ncDimensions {} |
Additional Inherited Members | |
Public Types inherited from ParallelIoBase< ParallelIoPNetcdf > | |
using | size_type = MLong |
Type used for all size- and offset-related values. More... | |
using | maiabd_type = maia::parallel_io::maiabd_type |
Type used for all constants that are defined in maia::parallel_io. More... | |
Static Public Member Functions inherited from ParallelIoBase< ParallelIoPNetcdf > | |
static MBool | fileExists (const MString &name, const MPI_Comm &mpiComm) |
Check whether a file exists. [MPI] More... | |
static void | deleteFile (const MString &name) |
Deletes the specified file. [MPI] More... | |
static MBool | isParallelIoFile (const MString &name, const MPI_Comm &mpiComm) |
Check if specified file is a valid ParallelIoHdf5 file. [MPI] More... | |
static MString | fileExt () |
Returns backend-specific ending of filename (either ".Netcdf" or ".Hdf5") More... | |
static void | calcOffset (size_type localCount, size_type *offset, size_type *totalCount, const MPI_Comm &mpiComm, size_type *noChunks=nullptr) |
Calculates the totalCount and offset information needed in setOffset(). [MPI] More... | |
Protected Member Functions inherited from ParallelIoBase< ParallelIoPNetcdf > | |
ParallelIoBase (MString fileName, MInt fileMode, const MPI_Comm &mpiComm) | |
Creates a new object to read and write big data files. [MPI] More... | |
virtual | ~ParallelIoBase () |
empty destructor. [MPI] More... | |
void | validateType (const maiabd_type type) const |
Auxiliary method that aborts MAIA if type is not a valid type constant for ParallelIo. More... | |
Protected Attributes inherited from ParallelIoBase< ParallelIoPNetcdf > | |
const MString | m_fileName |
const MInt | m_fileMode |
MBool | m_isHeaderSaved |
MInt | m_domainId |
MInt | m_noDomains |
MPI_Comm | m_mpiComm |
MPI_Info | m_mpiInfo |
MBool | m_offsetsAreSet |
std::vector< size_type > | m_localCount |
std::vector< size_type > | m_offset |
size_type | m_noChunks |
MFloat | m_creationTime |
std::set< MString > | m_unwrittenArrays |
std::set< MString > | m_unwrittenScalars |
std::set< MString > | m_writtenArrays |
std::set< MString > | m_writtenScalars |
std::set< MString > | m_readArrays |
std::set< MString > | m_readScalars |
Static Protected Attributes inherited from ParallelIoBase< ParallelIoPNetcdf > | |
static const size_type | s_maxChunkSize |
static const MPI_Datatype | s_mpiSizeType |
Definition at line 12 of file parallelio_pnetcdf.h.
|
private |
Definition at line 96 of file parallelio_pnetcdf.h.
ParallelIoPNetcdf::ParallelIoPNetcdf | ( | const MString & | fileName, |
MInt | fileMode, | ||
const MPI_Comm & | mpiComm | ||
) |
[in] | fileMode | The file mode can be either maia::parallel_io::PIO_CREATE, maia::parallel_io::PIO_APPEND, or maia::parallel_io::PIO_READ. |
[in] | mpiComm | The MPI communicator that should be used to open/create the file. |
Definition at line 372 of file parallelio_pnetcdf.cpp.
|
override |
Definition at line 452 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 561 of file parallelio_pnetcdf.cpp.
|
private |
[in] | type | Data type of the array (may be either maia::parallel_io::PIO_FLOAT or maia::parallel_io::PIO_INT or maia::parallel_io::PIO_STRING or maia::parallel_io::PIO_UCHAR). |
[in] | name | Name of the array (must not be empty). |
[in] | noDims | Number of array dimensions |
[in] | totalCount | Total size of the array in each dimension. |
Definition at line 717 of file parallelio_pnetcdf.cpp.
|
private |
|
private |
[in] | type | Data type of the scalar (may be either maia::parallel_io::PIO_FLOAT or maia::parallel_io::PIO_INT). |
[in] | name | Name of the scalar (must not be empty). |
Definition at line 808 of file parallelio_pnetcdf.cpp.
|
staticprivate |
[in] | status | HDF5 status code (negative if unexspected behaviour) |
[in] | name | Name of the file / variable / attribute |
[in] | location | Function which called the error message |
Definition at line 2100 of file parallelio_pnetcdf.cpp.
|
staticprivate |
Definition at line 349 of file parallelio_pnetcdf.cpp.
void ParallelIoPNetcdf::b_getAttribute | ( | MString *const | value, |
const MString & | name, | ||
const MString & | datasetName, | ||
const size_type | totalCount | ||
) |
[out] | value | Attribute value |
[in] | name | Attribute name |
[in] | datasetName | Dataset (scalar or array) to which the attribute is attached (leave empty for file attributes). |
Definition at line 2030 of file parallelio_pnetcdf.cpp.
|
private |
[out] | value | Attribute value |
[in] | name | Attribute name |
[in] | datasetName | Dataset (scalar or array) to which the attribute is attached (leave empty for file attributes). |
Definition at line 1987 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 2061 of file parallelio_pnetcdf.cpp.
|
private |
[in] | name | Name of the attribute to be checked. |
[in] | datasetName | Name of the dataset for which the attribute is checked. If empty, a file attribute is checked. |
Definition at line 1174 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 925 of file parallelio_pnetcdf.cpp.
|
private |
[in] | dimension | Match only datasets with given number of dimensions, default -1 which will return all datasets, 0 will only return scalars, 1 arrays with one dimension, ... |
[out] | names | List of dataset names. |
Definition at line 1020 of file parallelio_pnetcdf.cpp.
|
private |
[in] | name | Dataset name for which the number of dimensions is returned |
The number of dimensions of a dataset is returned, 0 is a scalar, 1 an array with one dimension, ...
Definition at line 1066 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 941 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 950 of file parallelio_pnetcdf.cpp.
|
private |
[in] | name | Name of the array to check. |
[in] | dimensionId | dimension of the array to check. |
Definition at line 1094 of file parallelio_pnetcdf.cpp.
[in] | name | Name of the dataset to check. |
Definition at line 972 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 933 of file parallelio_pnetcdf.cpp.
|
private |
[in] | name | Name of the attribute to be checked. |
[in] | datasetName | Name of the dataset for which the attribute is checked. If empty, a file attribute is checked. |
Definition at line 1131 of file parallelio_pnetcdf.cpp.
Definition at line 916 of file parallelio_pnetcdf.cpp.
|
private |
[in] | name | The name of the dataset that should be checked. |
[in] | noDimensions | Number of dimensions of the dataset to match, default -1 which is any dimensionality, 0 will only check scalars, 1 arrays with one dimension, ... |
Definition at line 878 of file parallelio_pnetcdf.cpp.
Definition at line 908 of file parallelio_pnetcdf.cpp.
|
staticprivate |
[in] | name | Name of the file that is to be checked. |
[in] | mpiComm | MPI communicator to be used. |
This must be a collective call from all ranks in mpiComm.
Definition at line 322 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 502 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 519 of file parallelio_pnetcdf.cpp.
|
private |
Source: https://trac.mcs.anl.gov/projects/parallel-netcdf/browser/trunk/examples/C/hints.c
Definition at line 1218 of file parallelio_pnetcdf.cpp.
void ParallelIoPNetcdf::b_readArray | ( | MString * | array, |
const MString & | name, | ||
const size_type | noDims, | ||
MPI_Offset * | start, | ||
MPI_Offset * | count, | ||
MPI_Offset | memoryStride, | ||
const size_type | noChunks, | ||
MPI_Offset | diskStride | ||
) |
[in] | array | Pointer to data in memory. |
[in] | name | Name of the dataset. |
[in] | noDims | Number of array dimensions |
[in] | start | Start offset in the file (i.e. the domain should start reading from here). |
[in] | count | Number of elements read from this domain. |
[in] | memoryStride | Stride in memory between data values. |
This method is the exact counterpart to h5WriteArray().
Definition at line 1726 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 1595 of file parallelio_pnetcdf.cpp.
|
private |
[in] | array | Pointer to data in memory. |
[in] | name | Name of the dataset. |
[in] | noDims | Number of array dimensions |
[in] | start | Start offset in the file (i.e. the domain should start reading from here). |
[in] | count | Number of elements read from this domain. |
[in] | memoryStride | Stride in memory between data values. |
This method is the exact counterpart to h5WriteArray().
Definition at line 1626 of file parallelio_pnetcdf.cpp.
[out] | scalar | Value to read. |
[in] | name | Name of the dataset. |
This method is the exact counterpart to h5WriteScalar().
Definition at line 1864 of file parallelio_pnetcdf.cpp.
|
private |
[out] | scalar | Value to read. |
[in] | name | Name of the dataset. |
This method is the exact counterpart to h5WriteScalar().
Definition at line 1831 of file parallelio_pnetcdf.cpp.
|
private |
This method must be called exactly once for newly created files.
Definition at line 538 of file parallelio_pnetcdf.cpp.
void ParallelIoPNetcdf::b_setAttribute | ( | const MString * | value, |
const MString & | name, | ||
const MString & | datasetName, | ||
const size_type | totalCount | ||
) |
[in] | value | Attribute value. |
[in] | name | Attribute name. |
[in] | datasetName | Dataset (scalar or array) to which the attribute is attached (leave empty for file attributes). |
Definition at line 1938 of file parallelio_pnetcdf.cpp.
|
private |
[in] | value | Attribute value. |
[in] | name | Attribute name. |
[in] | datasetName | Dataset (scalar or array) to which the attribute is attached (leave empty for file attributes). |
Definition at line 1901 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 683 of file parallelio_pnetcdf.cpp.
void ParallelIoPNetcdf::b_writeArray | ( | const MString * | array, |
const MString & | name, | ||
const size_type | noDims, | ||
MPI_Offset * | start, | ||
MPI_Offset * | count, | ||
MPI_Offset | memoryStride, | ||
const size_type | noChunks, | ||
MPI_Offset | diskStride | ||
) |
[in] | array | Pointer to data in memory. |
[in] | name | Name of the dataset. |
[in] | noDims | Number of array dimensions |
[in] | start | Start offset in the file (i.e. the domain should start writing from here). |
[in] | count | Number of elements written from this domain. |
[in] | memoryStride | Stride in memory between data values. |
Definition at line 1436 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 1303 of file parallelio_pnetcdf.cpp.
|
private |
T | Data type of the data to write. |
[in] | array | Pointer to data in memory. |
[in] | name | Name of the dataset. |
[in] | noDims | Number of array dimensions |
[in] | start | Start offset in the file (i.e. the domain should start writing from here). |
[in] | count | Number of elements written from this domain. |
[in] | memoryStride | Stride in memory between data values. |
Definition at line 1336 of file parallelio_pnetcdf.cpp.
[in] | scalar | Value to write. |
[in] | name | Name of the dataset. |
Definition at line 1574 of file parallelio_pnetcdf.cpp.
|
private |
[in] | scalar | Value to write. |
[in] | name | Name of the dataset. |
Definition at line 1543 of file parallelio_pnetcdf.cpp.
void ParallelIoPNetcdf::close | ( | ) |
Definition at line 465 of file parallelio_pnetcdf.cpp.
|
private |
Definition at line 92 of file parallelio_pnetcdf.h.
|
private |
Definition at line 97 of file parallelio_pnetcdf.h.
|
private |
Definition at line 91 of file parallelio_pnetcdf.h.
|
private |
Definition at line 13 of file parallelio_pnetcdf.h.