| File: | /home/sbrandt/cactus/Cactus/arrangements/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh |
| 1 | :#ifndef CARPETIOHDF5_HH
|
| 2 | :#define CARPETIOHDF5_HH
|
| 3 | :
|
| 4 | :#define H5_USE_16_API 1
|
| 5 | :#include <hdf5.h>
|
| 6 | :
|
| 7 | :#include <vector>
|
| 8 | :
|
| 9 | :#include "cctk_Arguments.h"
|
| 10 | :#include "CactusBase/IOUtil/src/ioutil_Utils.h"
|
| 11 | :#include "carpet.hh"
|
| 12 | :
|
| 13 | :
|
| 14 | :
|
| 15 | :
|
| 16 | :
|
| 17 | :// some macros for HDF5 group names
|
| 18 | :#define METADATA_GROUP "Parameters and Global Attributes"
|
| 19 | :#define ALL_PARAMETERS "All Parameters"
|
| 20 | :#define GRID_STRUCTURE "Grid Structure v5"
|
| 21 | :
|
| 22 | :// atomic HDF5 datatypes for the generic CCTK datatypes
|
| 23 | :// (the one for CCTK_COMPLEX is created at startup as a compound HDF5 datatype)
|
| 24 | :#define HDF5_CHAR H5T_NATIVE_CHAR
|
| 25 | :
|
| 26 | :#ifdef CCTK_REAL_PRECISION_16
|
| 27 | :#define HDF5_REAL H5T_NATIVE_LDOUBLE
|
| 28 | :#elif CCTK_REAL_PRECISION_8
|
| 29 | :#define HDF5_REAL H5T_NATIVE_DOUBLE
|
| 30 | :#elif CCTK_REAL_PRECISION_4
|
| 31 | :#define HDF5_REAL H5T_NATIVE_FLOAT
|
| 32 | :#endif
|
| 33 | :
|
| 34 | :#ifdef CCTK_INTEGER_PRECISION_8
|
| 35 | :#define HDF5_INT H5T_NATIVE_LLONG
|
| 36 | :#elif CCTK_INTEGER_PRECISION_4
|
| 37 | :#define HDF5_INT H5T_NATIVE_INT
|
| 38 | :#elif CCTK_INTEGER_PRECISION_2
|
| 39 | :#define HDF5_INT H5T_NATIVE_SHORT
|
| 40 | :#elif CCTK_INTEGER_PRECISION_1
|
| 41 | :#define HDF5_INT H5T_NATIVE_CHAR
|
| 42 | :#endif
|
| 43 | :
|
| 44 | :
|
| 45 | :// check return code of HDF5 call and print a warning in case of an error
|
| 46 | :#define HDF5_ERROR(fn_call) \
|
| 47 | : do { \
|
| 48 | : int _error_code = fn_call; \
|
| 49 | : \
|
| 50 | : \
|
| 51 | : if (_error_code < 0) \
|
| 52 | : { \
|
| 53 | : CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \
|
| 54 | : "HDF5 call '%s' returned error code %d", \
|
| 55 | : #fn_call, _error_code); \
|
| 56 | : error_count++; \
|
| 57 | : } \
|
| 58 | : } while (0)
|
| 59 | :
|
| 60 | :
|
| 61 | :// datatype of the start[] parameter in a call to H5Sselect_hyperslab()
|
| 62 | :// (the HDF5 API has changed in this respect after version 1.6.3)
|
| 63 | :#if (H5_VERS_MAJOR == 1 && \
|
| 64 | : (H5_VERS_MINOR < 6 || (H5_VERS_MINOR == 6 && H5_VERS_RELEASE < 4)))
|
| 65 | :#define slice_start_size_t hssize_t
|
| 66 | :#else
|
| 67 | :#define slice_start_size_t hsize_t
|
| 68 | :#endif
|
| 69 | :
|
| 70 | :
|
| 71 | :// CarpetIOHDF5 GH extension structure
|
| 72 | :typedef struct
|
| 73 | :{
|
| 74 | : // default number of times to output
|
| 75 | : int out_every_default;
|
| 76 | :
|
| 77 | : // list of variables to output
|
| 78 | : char *out_vars;
|
| 79 | :
|
| 80 | : // stop on I/O parameter parsing errors ?
|
| 81 | : int stop_on_parse_errors;
|
| 82 | :
|
| 83 | : // I/O request description list (for all variables)
|
| 84 | : vector<ioRequest*> requests;
|
| 85 | :
|
| 86 | : // directory in which to output
|
| 87 | : char *out_dir;
|
| 88 | :
|
| 89 | : // ring buffer for list of successfully created cp files
|
| 90 | : int checkpoint_keep;
|
| 91 | : int cp_filename_index;
|
| 92 | : char **cp_filename_list;
|
| 93 | :
|
| 94 | : // list of recovery files to remove
|
| 95 | : int recovery_num_filenames;
|
| 96 | : char **recovery_filename_list;
|
| 97 | :
|
| 98 | : // iteration number of the last checkpoint
|
| 99 | : int last_checkpoint_iteration;
|
| 100 | :
|
| 101 | : // hdf5 datatype for complex variables; to be set at run time
|
| 102 | : hid_t HDF5_COMPLEX, HDF5_COMPLEX8, HDF5_COMPLEX16, HDF5_COMPLEX32;
|
| 103 | :
|
| 104 | :} CarpetIOHDF5GH;
|
| 105 | :
|
| 106 | :
|
| 107 | :namespace CarpetIOHDF5
|
| 108 | :{
|
| 109 | : // callback routine registered for recovery/filereader
|
| 110 | : int Recover (cGH* cctkGH, const char *basefilename, int called_from);
|
| 111 | :
|
| 112 | : // worker routines to write a single variable
|
| 113 | : int WriteVarUnchunked (const cGH* const cctkGH,
|
| 114 | : hid_t file,
|
| 115 | : CCTK_REAL & io_bytes,
|
| 116 | : const ioRequest* const request,
|
| 117 | : bool called_from_checkpoint);
|
| 118 | : int WriteVarChunkedSequential (const cGH* const cctkGH,
|
| 119 | : hid_t file,
|
| 120 | : CCTK_REAL & io_bytes,
|
| 121 | : const ioRequest* const request,
|
| 122 | : bool called_from_checkpoint,
|
| 123 | : hid_t index = -1);
|
| 124 | : int WriteVarChunkedParallel (const cGH* const cctkGH,
|
| 125 | : hid_t file,
|
| 126 | : CCTK_REAL & io_bytes,
|
| 127 | : const ioRequest* const request,
|
| 128 | : bool called_from_checkpoint,
|
| 129 | : hid_t index = -1);
|
| 130 | :
|
| 131 | : int WriteMetadata (const cGH * const cctkGH, int const nioprocs,
|
| 132 | : int const firstvar, int const numvars,
|
| 133 | : bool const called_from_checkpoint, hid_t const file);
|
| 134 | :
|
| 135 | : int AddSliceAttributes(const cGH* const cctkGH,
|
| 136 | : const char* const fullname,
|
| 137 | : const int refinementlevel,
|
| 138 | : const int multigridlevel,
|
| 139 | : const int map,
|
| 140 | : const int timelevel,
|
| 141 | : const vector<double>& origin,
|
| 142 | : const vector<double>& delta,
|
| 143 | : const vector<int>& iorigin,
|
| 144 | : const vector<int>& ioffset,
|
| 145 | : const vector<int>& ioffsetdenom,
|
| 146 | : const vector<int>& bbox,
|
| 147 | : const vector<int>& nghostzones,
|
| 148 | : hid_t& dataset,
|
| 149 | : const vector<hsize_t>& shape,
|
| 150 | : const bool is_index);
|
| 151 | :
|
| 152 | : // returns an HDF5 datatype corresponding to the given CCTK datatype
|
| 153 | : hid_t CCTKtoHDF5_Datatype (const cGH* const cctkGH,
|
| 154 | : int cctk_type,
|
| 155 | : bool single_precision);
|
| 156 | :
|
| 157 | :
|
| 158 | : // Everything is a class template, so that it can easily be
|
| 159 | : // instantiated for all output dimensions
|
| 160 | :
|
| 161 | : // computes the active region the way dh::regrid does
|
| 162 | : void GetAllActive (const dh *dd,
|
| 163 | : const gh *hh,
|
| 164 | : int ml,
|
| 165 | : int rl,
|
| 166 | : ibset &allactive);
|
| 167 | :
|
| 168 | : template<int outdim>
|
| 169 | : struct IOHDF5 {
|
| 170 | :
|
| 171 | : // name of the output directory
|
| 172 | : static char* my_out_slice_dir;
|
| 173 | :
|
| 174 | : // list of variables to output
|
| 175 | : static char* my_out_slice_vars;
|
| 176 | :
|
| 177 | : // I/O request description list (for all variables)
|
| 178 | : static vector<ioRequest*> slice_requests;
|
| 179 | :
|
| 180 | : // number of I/O processors to use, which processor does I/O for me
|
| 181 | : static int nioprocs;
|
| 182 | : static int ioproc;
|
| 183 | : static int ioproc_every;
|
| 184 | :
|
| 185 | :
|
| 186 | : // Scheduled functions
|
| 187 | : static int Startup();
|
| 188 | :
|
| 189 | : // Registered functions
|
| 190 | : static void* SetupGH (tFleshConfig* fc, int convLevel, cGH* cctkGH);
|
| 191 | :
|
| 192 | : static int OutputGH (const cGH* cctkGH);
|
| 193 | : static int OutputVarAs (const cGH* cctkGH,
|
| 194 | : const char* varname, const char* alias);
|
| 195 | : static int TimeToOutput (const cGH* cctkGH, int vindex);
|
| 196 | : static int TriggerOutput (const cGH* cctkGH, int vindex);
|
| 197 | :
|
| 198 | : // Other functions
|
| 199 | : static void CheckSteerableParameters (const cGH* cctkGH);
|
| 200 | :
|
| 201 | : static bool DidOutput (const cGH* cctkGH,
|
| 202 | : int vindex,
|
| 203 | : string basefilename,
|
| 204 | : bool& is_new_file, bool& truncate_file);
|
| 205 | :
|
| 206 | : static bool DirectionIsRequested (const vect<int,outdim>& dirs);
|
| 207 | :
|
| 208 | : static void OutputDirection (const cGH* cctkGH,
|
| 209 | : int vindex,
|
| 210 | : string alias,
|
| 211 | : string basefilename,
|
| 212 | : const vect<int,outdim>& dirs,
|
| 213 | : bool is_new_file,
|
| 214 | : bool truncate_file);
|
| 215 | :
|
| 216 | : static int OpenFile (const cGH* cctkGH,
|
| 217 | : int m,
|
| 218 | : int vindex,
|
| 219 | : int numvars,
|
| 220 | : string alias,
|
| 221 | : string basefilename,
|
| 222 | : const vect<int,outdim>& dirs,
|
| 223 | : bool is_new_file,
|
| 224 | : bool truncate_file,
|
| 225 | : hid_t& file,
|
| 226 | : hid_t& index_file);
|
| 227 | :
|
| 228 | : static int WriteHDF5 (const cGH* cctkGH,
|
| 229 | : hid_t& file,
|
| 230 | : hid_t& index_file,
|
| 231 | : vector<gdata*> const gfdatas,
|
| 232 | : const bbox<int,dim>& gfext,
|
| 233 | : const int vi,
|
| 234 | : const vect<int,dim>& org,
|
| 235 | : const vect<int,outdim>& dirs,
|
| 236 | : const int rl,
|
| 237 | : const int ml,
|
| 238 | : const int m,
|
| 239 | : const int c,
|
| 240 | : const int output_component,
|
| 241 | : const int tl,
|
| 242 | : const CCTK_REAL coord_time,
|
| 243 | : const vect<CCTK_REAL,dim>& coord_lower,
|
| 244 | : const vect<CCTK_REAL,dim>& coord_upper);
|
| 245 | :
|
| 246 | : static int CloseFile (const cGH* cctkGH,
|
| 247 | : hid_t& file,
|
| 248 | : hid_t& index_file);
|
| 249 | :
|
| 250 | : static ivect GetOutputOffset (const cGH* cctkGH, int m,
|
| 251 | : const vect<int,outdim>& dirs);
|
| 252 | : static int IOProcForProc (int proc);
|
| 253 | :
|
| 254 | : }; // struct IOHDF5
|
| 255 | :
|
| 256 | : // scheduled and aliased routines (must be declared as C according
|
| 257 | : // to schedule.ccl)
|
| 258 | : extern "C" {
|
| 259 | :
|
| 260 | : int CarpetIOHDF5_RecoverParameters (void);
|
| 261 | : int CarpetIOHDF5_SetNumRefinementLevels (void);
|
| 262 | : int CarpetIOHDF5_Startup (void);
|
| 263 | : void CarpetIOHDF5_Init (CCTK_ARGUMENTS);
|
| 264 | : void CarpetIOHDF5_InitCheckpointingIntervals (CCTK_ARGUMENTS);
|
| 265 | : void CarpetIOHDF5_RecoverGridStructure (CCTK_ARGUMENTS);
|
| 266 | : void CarpetIOHDF5_CloseFiles (CCTK_ARGUMENTS);
|
| 267 | : void CarpetIOHDF5_InitialDataCheckpoint (CCTK_ARGUMENTS);
|
| 268 | : void CarpetIOHDF5_EvolutionCheckpoint (CCTK_ARGUMENTS);
|
| 269 | : void CarpetIOHDF5_TerminationCheckpoint (CCTK_ARGUMENTS);
|
| 270 | :
|
| 271 | : CCTK_INT CarpetIOHDF5_SetCheckpointGroups (CCTK_INT const *groups,
|
| 272 | : CCTK_INT ngroups);
|
| 273 | :
|
| 274 | : } // extern "C"
|
| 275 | :
|
| 276 | : // Which groups should be checkpointed. If empty, all variables
|
| 277 | : // should be checkpointed (default).
|
| 278 | : extern vector<bool> groups_to_checkpoint;
|
| 279 | :
|
| 280 | :} // namespace CarpetIOHDF5
|
| 281 | :
|
| 282 | :#endif // !defined(CARPETIOHDF5_HH)
|