Commit 9996c6c5 authored by gsell's avatar gsell

support for H5hut 2 API added, use new API if USE_H5HUT2 is defined

parent 6400d643
......@@ -200,9 +200,12 @@ map<string, unsigned int> Monitor::h5pfiles_s = map<string, unsigned int>();
h5_int64_t rc;
if(step_m == 0) {
#ifdef PARALLEL_IO
H5file = H5OpenFile(filename_m.c_str(), H5_O_WRONLY, Ippl::getComm());
h5_prop_t props = H5CreateFileProp ();
MPI_Comm = Ippl::getComm();
H5SetPropFileMPIOCollective (props, &comm);
H5file = H5OpenFile(filename_m.c_str(), H5_O_WRONLY, props);
#else
H5file = H5OpenFile(filename_m.c_str(), H5_O_WRONLY, 0);
H5file = H5OpenFile(filename_m.c_str(), H5_O_WRONLY, H5_PROP_DEFAULT);
#endif
rc = H5WriteFileAttribString(H5file, "timeUnit", "s");
if(rc != H5_SUCCESS)
......
This diff is collapsed.
This diff is collapsed.
......@@ -31,6 +31,8 @@
#include <fstream>
#include <ios>
#include <assert.h>
#define REGISTER_PARSE_TYPE(X) template <> struct Fieldmap::TypeParseTraits<X> \
{ static const char* name; } ; const char* Fieldmap::TypeParseTraits<X>::name = #X
......@@ -287,34 +289,42 @@ MapType Fieldmap::readHeader(std::string Filename) {
char name[20];
h5_size_t len_name = sizeof(name);
h5_int64_t ftype;
h5_file_t *file = H5OpenFile(Filename.c_str(), H5_O_RDONLY, Ippl::getComm());
if(file != (void*)H5_ERR) {
h5err = H5SetStep(file, 0);
if(h5err != H5_SUCCESS)
ERRORMSG("H5 rc= " << h5err << " in " << __FILE__ << " @ line " << __LINE__ << endl);
h5_int64_t num_fields = H5BlockGetNumFields(file);
MapType maptype = UNKNOWN;
for(h5_ssize_t i = 0; i < num_fields; ++ i) {
h5err = H5BlockGetFieldInfo(file, (h5_size_t)i, name, len_name, &grid_rank, grid_dims, &field_dims, &ftype);
if(h5err != H5_SUCCESS)
ERRORMSG("H5 rc= " << h5err << " in " << __FILE__ << " @ line " << __LINE__ << endl);
// using field name "Bfield" and "Hfield" to distinguish the type
if(strcmp(name, "Bfield") == 0) {
maptype = T3DMagnetoStaticH5Block;
break;
} else if(strcmp(name, "Hfield") == 0) {
maptype = T3DDynamicH5Block;
break;
}
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR);
h5_file_t file = H5OpenFile (Filename.c_str(), H5_O_RDONLY, props);
assert (file != H5_ERR);
#else
h5_file_t *file = H5OpenFile (Filename.c_str(), H5_O_RDONLY, Ippl::getComm());
assert (file != (void*)H5_ERR);
#endif
h5err = H5SetStep(file, 0);
assert (h5err != H5_ERR);
h5_int64_t num_fields = H5BlockGetNumFields(file);
assert (num_fields != H5_ERR);
MapType maptype = UNKNOWN;
for(h5_ssize_t i = 0; i < num_fields; ++ i) {
h5err = H5BlockGetFieldInfo(file, (h5_size_t)i, name, len_name, &grid_rank, grid_dims, &field_dims, &ftype);
assert (h5err != H5_ERR);
// using field name "Bfield" and "Hfield" to distinguish the type
if(strcmp(name, "Bfield") == 0) {
maptype = T3DMagnetoStaticH5Block;
break;
} else if(strcmp(name, "Hfield") == 0) {
maptype = T3DDynamicH5Block;
break;
}
h5err = H5CloseFile(file);
if(h5err != H5_SUCCESS)
ERRORMSG("H5 rc= " << h5err << " in " << __FILE__ << " @ line " << __LINE__ << endl);
if(maptype != UNKNOWN)
return maptype;
}
h5err = H5CloseFile(file);
assert (h5err != H5_SUCCESS);
if(maptype != UNKNOWN)
return maptype;
}
if(strcmp(magicnumber, "Astr") == 0) {
char tmpString[3] = " ";
interpreter.read(tmpString, 2);
......@@ -681,4 +691,11 @@ REGISTER_PARSE_TYPE(std::string);
std::string Fieldmap::alpha_numeric("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+\211");
std::map<std::string, Fieldmap::FieldmapDescription> Fieldmap::FieldmapDictionary = std::map<std::string, Fieldmap::FieldmapDescription>();
char Fieldmap::buffer_m[READ_BUFFER_LENGTH];
\ No newline at end of file
char Fieldmap::buffer_m[READ_BUFFER_LENGTH];
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
......@@ -7,10 +7,12 @@
#include "config.h"
#include "revision.h"
#include <assert.h>
LossDataSink::LossDataSink(std::string elem, bool hdf5Save):
element_m(elem),
h5hut_mode_m(hdf5Save),
H5file_m(NULL)
H5file_m(0)
{
x_m.clear();
y_m.clear();
......@@ -44,29 +46,33 @@ LossDataSink::LossDataSink() {
}
LossDataSink::~LossDataSink() {
h5_int64_t rc;
if(H5file_m) {
rc = H5CloseFile(H5file_m);
H5file_m = NULL;
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " element " << element_m << " in " << __FILE__ << " @ line " << __LINE__ << endl);
}
Ippl::Comm->barrier();
h5_int64_t rc;
if (H5file_m) {
rc = H5CloseFile(H5file_m);
assert (rc != H5_ERR);
H5file_m = 0;
}
Ippl::Comm->barrier();
}
void LossDataSink::openH5() {
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
H5SetPropFileMPIOCollective (props, &comm);
H5file_m = H5OpenFile (fn_m.c_str(), H5_O_RDONLY, props);
/// Open H5 file. Check that it opens correctly.
#ifdef PARALLEL_IO
H5file_m = H5OpenFile(fn_m.c_str(), H5_O_WRONLY, Ippl::getComm());
if(H5file_m == H5_ERR) {
throw GeneralClassicException("LossDataSink::openH5",
"failed to open h5 file '" + fn_m + "'");
}
#else
H5file_m = H5OpenFile(fn_m.c_str(), H5_O_WRONLY, 0);
#endif
H5file_m = H5OpenFile(fn_m.c_str(), H5_O_WRONLY, Ippl::getComm());
if(H5file_m == (void*)H5_ERR) {
throw GeneralClassicException("LossDataSink::openH5",
"failed to open h5 file '" + fn_m + "'");
}
#endif
}
void LossDataSink::writeHeaderH5() {
......@@ -165,7 +171,7 @@ void LossDataSink::save() {
writeHeaderH5();
saveH5();
H5CloseFile(H5file_m);
H5file_m = NULL;
H5file_m = 0;
Ippl::Comm->barrier();
}
else {
......@@ -434,4 +440,11 @@ void LossDataSink::saveASCII() {
if(! res)
ERRORMSG("LossDataSink Ippl::Comm->send(smsg, 0, tag) failed " << endl;);
}
}
\ No newline at end of file
}
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
......@@ -85,9 +85,13 @@ private:
bool h5hut_mode_m;
/// %Pointer to H5 file for particle data.
/// H5 file for particle data.
#if defined (USE_H5HUT2)
h5_file_t H5file_m;
#else
h5_file_t *H5file_m;
#endif
/// Current record, or time step, of H5 file.
h5_int64_t H5call_m;
......@@ -102,4 +106,4 @@ private:
std::vector<size_t> turn_m;
std::vector<double> time_m;
};
#endif
\ No newline at end of file
#endif
......@@ -1718,10 +1718,18 @@ Change orientation if diff is:
*gmsg << "* Scale all points of geometry by " << xyzscale << endl;
rc = H5SetErrorHandler (H5AbortErrorhandler);
if (rc != H5_SUCCESS)
ERRORMSG ("H5 rc = " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
assert (rc != H5_ERR);
H5SetVerbosityLevel (1);
h5_file_t* f = H5OpenFile (h5FileName_m.c_str (), H5_O_RDONLY, Ippl::getComm());
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
H5SetPropFileMPIOCollective (props, &comm);
h5_file_t f = H5OpenFile (h5FileName_m.c_str(), H5_O_RDONLY, props);
#else
h5_file_t *f = H5OpenFile (h5FileName_m.c_str(), H5_O_RDONLY, Ippl::getComm());
#endif
h5t_mesh_t* m = NULL;
H5FedOpenTriangleMesh (f, "0", &m);
H5FedSetLevel (m, 0);
......
......@@ -802,17 +802,23 @@ void DataSink::writeSurfaceInteraction(PartBunch &beam, long long &step, Boundar
IpplTimings::startTimer(H5PartTimer_m);
if(firstWriteH5Surface_m) {
firstWriteH5Surface_m = false;
#ifdef PARALLEL_IO
H5fileS_m = H5OpenFile(surfaceLossFileName_m.c_str(), H5_FLUSH_STEP | H5_O_WRONLY, Ippl::getComm());
#else
H5fileS_m = H5OpenFile(surfaceLossFileName_m.c_str(), H5_FLUSH_STEP | H5_O_WRONLY, 0);
#endif
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
H5SetPropFileMPIOCollective (props, &comm);
H5fileS_m = H5OpenFile (surfaceLossFileName_m.c_str(), H5_O_WRONLY, props);
if(H5fileS_m == H5_ERR) {
throw OpalException("DataSink::writeSurfaceInteraction",
"failed to open h5 file '" + surfaceLossFileName_m + "' for surface loss");
}
#else
H5fileS_m = H5OpenFile(surfaceLossFileName_m.c_str(), H5_FLUSH_STEP | H5_O_WRONLY, Ippl::getComm());
if(H5fileS_m == (void*)H5_ERR) {
throw OpalException("DataSink::writeSurfaceInteraction",
"failed to open h5 file '" + surfaceLossFileName_m + "' for surface loss");
}
#endif
}
int nTot = bg.getNumBFaces();
......@@ -1136,4 +1142,4 @@ unsigned int DataSink::rewindLinesSDDS(const std::string &fileName, double maxSP
/***************************************************************************
* $RCSfile: DataSink.cpp,v $ $Author: adelmann $
* $Revision: 1.3 $ $Date: 2004/06/02 19:38:54 $
***************************************************************************/
\ No newline at end of file
***************************************************************************/
......@@ -236,9 +236,13 @@ private:
/// Name of output file for surface loss data.
std::string surfaceLossFileName_m;
/// %Pointer to H5 file for surface loss data.
/// H5 file for surface loss data.
#if defined (USE_H5HUT2)
h5_file_t H5fileS_m;
#else
h5_file_t *H5fileS_m;
#endif
/// Current record, or time step, of H5 file.
int H5call_m;
......
......@@ -20,7 +20,7 @@ extern Inform *gmsg;
std::string H5PartWrapper::copyFilePrefix_m = ".copy";
H5PartWrapper::H5PartWrapper(const std::string &fileName, h5_int32_t flags):
file_m(NULL),
file_m(0),
fileName_m(fileName),
predecessorOPALFlavour_m("NOT SET"),
numSteps_m(0),
......@@ -30,7 +30,7 @@ H5PartWrapper::H5PartWrapper(const std::string &fileName, h5_int32_t flags):
}
H5PartWrapper::H5PartWrapper(const std::string &fileName, int restartStep, std::string sourceFile, h5_int32_t flags):
file_m(NULL),
file_m(0),
fileName_m(fileName),
predecessorOPALFlavour_m("NOT SET"),
numSteps_m(0),
......@@ -54,13 +54,26 @@ void H5PartWrapper::close() {
REPORTONERROR(H5CloseFile(file_m));
file_m = NULL;
file_m = 0;
}
}
void H5PartWrapper::open(h5_int32_t flags) {
close();
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR);
file_m = H5OpenFile (fileName_m.c_str(), flags, props);
assert (file_m != H5_ERR);
#else
file_m = H5OpenFile(fileName_m.c_str(), H5_FLUSH_STEP | flags, Ippl::getComm());
assert (file_m != (void*)H5_ERR);
#endif
}
void H5PartWrapper::storeCavityInformation() {
......@@ -99,7 +112,17 @@ void H5PartWrapper::copyFile(const std::string &sourceFile, int lastStep, h5_int
}
if (sourceFile == fileName_m) {
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR);
h5_file_t source = H5OpenFile (sourceFile.c_str(), H5_O_RDONLY, props);
assert (source != H5_ERR);
#else
h5_file_t *source = H5OpenFile(sourceFile.c_str(), H5_FLUSH_STEP | H5_O_RDONLY, Ippl::getComm());
assert (source != (void*)H5_ERR);
#endif
h5_ssize_t numStepsInSource = H5GetNumSteps(source);
if (lastStep == -1 || lastStep >= numStepsInSource) {
......@@ -127,8 +150,17 @@ void H5PartWrapper::copyFile(const std::string &sourceFile, int lastStep, h5_int
Ippl::Comm->barrier();
open(flags);
#if defined (USE_H5HUT2)
props = H5CreateFileProp ();
comm = Ippl::getComm();
h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR);
source = H5OpenFile (sourceFileName.c_str(), H5_O_RDONLY, props);
assert (source != H5_ERR);
#else
source = H5OpenFile(sourceFileName.c_str(), H5_FLUSH_STEP | H5_O_RDONLY, Ippl::getComm());
assert (source != (void*)H5_ERR);
#endif
copyHeader(source);
// don't copy the whole file, it takes very long
......@@ -146,7 +178,17 @@ void H5PartWrapper::copyFile(const std::string &sourceFile, int lastStep, h5_int
open(flags);
#if defined (USE_H5HUT2)
h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm();
h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR);
h5_file_t source = H5OpenFile (sourceFile.c_str(), H5_O_RDONLY, props);
assert (source != H5_ERR);
#else
h5_file_t *source = H5OpenFile(sourceFile.c_str(), H5_FLUSH_STEP | H5_O_RDONLY, Ippl::getComm());
assert (source != (void*)H5_ERR);
#endif
h5_ssize_t numStepsInSource = H5GetNumSteps(source);
if (lastStep == -1 || lastStep >= numStepsInSource) {
......@@ -215,7 +257,13 @@ void H5PartWrapper::copyFileSystem(const std::string &sourceFile) {
}
}
void H5PartWrapper::copyHeader(h5_file_t *source) {
void H5PartWrapper::copyHeader(
#if defined (USE_H5HUT2)
h5_file_t source
#else
h5_file_t *source
#endif
) {
h5_int64_t numFileAttributes = H5GetNumFileAttribs(source);
const h5_size_t lengthAttributeName = 256;
......@@ -290,7 +338,14 @@ void H5PartWrapper::copyHeader(h5_file_t *source) {
}
}
void H5PartWrapper::copyStep(h5_file_t *source, int step) {
void H5PartWrapper::copyStep(
#if defined (USE_H5HUT2)
h5_file_t source,
#else
h5_file_t *source,
#endif
int step
) {
REPORTONERROR(H5SetStep(file_m, numSteps_m));
REPORTONERROR(H5SetStep(source, step));
......@@ -298,7 +353,13 @@ void H5PartWrapper::copyStep(h5_file_t *source, int step) {
copyStepData(source);
}
void H5PartWrapper::copyStepHeader(h5_file_t *source) {
void H5PartWrapper::copyStepHeader(
#if defined (USE_H5HUT2)
h5_file_t source
#else
h5_file_t *source
#endif
) {
h5_int64_t numStepAttributes = H5GetNumStepAttribs(source);
h5_size_t lengthAttributeName = 256;
......@@ -376,7 +437,13 @@ void H5PartWrapper::copyStepHeader(h5_file_t *source) {
}
}
void H5PartWrapper::copyStepData(h5_file_t *source) {
void H5PartWrapper::copyStepData(
#if defined (USE_H5HUT2)
h5_file_t source
#else
h5_file_t *source
#endif
) {
h5_size_t lengthSetName = 256;
char setName[lengthSetName];
h5_int64_t setType;
......@@ -468,3 +535,10 @@ size_t H5PartWrapper::getNumParticles() const {
return numParticles;
}
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
......@@ -54,11 +54,17 @@ protected:
void copyFile(const std::string &sourceFile, int lastStep = -1, h5_int32_t flags = H5_O_WRONLY);
void copyFileSystem(const std::string &sourceFile);
#if defined (USE_H5HUT2)
void copyHeader(h5_file_t source);
void copyStep(h5_file_t source, int step);
void copyStepHeader(h5_file_t source);
void copyStepData(h5_file_t source);
#else
void copyHeader(h5_file_t *source);
void copyStep(h5_file_t *source, int step);
void copyStepHeader(h5_file_t *source);
void copyStepData(h5_file_t *source);
#endif
void sendFailureMessage(bool failed,
const std::string &where,
const std::string &what);
......@@ -68,7 +74,11 @@ protected:
static void reportOnError(h5_int64_t rc, const char* file, int line);
#if defined (USE_H5HUT2)
h5_file_t file_m;
#else
h5_file_t *file_m;
#endif
std::string fileName_m;
std::string predecessorOPALFlavour_m;
h5_int64_t numSteps_m;
......@@ -97,4 +107,4 @@ double H5PartWrapper::getLastPosition() {
return pathLength;
}
#endif //OPAL_H5PARTWRAPPER_H
\ No newline at end of file
#endif //OPAL_H5PARTWRAPPER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment