diff options
-rw-r--r-- | src/DumpUtils.c | 66 | ||||
-rw-r--r-- | src/DumpVar.c | 76 | ||||
-rw-r--r-- | src/RecoverVar.c | 66 | ||||
-rw-r--r-- | src/Startup.c | 32 | ||||
-rw-r--r-- | src/ioHDF5UtilGH.h | 87 |
5 files changed, 225 insertions, 102 deletions
diff --git a/src/DumpUtils.c b/src/DumpUtils.c index 50e7c56..1393787 100644 --- a/src/DumpUtils.c +++ b/src/DumpUtils.c @@ -457,3 +457,69 @@ void IOHDF5Util_DumpGHExtensions (cGH *GH, IOHDF5_ERROR (H5Gclose (group)); } + + +/*@@ + @routine IOHDF5Util_DataType + @author Thomas Radke + @date Mon 11 June 2001 + @desc + Returns the HDF5 datatype for a given CCTK datatype + @enddesc + + @var myGH + @vdesc Pointer to IOHDF5Util's GH extensions + @vtype ioHDF5UtilGH * + @vio in + @endvar + @var cctk_type + @vdesc CCTK datatype + @vtype int + @vio in + @endvar + + @returntype hid_t + @returndesc + the appropriate HDF5 datatype for success, or -1 otherwise + @endreturndesc +@@*/ +hid_t IOHDF5Util_DataType (const ioHDF5UtilGH *myGH, int cctk_type) +{ + hid_t retval; + + + switch (cctk_type) + { + case CCTK_VARIABLE_CHAR: retval = IOHDF5_CHAR; break; + case CCTK_VARIABLE_INT: retval = IOHDF5_INT; break; + case CCTK_VARIABLE_REAL: retval = IOHDF5_REAL; break; + case CCTK_VARIABLE_COMPLEX: retval = myGH->IOHDF5_COMPLEX; break; +#ifdef CCTK_INT2 + case CCTK_VARIABLE_INT2: retval = IOHDF5_INT2; break; +#endif +#ifdef CCTK_INT4 + case CCTK_VARIABLE_INT4: retval = IOHDF5_INT4; break; +#endif +#ifdef CCTK_INT8 + case CCTK_VARIABLE_INT8: retval = IOHDF5_INT8; break; +#endif +#ifdef CCTK_REAL4 + case CCTK_VARIABLE_REAL4: retval = IOHDF5_REAL4; break; + case CCTK_VARIABLE_COMPLEX8: retval = myGH->IOHDF5_COMPLEX8; break; +#endif +#ifdef CCTK_REAL8 + case CCTK_VARIABLE_REAL8: retval = IOHDF5_REAL8; break; + case CCTK_VARIABLE_COMPLEX16: retval = myGH->IOHDF5_COMPLEX16; break; +#endif +#ifdef CCTK_REAL16 + case CCTK_VARIABLE_REAL16: retval = IOHDF5_REAL16; break; + case CCTK_VARIABLE_COMPLEX32: retval = myGH->IOHDF5_COMPLEX32; break; +#endif + + default: CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported CCTK variable datatype %d", cctk_type); + retval = -1; + } + + return (retval); +} diff --git a/src/DumpVar.c b/src/DumpVar.c index 4cc6b00..7feb035 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -21,7 +21,7 @@ /* the rcs ID and its dummy function to use it */ -static const char *rcsid = "$Id$"; +static const char *rcsid = "$Header$"; CCTK_FILEVERSION(BetaThorns_IOHDF5Util_DumpVar_c) /* #define DEBUG_ME 1 */ @@ -146,7 +146,7 @@ int IOHDF5Util_DumpVar (cGH *GH, hid_t file, int check_exisiting_objects) { - int gtype; + int vtype, gtype; pGH *pughGH; ioHDF5UtilGH *myGH; ioGH *ioUtilGH; @@ -159,49 +159,43 @@ int IOHDF5Util_DumpVar (cGH *GH, ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); myGH = (ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); - switch (CCTK_VarTypeI (vindex)) + vtype = CCTK_VarTypeI (vindex); + /* downgrade the output precision if requested */ + if (ioUtilGH->out_single) { - case CCTK_VARIABLE_CHAR: - info.iohdf5_type = IOHDF5_CHAR; - info.element_size = sizeof (CCTK_CHAR); -#ifdef CCTK_MPI - info.mpi_type = PUGH_MPI_CHAR; + /* Do we only want to downgrade generic CCTK types ? */ +#ifdef CCTK_REAL4 + if (vtype == CCTK_VARIABLE_REAL) + { + vtype = CCTK_VARIABLE_REAL4; + } + else if (vtype == CCTK_VARIABLE_COMPLEX) + { + vtype = CCTK_VARIABLE_COMPLEX8; + } #endif - break; - - case CCTK_VARIABLE_INT: - info.iohdf5_type = IOHDF5_INT; - info.element_size = sizeof (CCTK_INT); -#ifdef CCTK_MPI - info.mpi_type = PUGH_MPI_INT; +#ifdef CCTK_INT4 + if (vtype == CCTK_VARIABLE_INT) + { + vtype = CCTK_VARIABLE_INT4; + } #endif - break; - - case CCTK_VARIABLE_REAL: - info.iohdf5_type = ioUtilGH->out_single ? IOHDF5_REAL4 : IOHDF5_REAL; - info.element_size = ioUtilGH->out_single ? - sizeof (CCTK_REAL4) : sizeof (CCTK_REAL); + } + info.element_size = CCTK_VarTypeSize (vtype); #ifdef CCTK_MPI - info.mpi_type = ioUtilGH->out_single ? PUGH_MPI_REAL4 : PUGH_MPI_REAL; + info.mpi_type = PUGH_MPIDataType (pughGH, vtype); #endif - break; + info.iohdf5_type = IOHDF5Util_DataType (myGH, vtype); - case CCTK_VARIABLE_COMPLEX: - info.iohdf5_type = ioUtilGH->out_single ? myGH->IOHDF5_COMPLEX8 : - myGH->IOHDF5_COMPLEX; - info.element_size = ioUtilGH->out_single ? - sizeof (CCTK_COMPLEX8) : sizeof (CCTK_COMPLEX); + if (info.element_size <= 0 || #ifdef CCTK_MPI - info.mpi_type = ioUtilGH->out_single ? pughGH->PUGH_mpi_complex8 : - pughGH->PUGH_mpi_complex; + info.mpi_type == MPI_DATATYPE_NULL || #endif - break; - - default: - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unsupported variable datatype '%s'", - CCTK_VarTypeName (CCTK_VarTypeI (vindex))); - return (-1); + info.iohdf5_type < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported variable type %d", vtype); + return (-1); } /* now branch to the appropriate dump routine */ @@ -560,11 +554,14 @@ static int IOHDF5Util_getDumpData (cGH *GH, cctk_output_type = CCTK_VarTypeI (vindex); if (ioUtilGH->out_single) { +#ifdef CCTK_INT4 if (cctk_output_type == CCTK_VARIABLE_INT) { cctk_output_type = CCTK_VARIABLE_INT4; } - else if (cctk_output_type == CCTK_VARIABLE_REAL) +#endif +#ifdef CCTK_REAL4 + if (cctk_output_type == CCTK_VARIABLE_REAL) { cctk_output_type = CCTK_VARIABLE_REAL4; } @@ -572,6 +569,7 @@ static int IOHDF5Util_getDumpData (cGH *GH, { cctk_output_type = CCTK_VARIABLE_COMPLEX8; } +#endif } /* FIXME */ @@ -601,7 +599,7 @@ static int IOHDF5Util_getDumpData (cGH *GH, if (NewHyperslab_GetLocalHyperslab (GH, vindex, timelevel, request->sdim, cctk_output_type, NULL, request->origin, request->direction, request->length, - request->downsample, outme, + request->downsample, 1, outme, free_outme, hsizes, hsizes_global, hsizes_offset) < 0) { fullname = CCTK_FullName (vindex); diff --git a/src/RecoverVar.c b/src/RecoverVar.c index ca23d2a..0195416 100644 --- a/src/RecoverVar.c +++ b/src/RecoverVar.c @@ -451,13 +451,16 @@ static int GetCommonAttributes (cGH *GH, /* The CCTK variable type defines do not correlate with the HDF5 defines so compare them explicitely here. */ flag = (H5Tget_class (datatype) == H5T_FLOAT && - group_static_data.vartype == CCTK_VARIABLE_REAL) || + strncmp (CCTK_VarTypeName (group_static_data.vartype), + "CCTK_VARIABLE_REAL", 18) == 0) || (H5Tget_class (datatype) == H5T_INTEGER && - group_static_data.vartype == CCTK_VARIABLE_INT) || - (H5Tget_class (datatype) == H5T_INTEGER && - group_static_data.vartype == CCTK_VARIABLE_CHAR) || + (strncmp (CCTK_VarTypeName (group_static_data.vartype), + "CCTK_VARIABLE_INT", 17) == 0 || + strcmp (CCTK_VarTypeName (group_static_data.vartype), + "CCTK_VARIABLE_CHAR") == 0)) || (H5Tget_class (datatype) == H5T_COMPOUND && - group_static_data.vartype == CCTK_VARIABLE_COMPLEX); + strncmp (CCTK_VarTypeName (group_static_data.vartype), + "CCTK_VARIABLE_COMPLEX", 21) == 0); IOHDF5_ERROR (H5Tclose (datatype)); if (! flag) @@ -715,8 +718,8 @@ static herr_t processDataset (hid_t group, DECLARE_CCTK_PARAMETERS pGH *pughGH; ioGH *ioUtilGH; - ioHDF5UtilGH *h5UtilGH; - int vindex, gtype, timelevel; + ioHDF5UtilGH *myGH; + int vindex, vtype, gtype, timelevel; iterate_info_t *it_info = (iterate_info_t *) arg; recover_info_t rec_info; hid_t dataset; @@ -734,7 +737,7 @@ static herr_t processDataset (hid_t group, /* Get the handle for PUGH, IOUtil, and IOHDF5Util extensions */ pughGH = PUGH_pGH (it_info->GH); ioUtilGH = (ioGH *) CCTK_GHExtension (it_info->GH, "IO"); - h5UtilGH = (ioHDF5UtilGH *) CCTK_GHExtension (it_info->GH, "IOHDF5Util"); + myGH = (ioHDF5UtilGH *) CCTK_GHExtension (it_info->GH, "IOHDF5Util"); IOHDF5_ERROR (H5Gget_objinfo (group, datasetname, 0, &object_info)); is_group = object_info.type == H5G_GROUP; @@ -781,47 +784,22 @@ static herr_t processDataset (hid_t group, free (varname); } + vtype = CCTK_VarTypeI (vindex); rec_info.it_info = it_info; - - switch (CCTK_VarTypeI (vindex)) - { - case CCTK_VARIABLE_CHAR: - rec_info.iohdf5_type = IOHDF5_CHAR; - rec_info.element_size = sizeof (CCTK_CHAR); -#ifdef CCTK_MPI - rec_info.mpi_type = PUGH_MPI_CHAR; -#endif - break; - - case CCTK_VARIABLE_INT: - rec_info.iohdf5_type = IOHDF5_INT; - rec_info.element_size = sizeof (CCTK_INT); + rec_info.element_size = CCTK_VarTypeSize (vtype); #ifdef CCTK_MPI - rec_info.mpi_type = PUGH_MPI_INT; + rec_info.mpi_type = PUGH_MPIDataType (pughGH, vtype); #endif - break; - - case CCTK_VARIABLE_REAL: - rec_info.iohdf5_type = IOHDF5_REAL; - rec_info.element_size = sizeof (CCTK_REAL); + rec_info.iohdf5_type = IOHDF5Util_DataType (myGH, vtype); + if (rec_info.element_size <= 0 || #ifdef CCTK_MPI - rec_info.mpi_type = PUGH_MPI_REAL; + rec_info.mpi_type == MPI_DATATYPE_NULL || #endif - break; - - case CCTK_VARIABLE_COMPLEX: - rec_info.iohdf5_type = h5UtilGH->IOHDF5_COMPLEX; - rec_info.element_size = sizeof (CCTK_COMPLEX); -#ifdef CCTK_MPI - rec_info.mpi_type = pughGH->PUGH_mpi_complex; -#endif - break; - - default: - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unsupported variable datatype '%s'", - CCTK_VarTypeName (CCTK_VarTypeI (vindex))); - return (0); + rec_info.iohdf5_type < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported variable datatype %d", vtype); + return (1); } /* Read in the data */ diff --git a/src/Startup.c b/src/Startup.c index f6e398d..710e35c 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -98,10 +98,24 @@ void IOHDF5Util_Terminate (cGH *GH) { IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX)); } +#ifdef CCTK_REAL4 if (myGH->IOHDF5_COMPLEX8 >= 0) { IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX8)); } +#endif +#ifdef CCTK_REAL8 + if (myGH->IOHDF5_COMPLEX16 >= 0) + { + IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX16)); + } +#endif +#ifdef CCTK_REAL16 + if (myGH->IOHDF5_COMPLEX32 >= 0) + { + IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_COMPLEX32)); + } +#endif if (myGH->IOHDF5_STRING >= 0) { IOHDF5_ERROR (H5Tclose (myGH->IOHDF5_STRING)); @@ -156,12 +170,30 @@ static void *IOHDF5Util_SetupGH (tFleshConfig *config, offsetof (CCTK_COMPLEX, Re), IOHDF5_REAL)); IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX, "imag", offsetof (CCTK_COMPLEX, Im), IOHDF5_REAL)); +#ifdef CCTK_REAL4 IOHDF5_ERROR (myGH->IOHDF5_COMPLEX8 = H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX8))); IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX8, "real", offsetof (CCTK_COMPLEX8, Re), IOHDF5_REAL4)); IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX8, "imag", offsetof (CCTK_COMPLEX8, Im), IOHDF5_REAL4)); +#endif +#ifdef CCTK_REAL8 + IOHDF5_ERROR (myGH->IOHDF5_COMPLEX16 = + H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX16))); + IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX16, "real", + offsetof (CCTK_COMPLEX16, Re), IOHDF5_REAL8)); + IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX16, "imag", + offsetof (CCTK_COMPLEX16, Im), IOHDF5_REAL8)); +#endif +#ifdef CCTK_REAL16 + IOHDF5_ERROR (myGH->IOHDF5_COMPLEX32 = + H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX32))); + IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX32, "real", + offsetof (CCTK_COMPLEX32, Re), IOHDF5_REAL16)); + IOHDF5_ERROR (H5Tinsert (myGH->IOHDF5_COMPLEX32, "imag", + offsetof (CCTK_COMPLEX32, Im), IOHDF5_REAL16)); +#endif /* predefine a C string datatype */ IOHDF5_ERROR (myGH->IOHDF5_STRING = H5Tcopy (H5T_C_S1)); diff --git a/src/ioHDF5UtilGH.h b/src/ioHDF5UtilGH.h index a5d1a16..211d999 100644 --- a/src/ioHDF5UtilGH.h +++ b/src/ioHDF5UtilGH.h @@ -2,9 +2,10 @@ @header ioHDF5UtilGH.h @date Fri Oct 6 2000 @author Thomas Radke - @desc + @desc The GH extensions structure for IOHDF5Util. - @version $Id$ + @enddesc + @version $Id$ @@*/ #ifndef _IOUTILHDF5_IOUTILHDF5GH_H_ @@ -106,22 +107,67 @@ } while (0) -/* Mapping off CCTK datatypes to HDF5 datatypes */ -#define IOHDF5_REAL4 H5T_NATIVE_FLOAT +/*** + Define the different datatypes used for HDF5 I/O + NOTE: the complex datatype is defined dynamically at runtime in Startup.c + ***/ +/* char type is easy */ +#define IOHDF5_CHAR H5T_NATIVE_CHAR + +/* floating point types are architecture-independent, + ie. a float has always 4 bytes, and a double has 8 bytes + + IOHDF5_REAL is used for storing reals of the generic CCTK_REAL type + IOHDF5_REALn is used to explicitely store n-byte reals */ +#ifdef CCTK_REAL4 +#define IOHDF5_REAL4 H5T_NATIVE_FLOAT +#endif +#ifdef CCTK_REAL8 +#define IOHDF5_REAL8 H5T_NATIVE_DOUBLE +#endif +#ifdef CCTK_REAL16 +#define IOHDF5_REAL16 (sizeof (CCTK_REAL16) == sizeof (long double) ? \ + H5T_NATIVE_LDOUBLE : -1) +#endif + #ifdef CCTK_REAL_PRECISION_16 -#define IOHDF5_REAL H5T_NATIVE_LDOUBLE +#define IOHDF5_REAL IOHDF5_REAL16 #elif CCTK_REAL_PRECISION_8 -#define IOHDF5_REAL H5T_NATIVE_DOUBLE +#define IOHDF5_REAL IOHDF5_REAL8 #elif CCTK_REAL_PRECISION_4 -#define IOHDF5_REAL H5T_NATIVE_FLOAT +#define IOHDF5_REAL IOHDF5_REAL4 #endif -#define IOHDF5_INT (sizeof (CCTK_INT) == sizeof (int) ? \ - H5T_NATIVE_INT : H5T_NATIVE_SHORT) -#define IOHDF5_INT4 (sizeof (int) == 4 ? \ - H5T_NATIVE_INT : H5T_NATIVE_SHORT) -#define IOHDF5_CHAR H5T_NATIVE_CHAR + +/* integer types are architecture-dependent: + IOHDF5_INT is used for communicating integers of the generic CCTK_INT type + IOHDF5_INTn is used to explicitely communicate n-byte integers */ +#ifdef CCTK_INT8 +#define IOHDF5_INT8 (sizeof (CCTK_INT8) == sizeof (int) ? H5T_NATIVE_INT : \ + sizeof (CCTK_INT8) == sizeof (long) ? H5T_NATIVE_LONG :\ + sizeof (CCTK_INT8) == sizeof (long long) ? \ + H5T_NATIVE_LLONG : -1) +#endif + +#ifdef CCTK_INT4 +#define IOHDF5_INT4 (sizeof (CCTK_INT4) == sizeof (int) ? H5T_NATIVE_INT : \ + sizeof (CCTK_INT4) == sizeof (short) ? \ + H5T_NATIVE_SHORT : -1) +#endif + +#ifdef CCTK_INT2 +#define IOHDF5_INT2 (sizeof (CCTK_INT2) == sizeof (short) ? \ + H5T_NATIVE_SHORT : -1) +#endif + +#ifdef CCTK_INTEGER_PRECISION_8 +#define IOHDF5_INT IOHDF5_INT8 +#elif CCTK_INTEGER_PRECISION_4 +#define IOHDF5_INT IOHDF5_INT4 +#elif CCTK_INTEGER_PRECISION_2 +#define IOHDF5_INT IOHDF5_INT2 +#endif /* Constants to index timers within the timers array */ @@ -137,6 +183,11 @@ #define ALL_PARAMETERS "All Parameters" +#ifdef __cplusplus +extern "C" +{ +#endif + /* Geometry information structure for output variable */ typedef struct { @@ -178,8 +229,10 @@ typedef struct hid_t scalar_dataspace, array_dataspace; /* predefined datatype for writing CCTK_COMPLEX types */ - hid_t IOHDF5_COMPLEX; - hid_t IOHDF5_COMPLEX8; + hid_t IOHDF5_COMPLEX, + IOHDF5_COMPLEX8, + IOHDF5_COMPLEX16, + IOHDF5_COMPLEX32; /* predefined datatype for writing C string string attributes */ hid_t IOHDF5_STRING; @@ -187,12 +240,8 @@ typedef struct } ioHDF5UtilGH; -#ifdef __cplusplus -extern "C" -{ -#endif - /* exported functions */ +hid_t IOHDF5Util_DataType (const ioHDF5UtilGH *myGH, int cctk_type); void IOHDF5Util_ParseVarsForOutput (const char *output_varstring, ioHDF5Geo_t *output_request_list[]); void IOHDF5Util_DumpParameters (cGH *GH, hid_t group); |