4d double, 4d int); fixed error in RestartInfo output; added the maximum length of the engine state string into sim_constants.h
607 lines
21 KiB
C++
Executable File
607 lines
21 KiB
C++
Executable File
#include "IO/hdf5_writer.h"
|
|
|
|
#include <hdf5.h>
|
|
#include <hdf5_hl.h>
|
|
#include <sys/stat.h>
|
|
#include <iostream>
|
|
#include "simulation/errors.h"
|
|
#include "constants/sim_constants.h"
|
|
|
|
#include "simulation/mpi_communication.h"
|
|
|
|
Hdf5Writer::Hdf5Writer(std::string directory, std::string filename)
|
|
: absolute_filename_((directory + "/" + filename + ".h5").c_str()) {
|
|
createFolder(directory);
|
|
createFile(absolute_filename_);
|
|
}
|
|
|
|
void Hdf5Writer::createFolder(std::string directory) {
|
|
mkdir(directory.c_str(), 0755);
|
|
}
|
|
|
|
void Hdf5Writer::createFile(std::string absolute_filename) {
|
|
if (MpiCommunication::mpi_rank == 0) {
|
|
hid_t file = H5Fcreate(absolute_filename.c_str(), H5F_ACC_TRUNC,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
H5Fclose(file);
|
|
}
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::Array<double, 1>& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
blitz::TinyVector<int, 1> size = data.extent();
|
|
int start = 0;
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
hid_t memoryspace =
|
|
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
// select a part of the disc space
|
|
H5Sselect_hyperslab(filespace, H5S_SELECT_SET,
|
|
blitz::TinyVector<hsize_t, 1>(start).data(), NULL,
|
|
blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
// select a part of the memory space, in this case all
|
|
H5Sselect_hyperslab(
|
|
memoryspace, H5S_SELECT_SET,
|
|
blitz::TinyVector<hsize_t, 1>(blitz::TinyVector<int, 1>(0)).data(), NULL,
|
|
blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Sclose(memoryspace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::Array<double, 2>& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
blitz::TinyVector<int, 2> size = data.extent();
|
|
blitz::TinyVector<int, 2> start(0, 0);
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(2, blitz::TinyVector<hsize_t, 2>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::Array<double, 3>& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
blitz::TinyVector<int, 3> size = data.extent();
|
|
blitz::TinyVector<int, 3> start(0, 0, 0);
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(3, blitz::TinyVector<hsize_t, 3>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::Array<double, 4>& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
blitz::TinyVector<int, 4> size = data.extent();
|
|
blitz::TinyVector<int, 4> start(0, 0, 0, 0);
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(4, blitz::TinyVector<hsize_t, 4>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, filespace, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
|
|
std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
blitz::TinyVector<int, 4> size = data.extent();
|
|
blitz::TinyVector<int, 4> start(0, 0, 0, 0);
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(4, blitz::TinyVector<hsize_t, 4>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_LONG, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::TinyVector<double, 3>& data,
|
|
std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
int size = 3;
|
|
int start = 0;
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const blitz::TinyVector<int, 3>& data,
|
|
std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
int size = 3;
|
|
int start = 0;
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_INT, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const std::vector<double>& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
int size = data.size();
|
|
int start = 0;
|
|
|
|
hid_t filespace =
|
|
H5Screate_simple(1, blitz::TinyVector<hsize_t, 1>(size).data(), NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
|
data.data());
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(int data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
hsize_t scalar = 1;
|
|
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_INT, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(long int data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
hsize_t scalar = 1;
|
|
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_LONG, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(double data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
hsize_t scalar = 1;
|
|
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_DOUBLE, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
|
|
|
|
H5Dclose(dataset);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
void Hdf5Writer::write(const std::string& data, std::string path) {
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
hsize_t scalar = 1;
|
|
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
hid_t dtype;
|
|
dtype = H5Tcreate(H5T_STRING, data.size());
|
|
// see:https://stackoverflow.com/questions/581209/how-to-best-write-out-a-stdvector-stdstring-container-to-a-hdf5-dataset
|
|
// for the way to create a variable length dtype and how to write it
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
hid_t dataset;
|
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
if (dataset < 0) {
|
|
dataset = H5Dcreate2(file, path.c_str(), dtype, filespace, lcpl,
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
|
|
H5Dwrite(dataset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data.c_str());
|
|
|
|
H5Dclose(dataset);
|
|
H5Tclose(dtype);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
}
|
|
|
|
// maybe split into a function that writes a string in parallel and one that writes an
|
|
// int in parallel. Would be a bit more effort but it would be more consistent with the
|
|
// way the rest of the writer functions work
|
|
|
|
// writes a string-representation of an random numbers engine (right now assumed mt19973)
|
|
// written output: input string padded with 0 at the end to achieve a fixed length
|
|
// and the size of the input string
|
|
void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
|
/*
|
|
* Note:
|
|
* Writing the string representation of the std::mt19973 engine might not be the best option.
|
|
* (see comment for statStringSizeMax_ in hdf5_writer.h)
|
|
* The potential issues are: de-serialization using '>>' not platform independent (i.e. can not be
|
|
* restarted), length of the max size uncertain, relatively large storage space usage (>6370 bytes/cpu/output)
|
|
* (comparision: HAWK: size of file ~ 3.4MB/sync, RestartInfo Size (estimate) ~ 81MB/sync (12800 procs))
|
|
*
|
|
* Second option: wrapper for the engine and count the times its been used and store that number.
|
|
* Also has an issue with restarts on a different platform (since engine implementation is platform dependent).
|
|
* Signigicantly lower storage space usage. Restoring the engine state would easy in implementation
|
|
* (potentially a bit more expensive in execution time: discard() function).
|
|
*/
|
|
|
|
MPI_Info info;
|
|
MPI_Info_create(&info);
|
|
hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
|
|
H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, info);
|
|
// MPI_Info_free(&info);
|
|
|
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, fapl);
|
|
|
|
if(file < 0) {
|
|
SIM_INFO("file could not be opened");
|
|
}
|
|
hsize_t scalar = 1;
|
|
hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
int mpi_rank = MpiCommunication::mpiRank();
|
|
std::string out{data};
|
|
|
|
size_t stateStringSize = out.size();
|
|
|
|
if(stateStringSize > SimConstants::engine_string_length_max) {
|
|
ERROR("Max Size (" + std::to_string(SimConstants::engine_string_length_max) + ") too small. String size: " + std::to_string(stateStringSize));
|
|
}
|
|
|
|
out.insert(out.end(), (SimConstants::engine_string_length_max - stateStringSize), '0');
|
|
|
|
// apperently it's not possible to use 'H5T_VARIABLE' with the MPI-I/O file driver
|
|
// (since it doesn't allow for variable size objects to be created, see: https://davis.lbl.gov/Manuals/HDF5-1.8.7/TechNotes/VLTypes.html)
|
|
hid_t dtype = H5Tcreate(H5T_STRING, SimConstants::engine_string_length_max);
|
|
|
|
// store old error stack info
|
|
H5E_auto2_t oldfunc;
|
|
void* old_client_data;
|
|
H5Eget_auto2(H5E_DEFAULT, &oldfunc, &old_client_data);
|
|
|
|
// turn of error report by hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
|
|
for(int i = 0; i < MpiCommunication::mpiSize(); ++i) {
|
|
std::string path = path_base + std::to_string(i);
|
|
DEBUG_LEVEL_3(path);
|
|
hid_t dataset_string = H5Dcreate2(file, (path + "/string").c_str(), dtype, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
|
// this sadly seems to be the option that takes the least amount of effort.
|
|
// H5Lexits() would be an option but (!) each group would need to be checked for existance first, which sucks
|
|
if(dataset_string < 0) {
|
|
DEBUG_LEVEL_3("Dataset could not be created");
|
|
dataset_string = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
|
if(dataset_string < 0) {
|
|
ERROR("Dataset for string can neither be created nor opened");
|
|
}
|
|
}
|
|
|
|
hid_t dataset_length = H5Dcreate2(file, (path + "/length").c_str(), H5T_NATIVE_HSIZE, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
|
if(dataset_length < 0) {
|
|
DEBUG_LEVEL_3("Dataset could not be created");
|
|
dataset_length = H5Dopen2(file, (path + "/length").c_str(), H5P_DEFAULT);
|
|
if(dataset_length < 0) {
|
|
ERROR("Dataset for length can neither be created nor opened");
|
|
}
|
|
}
|
|
|
|
if(i == mpi_rank) {
|
|
H5Dwrite(dataset_string, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, out.c_str());
|
|
H5Dwrite(dataset_length, H5T_NATIVE_HSIZE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &stateStringSize);
|
|
}
|
|
H5Dclose(dataset_string);
|
|
H5Dclose(dataset_length);
|
|
}
|
|
// turn error report back onby hdf5 because of check H5Dopen2
|
|
H5Eset_auto(H5E_DEFAULT, oldfunc, old_client_data);
|
|
|
|
H5Tclose(dtype);
|
|
H5Pclose(lcpl);
|
|
H5Sclose(filespace);
|
|
H5Fclose(file);
|
|
H5Pclose(fapl);
|
|
}
|
|
|
|
// Debug utility
|
|
std::string Hdf5Writer::AbsoluteFileName() const {
|
|
return absolute_filename_;
|
|
}
|
|
|
|
// testing function for the parallel output
|
|
|
|
// void Hdf5Writer::writeRNG(std::string path_base) {
|
|
// MPI_Info info;
|
|
// MPI_Info_create(&info);
|
|
// hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
|
|
// H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, info);
|
|
// // MPI_Info_free(&info);
|
|
|
|
// hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, fapl);
|
|
|
|
// if(file < 0) {
|
|
// SIM_INFO("file could not be opened");
|
|
// }
|
|
// hsize_t scalar = 1;
|
|
// hid_t filespace = H5Screate_simple(1, &scalar, NULL);
|
|
|
|
// hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
// H5Pset_create_intermediate_group(lcpl, 1);
|
|
|
|
// int mpi_rank = MpiCommunication::mpiRank();
|
|
// std::string out = "Hello from proc " + std::to_string(mpi_rank);
|
|
// out.insert(out.end(), mpi_rank, '0' + mpi_rank);
|
|
|
|
// const size_t maxSize = 25;
|
|
// size_t stringSize = out.size();
|
|
|
|
// if(stringSize > maxSize) {
|
|
// ERROR("Max Size (" + std::to_string(maxSize) + ") too small. String size: " + std::to_string(stringSize));
|
|
// }
|
|
|
|
// out.insert(out.end(), (maxSize - stringSize), '0');
|
|
|
|
// // apperently it's not possible to use 'H5T_VARIABLE' with the MPI-I/O file driver
|
|
// // (since it doesn't allow for variable size objects to be created, see: https://davis.lbl.gov/Manuals/HDF5-1.8.7/TechNotes/VLTypes.html)
|
|
// hid_t dtype = H5Tcreate(H5T_STRING, maxSize);
|
|
|
|
// // store old error stack info
|
|
// H5E_auto2_t oldfunc;
|
|
// void* old_client_data;
|
|
// H5Eget_auto2(H5E_DEFAULT, &oldfunc, &old_client_data);
|
|
|
|
// // turn of error report by hdf5 because of check H5Dopen2
|
|
// H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
|
|
// for(int i = 0; i < MpiCommunication::mpiSize(); ++i) {
|
|
// std::string path = path_base + std::to_string(i);
|
|
// DEBUG_LEVEL_3(path);
|
|
// hid_t dataset_string = H5Dcreate2(file, (path + "/string").c_str(), dtype, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
|
// // this sadly seems to be the option that takes the least amount of effort.
|
|
// // H5Lexits() would be an option but (!) each group would need to be checked for existance first, which sucks
|
|
// if(dataset_string < 0) {
|
|
// DEBUG_LEVEL_3("Dataset could not be created");
|
|
// dataset_string = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
|
// if(dataset_string < 0) {
|
|
// ERROR("Dataset for string can neither be created nor opened");
|
|
// }
|
|
// }
|
|
|
|
// hid_t dataset_length = H5Dcreate2(file, (path + "/length").c_str(), H5T_NATIVE_HSIZE, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
|
// if(dataset_length < 0) {
|
|
// DEBUG_LEVEL_3("Dataset could not be created");
|
|
// dataset_length = H5Dopen2(file, (path + "/length").c_str(), H5P_DEFAULT);
|
|
// if(dataset_length < 0) {
|
|
// ERROR("Dataset for length can neither be created nor opened");
|
|
// }
|
|
// }
|
|
|
|
// if(i == mpi_rank) {
|
|
// const char* out_ptr = out.c_str();
|
|
// H5Dwrite(dataset_string, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, out_ptr);
|
|
// H5Dwrite(dataset_length, H5T_NATIVE_HSIZE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &stringSize);
|
|
// }
|
|
// H5Dclose(dataset_string);
|
|
// H5Dclose(dataset_length);
|
|
// }
|
|
// // turn error report back onby hdf5 because of check H5Dopen2
|
|
// H5Eset_auto(H5E_DEFAULT, oldfunc, old_client_data);
|
|
|
|
// H5Tclose(dtype);
|
|
// H5Pclose(lcpl);
|
|
// H5Sclose(filespace);
|
|
// H5Fclose(file);
|
|
// H5Pclose(fapl);
|
|
// }
|