QDP++
qdp_hdf5.h
Go to the documentation of this file.
1// -*- C++ -*-
2
9
10#ifndef QDP_HDF5_H
11#define QDP_HDF5_H
12
13#include <string>
14#include <sstream>
15#include <stack>
16#include <list>
17
18#include <hdf5.h>
19
20//qdp related things:
21#include "qdp_util.h"
22#include "qdp_stopwatch.h"
23
24typedef unsigned long long ullong;
25
26namespace QDP {
27
28
29 namespace HDF5Base{
30 //write-modes
31 enum writemode{ ate=(1 << 0), trunc=(1 << 1) };
32 //access modes
33 enum accessmode{ transpose_order=(1 << 0), maintain_order=(1 << 1) };
34 }
35
36 //--------------------------------------------------------------------------------
38
41 class HDF5
42 {
43 protected:
47
48 //Lustre optimizations
50
51 //other stuff:
53 bool profile;
54 //copy of qmp mpi-communicator
55 MPI_Comm* mpicomm;
56
57 //constructors:
58 explicit HDF5(const long int& stripesizee=-1, const long int& maxalign=0);
59
60 //stack with all open groups:
61 std::string getNameById(hid_t id)const;
62
63 //helper for splitting directory names
64 void tokenize(const ::std::string& str, ::std::vector< ::std::string >& tokens, const ::std::string& delimiters);
65 std::vector<std::string> splitPathname(const std::string& name);
66
67 //check if an object exists, by iterating through the tree:
68 bool objectExists(const std::string& name);
69 bool objectExists(hid_t loc_id, const std::string& name);
70 std::string objectType(const ::std::string& name);
71 std::string objectType(hid_t loc_id, const ::std::string& name);
72
73 //error handler
74 static hid_t errorHandler(hid_t errstack, void* unused);
75
76 void HDF5_error_exit(const std::string& message){
77 close();
78 QDP_error_exit(message.c_str());
79 }
80
81 //***********************************************************************************************************************************
82 //***********************************************************************************************************************************
83 //LAYOUT HELPERS
84 //***********************************************************************************************************************************
85 //***********************************************************************************************************************************
86 //prefetch mapping for CB->lexicographical:
88
89 //conversion: LAYOUT<-HOST
90 template<class T>
91 inline void CvtToLayout(OLattice<T>& field, void* buf, const unsigned int& nodeSites, const unsigned int& elemSize){
92 //#pragma omp parallel for shared(nodeSites,elemSize,buf,field) default(shared)
93 for(unsigned int run=0; run<nodeSites; run++){
94 memcpy(&(field.elem(reordermap[run])),reinterpret_cast<char*>(buf)+run*elemSize,elemSize);
95 }
96 }
97
98 template<class T>
99 inline void CvtToLayout(multi1d< OLattice<T> >& fieldarray, void* buf, const unsigned int& nodeSites, const unsigned int& arraySize, const unsigned int& elemSize){
100 //#pragma omp parallel for shared(nodeSites,arraySize,elemSize,buf,fieldarray) default(shared)
101 for(unsigned int run=0; run<nodeSites; run++){
102 for(unsigned int dd=0; dd<arraySize; dd++){
103 memcpy(&(fieldarray[dd].elem(reordermap[run])),reinterpret_cast<char*>(buf)+(dd+arraySize*run)*elemSize,elemSize);
104 }
105 }
106 }
107
108 //conversion: HOST<-LAYOUT
109 template<class T>
110 inline void CvtToHost(void* buf, const OLattice<T>& field, const unsigned int& nodeSites, const unsigned int& elemSize){
111 //#pragma omp parallel for shared(nodeSites,elemSize,buf,field) default(shared)
112 for(unsigned int run=0; run<nodeSites; run++){
113 memcpy(reinterpret_cast<char*>(buf)+run*elemSize,&(field.elem(reordermap[run])),elemSize);
114 }
115 }
116
117 template<class T>
118 inline void CvtToHost(void* buf, const multi1d< OLattice<T> >& fieldarray, const unsigned int& nodeSites, const unsigned int& arraySize, const unsigned int& elemSize){
119 //#pragma omp parallel for shared(nodeSites,arraySize,elemSize,buf,fieldarray) default(shared)
120 for(unsigned int run=0; run<nodeSites; run++){
121 for(unsigned int dd=0; dd<arraySize; dd++){
122 memcpy(reinterpret_cast<char*>(buf)+(dd+arraySize*run)*elemSize,&(fieldarray[dd].elem(reordermap[run])),elemSize);
123 }
124 }
125 }
126
127 //***********************************************************************************************************************************
128 //***********************************************************************************************************************************
129 //DATATYPE HELPERS
130 //***********************************************************************************************************************************
131 //***********************************************************************************************************************************
132 //create complex
133 hid_t createComplexType(const unsigned int& float_size);
134
135 //check complex:
136 bool checkComplexType(const hid_t& type_id, hid_t& base_type_id);
137
138 //create colormat
139 hid_t createColorMatrixType(const hid_t& complex_id, const unsigned int& rank);
140
141 //check colormat:
142 bool checkColorMatrixType(const hid_t& type_id, const unsigned int& rank, hid_t& base_type_id);
143
144 //create propagator
145 hid_t createPropagatorType(const hid_t& colmat_id, const unsigned int& spinrank);
146
147 //check propagator
148 bool checkDiracPropagatorType(const hid_t& type_id, const unsigned int& spinrank, const unsigned int& colorrank, hid_t& base_type_id);
149
150 //***********************************************************************************************************************************
151 //***********************************************************************************************************************************
152 //READING ATTRIBUTES HELPERS
153 //***********************************************************************************************************************************
154 //***********************************************************************************************************************************
155 //private read helper routines
156 template<typename ctype>
157 void rdAtt(const std::string& obj_name, const std::string& attr_name, ctype& datum, const H5T_class_t& hdfclass, const bool& sign, const bool& rigid_checks=true){
158 //get datatype properties:
159 unsigned int size=sizeof(ctype);
160
161 std::string oname(obj_name), aname(attr_name);
162 bool exists=objectExists(current_group,oname);
163 if(!exists){
164 HDF5_error_exit("HDF5Reader::readAttribute: error, object "+oname+" you try to read attribute from does not exists!");
165 }
166
167 //do sanity checks and get datatype
168 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
169 if(ex!=1){
170 HDF5_error_exit("HDF5Reader::readAttribute: error, the attribute "+aname+" you try to read does not exists!");
171 }
172 hid_t attr_id=H5Aopen_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT,H5P_DEFAULT);
173 if(attr_id<0){
174 HDF5_error_exit("HDF5Reader::readAttribute: error, cannot open attribute "+aname+" attached to "+oname+"!");
175 }
176 hid_t type_id=H5Aget_type(attr_id);
177 if(H5Tget_class(type_id)!=hdfclass){
178 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+" , datatype type mismatch!");
179 }
180 if(rigid_checks){
181 if(H5Tget_size(type_id)!=size){
182 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype size mismatch!");
183 }
184 if( hdfclass==H5T_INTEGER ){
185 if(sign){
186 if(H5Tget_sign(type_id)!=H5T_SGN_2){
187 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype sign mismatch!");
188 }
189 }
190 else{
191 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
192 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype sign mismatch!");
193 }
194 }
195 }
196 }
197
198 //read
199 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
200 hid_t errhandle=H5Aread(attr_id,nat_type_id,reinterpret_cast<void*>(&datum));
201 errhandle=H5Aclose(attr_id);
202 errhandle=H5Tclose(nat_type_id);
203 errhandle=H5Tclose(type_id);
204 }
205
206 template<typename ctype>
207 void rdAtt(const std::string& obj_name, const std::string& attr_name, multi1d<ctype>& datum, const H5T_class_t& hdfclass, const bool& sign, const bool& rigid_checks=true){
208 //get datatype properties:
209 unsigned int size=sizeof(ctype);
210
211 std::string oname(obj_name), aname(attr_name);
212 bool exists=objectExists(current_group,oname);
213 if(!exists){
214 HDF5_error_exit("HDF5Reader::readAttribute: error, object "+oname+" you try to read attribute from does not exists!");
215 }
216
217 //do sanity checks and get datatype
218 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
219 if(ex!=1){
220 HDF5_error_exit("HDF5Reader::readAttribute: error, the attribute "+aname+" you try to read does not exists!");
221 }
222 hid_t attr_id=H5Aopen_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT,H5P_DEFAULT);
223 if(attr_id<0){
224 HDF5_error_exit("HDF5Reader::readAttribute: error, cannot open attribute "+aname+" attached to "+oname+"!");
225 }
226 hid_t type_id=H5Aget_type(attr_id);
227 if(H5Tget_class(type_id)!=hdfclass){
228 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype mismatch!");
229 }
230 if(rigid_checks){
231 if(H5Tget_size(type_id)!=size){
232 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype size mismatch!");
233 }
234 if( hdfclass==H5T_INTEGER ){
235 if(sign){
236 if(H5Tget_sign(type_id)!=H5T_SGN_2){
237 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype sign mismatch!");
238 }
239 }
240 else{
241 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
242 HDF5_error_exit("HDF5Reader::readAttribute: error reading "+attr_name+", datatype sign mismatch!");
243 }
244 }
245 }
246 }
247
248 //read
249 hid_t space_id=H5Aget_space(attr_id);
250 if(space_id<0){
251 HDF5_error_exit("HDF5Reader::readAttribute: cannot open dataspace.");
252 }
253 hsize_t space_size=H5Sget_simple_extent_npoints(space_id);
254 H5Sclose(space_id);
255 ctype* token=new ctype[space_size];
256 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
257 herr_t errhandle=H5Aread(attr_id,nat_type_id,reinterpret_cast<void*>(token));
258 H5Aclose(attr_id);
259 H5Tclose(nat_type_id);
260 H5Tclose(type_id);
261 datum.resize(space_size);
262 for(hsize_t i=0; i<space_size; i++) datum[i]=token[i];
263 delete [] token;
264 }
265
266 //***********************************************************************************************************************************
267 //***********************************************************************************************************************************
268 //READING DATASETS HELPERS
269 //***********************************************************************************************************************************
270 //***********************************************************************************************************************************
271 template<typename ctype>
272 void rd(const std::string& dataname, ctype& datum, const H5T_class_t& hdfclass, const bool& sign, const bool& rigid_checks=true){
273 //get datatype properties:
274 unsigned int size=sizeof(ctype);
275
276 std::string dname(dataname);
277 bool exists=objectExists(current_group,dname);
278 if(!exists){
279 HDF5_error_exit("HDF5Reader::read: error, dataset does not exists!");
280 }
281 H5O_info_t objinfo;
282 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
283 if(objinfo.type!=H5O_TYPE_DATASET){
284 HDF5_error_exit("HDF5Reader::read: error, "+dname+" exists but it is not a dataset!");
285 }
286 hid_t dset_id=H5Dopen(current_group,dname.c_str(),H5P_DEFAULT);
287 if(dset_id<0){
288 HDF5_error_exit("HDF5Reader::read: error reading "+dataname+", cannot open dataset!");
289 }
290 hid_t type_id=H5Dget_type(dset_id);
291 if(H5Tget_class(type_id)!=hdfclass){
292 HDF5_error_exit("HDF5Reader::read: error reading "+dataname+", datatype mismatch!");
293 }
294 //do sanity checks and get datatype
295 if(rigid_checks){
296 if(H5Tget_size(type_id)!=size){
297 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype size mismatch!");
298 }
299 if( hdfclass==H5T_INTEGER ){
300 if(sign){
301 if(H5Tget_sign(type_id)!=H5T_SGN_2){
302 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
303 }
304 }
305 else{
306 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
307 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
308 }
309 }
310 }
311 }
312
313 //read
314 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
315 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
316 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
317 H5Dread(dset_id,nat_type_id,H5S_ALL,H5S_ALL,plist_id,static_cast<void*>(&datum));
318 H5Pclose(plist_id);
319 H5Dclose(dset_id);
320 H5Tclose(nat_type_id);
321 H5Tclose(type_id);
322 }
323
324 template<typename ctype>
325 void rd(const std::string& dataname, multi1d<ctype>& datum, const H5T_class_t& hdfclass, const bool& sign, const bool& rigid_checks=true){
326 //get datatype properties:
327 unsigned int size=sizeof(ctype);
328
329 std::string dname(dataname);
330 bool exists=objectExists(current_group,dname);
331 if(!exists){
332 HDF5_error_exit("HDF5::read: error reading "+dataname+", dataset does not exists!");
333 }
334 H5O_info_t objinfo;
335 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
336 if(objinfo.type!=H5O_TYPE_DATASET){
337 HDF5_error_exit("HDF5::read: error, "+dname+" exists but it is not a dataset!");
338 }
339 hid_t dset_id=H5Dopen(current_group,dname.c_str(),H5P_DEFAULT);
340 if(dset_id<0){
341 HDF5_error_exit("HDF5::read: error reading "+dataname+", cannot open dataset!");
342 }
343 hid_t type_id=H5Dget_type(dset_id);
344 if(H5Tget_class(type_id)!=hdfclass){
345 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype mismatch!");
346 }
347 //do sanity checks and get datatype
348 if(rigid_checks){
349 if(H5Tget_size(type_id)!=size){
350 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype size mismatch!");
351 }
352 if( hdfclass==H5T_INTEGER ){
353 if(sign){
354 if(H5Tget_sign(type_id)!=H5T_SGN_2){
355 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
356 }
357 }
358 else{
359 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
360 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
361 }
362 }
363 }
364 }
365
366 //read
367 hid_t space_id=H5Dget_space(dset_id);
368 if(space_id<0){
369 HDF5_error_exit("HDF5::read: error, the dataset is corrupted!");
370 }
371 //check for correct dimensionality
372 hsize_t dim=H5Sget_simple_extent_ndims(space_id);
373 if(dim!=1){
374 HDF5_error_exit("HDF5::read: error, dimension mismatch!");
375 }
376 hsize_t space_size=H5Sget_simple_extent_npoints(space_id);
377 H5Sclose(space_id);
378 ctype* token=new ctype[space_size];
379 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
380 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
381 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
382 H5Dread(dset_id,nat_type_id,H5S_ALL,H5S_ALL,plist_id,static_cast<void*>(token));
383 H5Pclose(plist_id);
384 H5Dclose(dset_id);
385 H5Tclose(nat_type_id);
386 H5Tclose(type_id);
387 datum.resize(space_size);
388 for(hsize_t i=0; i<space_size; i++) datum[i]=token[i];
389 delete [] token;
390 }
391
392 template<typename ctype>
393 void rd(const std::string& dataname, multi2d<ctype>& datum, const H5T_class_t& hdfclass, const bool& sign, const bool& rigid_checks=true){
394 //get datatype properties:
395 unsigned int size=sizeof(ctype);
396
397 std::string dname(dataname);
398 bool exists=objectExists(current_group,dname);
399 if(!exists){
400 HDF5_error_exit("HDF5::read: error reading "+dataname+", dataset does not exists!");
401 }
402 H5O_info_t objinfo;
403 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
404 if(objinfo.type!=H5O_TYPE_DATASET){
405 HDF5_error_exit("HDF5::read: error, "+dname+" exists but it is not a dataset!");
406 }
407 hid_t dset_id=H5Dopen(current_group,dname.c_str(),H5P_DEFAULT);
408 if(dset_id<0){
409 HDF5_error_exit("HDF5::read: error reading "+dataname+", cannot open dataset!");
410 }
411 hid_t type_id=H5Dget_type(dset_id);
412 if(H5Tget_class(type_id)!=hdfclass){
413 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype mismatch!");
414 }
415 //do sanity checks and get datatype
416 if(rigid_checks){
417 if(H5Tget_size(type_id)!=size){
418 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype size mismatch!");
419 }
420 if( hdfclass==H5T_INTEGER ){
421 if(sign){
422 if(H5Tget_sign(type_id)!=H5T_SGN_2){
423 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
424 }
425 }
426 else{
427 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
428 HDF5_error_exit("HDF5::read: error reading "+dataname+", datatype sign mismatch!");
429 }
430 }
431 }
432 }
433
434 //read
435 hid_t space_id=H5Dget_space(dset_id);
436 if(space_id<0){
437 HDF5_error_exit("HDF5::read: error, the dataset is corrupted!");
438 }
439 hsize_t dim=H5Sget_simple_extent_ndims(space_id);
440 if(dim!=2){
441 HDF5_error_exit("HDF5::read: error, dimension mismatch!");
442 }
443 hsize_t dims[2];
444 errhandle=H5Sget_simple_extent_dims(space_id, dims, NULL);
445 hsize_t space_size=H5Sget_simple_extent_npoints(space_id);
446 H5Sclose(space_id);
447 ctype* token=new ctype[space_size];
448 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
449 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
450 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
451 H5Dread(dset_id,nat_type_id,H5S_ALL,H5S_ALL,plist_id,static_cast<void*>(token));
452 H5Pclose(plist_id);
453 H5Dclose(dset_id);
454 H5Tclose(nat_type_id);
455 H5Tclose(type_id);
456 datum.resize(dims[0],dims[1]);
457 for(hsize_t i=0; i<dims[0]; i++){
458 for(hsize_t j=0; j<dims[1]; j++){
459 datum(i,j)=token[j+dims[1]*i]; //HDF5 stores row-major
460 }
461 }
462 delete [] token;
463 }
464
465 //***********************************************************************************************************************************
466 //***********************************************************************************************************************************
467 //READING CUSTOM OBJECTS HELPERS
468 //***********************************************************************************************************************************
469 //***********************************************************************************************************************************
470 //helper routines for reading and writing objects:
471 void readPrepare(const std::string& name, hid_t& type_id);
472 void readPrepareLattice(const std::string& name, hid_t& type_id, multi1d<ullong>& sizes);
473
474 void readLattice(const std::string& name, const hid_t& type_id, const hid_t& base_type_id,
475 const ullong& obj_size, const ullong& tot_size, char* buf, bool invert_order=true);
476
477 public:
478 //open and close files. Open is virtual since the openmode differs for reader and writer:
479 virtual void open(const std::string& filename) = 0;
480 int close();
481
482 //find out if file exists:
483 static bool check_exists(const std::string& filename);
484
485 //setting the stripesize:
486 void set_stripesize(const int& stripesizee){stripesize=stripesizee;};
487
488 //activate profiling
489 void set_profiling(const bool& profilee){profile=profilee;};
490
491 //print present working directory and parent directory:
492 std::string pwd()const;
493 std::string parentDir()const;
494
495 //step back one directory:
496 void pop();
497 //change to a directory specified by dirname:
498 void cd(const std::string& dirname);
499
500 //reading routines:
501 //***********************************************************************************************************************************
502 //***********************************************************************************************************************************
503 //READING ATTRIBUTES
504 //***********************************************************************************************************************************
505 //***********************************************************************************************************************************
506 //single datum
507 void readAttribute(const std::string& obj_name, const std::string& attr_name, short& datum);
508 void readAttribute(const std::string& obj_name, const std::string& attr_name, unsigned short& datum);
509 void readAttribute(const std::string& obj_name, const std::string& attr_name, int& datum);
510 void readAttribute(const std::string& obj_name, const std::string& attr_name, unsigned int& datum);
511 void readAttribute(const std::string& obj_name, const std::string& attr_name, unsigned long long& datum);
512 void readAttribute(const std::string& obj_name, const std::string& attr_name, float& datum);
513 void readAttribute(const std::string& obj_name, const std::string& attr_name, double& datum);
514 void readAttribute(const std::string& obj_name, const std::string& attr_name, std::string& datum);
515
516 //array value
517 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<short>& datum);
518 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<unsigned short>& datum);
519 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<int>& datum);
520 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<unsigned int>& datum);
521 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<unsigned long long>& datum);
522 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<float>& datum);
523 void readAttribute(const std::string& obj_name, const std::string& attr_name, multi1d<double>& datum);
524
525 //***********************************************************************************************************************************
526 //***********************************************************************************************************************************
527 //READING DATASETS
528 //***********************************************************************************************************************************
529 //***********************************************************************************************************************************
530 //single datum
531 void read(const std::string& obj_name, short& datum);
532 void read(const std::string& obj_name, unsigned short& datum);
533 void read(const std::string& obj_name, int& datum);
534 void read(const std::string& obj_name, unsigned int& datum);
535 void read(const std::string& obj_name, unsigned long long& datum);
536 void read(const std::string& obj_name, float& datum);
537 void read(const std::string& obj_name, double& datum);
538 void read(const std::string& dataname, std::string& datum);
539
540 //array value
541 //1D
542 void read(const std::string& obj_name, multi1d<short>& datum);
543 void read(const std::string& obj_name, multi1d<unsigned short>& datum);
544 void read(const std::string& obj_name, multi1d<int>& datum);
545 void read(const std::string& obj_name, multi1d<unsigned int>& datum);
546 void read(const std::string& obj_name, multi1d<unsigned long long>& datum);
547 void read(const std::string& obj_name, multi1d<float>& datum);
548 void read(const std::string& obj_name, multi1d<double>& datum);
549 //2D
550 void read(const std::string& obj_name, multi2d<short>& datum);
551 void read(const std::string& obj_name, multi2d<unsigned short>& datum);
552 void read(const std::string& obj_name, multi2d<int>& datum);
553 void read(const std::string& obj_name, multi2d<unsigned int>& datum);
554 void read(const std::string& obj_name, multi2d<unsigned long long>& datum);
555 void read(const std::string& obj_name, multi2d<float>& datum);
556 void read(const std::string& obj_name, multi2d<double>& datum);
557
558 //***********************************************************************************************************************************
559 //***********************************************************************************************************************************
560 //READING OSCALAR OBJECTS
561 //***********************************************************************************************************************************
562 //***********************************************************************************************************************************
563 //single datum
564 template<class T>
565 void read(const std::string& name, OScalar<T>& scalar)
566 {
567 //read dataset extents:
568 multi1d<ullong> sizes;
569 ullong obj_size=0;
570 hid_t type_id;
571 readPrepareLattice(name,type_id,sizes);
572
573 //sanity check:
574 ullong float_size=H5Tget_size(type_id);
575 if( float_size!=4 && float_size!=8 ){
576 HDF5_error_exit("HDF5Reader::read: error, datatype mismatch!\n");
577 }
578 H5Tclose(type_id);
579 if(sizes.size()!=1){
580 HDF5_error_exit("HDF5Reader::read: error, wrong dimensionality!");
581 }
582 obj_size=sizes[0];
583 if( (obj_size*float_size) != sizeof(T) ){
584 HDF5_error_exit("HDF5Reader::read: error size of input vectors differ from those in record!\n");
585 }
586
587 //read data:
588 multi1d<REAL> buf(obj_size);
589 if(float_size==4){
590 multi1d<float> buf32(obj_size);
591 this->read(name,buf32);
592 for(ullong i=0; i<obj_size; i++) buf[i]=static_cast<REAL>(buf32[i]);
593 }
594 else{
595 multi1d<double> buf64(obj_size);
596 this->read(name,buf64);
597 for(ullong i=0; i<obj_size; i++) buf[i]=static_cast<REAL>(buf64[i]);
598 }
599 memcpy(reinterpret_cast<void*>(&scalar.elem()),&buf[0],sizeof(T));
600 }
601
602 //array
603 template<class T>
604 void read(const std::string& name, multi1d< OScalar<T> >& scalararray)
605 {
606 //read dataset extents:
607 multi1d<ullong> sizes;
608 ullong obj_size=0;
609 hid_t type_id;
610 readPrepareLattice(name,type_id,sizes);
611
612 //sanity check:
613 ullong float_size=H5Tget_size(type_id);
614 if( float_size!=4 && float_size!=8 ){
615 HDF5_error_exit("HDF5Reader::read: error, datatype mismatch!\n");
616 }
617 H5Tclose(type_id);
618 if(sizes.size()!=1){
619 HDF5_error_exit("HDF5Reader::read: error, wrong dimensionality!\n");
620 }
621 obj_size=sizes[0];
622 if( (obj_size*float_size)%sizeof(T) != 0 ){
623 HDF5_error_exit("HDF5Reader::read: error size of input vectors differ from those in record!\n");
624 }
625 ullong arr_size=(obj_size*float_size)/sizeof(T);
626 obj_size/=arr_size;
627
628 //read data:
629 multi1d<REAL> buf(obj_size*arr_size);
630 if(float_size==4){
631 multi1d<float> buf32(obj_size*arr_size);
632 this->read(name,buf32);
633 for(ullong i=0; i<(obj_size*arr_size); i++) buf[i]=static_cast<REAL>(buf32[i]);
634 }
635 else{
636 multi1d<double> buf64(obj_size*arr_size);
637 this->read(name,buf64);
638 for(ullong i=0; i<(obj_size*arr_size); i++) buf[i]=static_cast<REAL>(buf64[i]);
639 }
640 scalararray.resize(arr_size);
641 for(ullong i=0; i<arr_size; i++){
642 memcpy(reinterpret_cast<void*>(&scalararray[i].elem()),&buf[i*obj_size],sizeof(T));
643 }
644 }
645
646 //***********************************************************************************************************************************
647 //***********************************************************************************************************************************
648 //READING OLATTICE OBJECTS
649 //***********************************************************************************************************************************
650 //***********************************************************************************************************************************
651 //read OLattice object:
652 template<class T>
653 void read(const std::string& name, OLattice<T>& field, const HDF5Base::accessmode& accmode=HDF5Base::transpose_order)
654 {
655 StopWatch swatch_datatypes, swatch_prepare, swatch_reorder, swatch_read;
656
657 //define a new type
658 typedef typename WordType<T>::Type_t wtd;
659
660 bool invert_order;
661 switch(accmode){
663 invert_order=true;
664 break;
666 invert_order=false;
667 break;
668 }
669
670 //read dataset extents:
671 if(profile) swatch_prepare.start();
672 multi1d<ullong> sizes;
673 ullong obj_size=0;
674 hid_t type_id;
675 readPrepareLattice(name,type_id,sizes);
676 if(profile) swatch_prepare.stop();
677
678 //sanity checks for datatypes:
679 if(profile) swatch_datatypes.start();
680 ullong hdf5_float_size=H5Tget_size(type_id);
681 ullong field_float_size=sizeof(wtd);
682
683 //checks
684 if( hdf5_float_size!=4 && hdf5_float_size!=8 ){
685 HDF5_error_exit("HDF5Reader::read: error, datatype mismatch. The datatype should be either 32 or 64 bit!\n");
686 }
687 if(sizes.size()!=(Nd+1)){
688 HDF5_error_exit("HDF5Reader::read: error, wrong dimensionality!");
689 }
690 if(invert_order){
691 for(unsigned int dd=0; dd<Nd; dd++){
692 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
693 HDF5_error_exit("HDF5Reader::read: mismatching lattice extents.");
694 }
695 }
696 }
697 else{
698 for(unsigned int dd=0; dd<Nd; dd++){
699 if(sizes[dd]!=Layout::lattSize()[dd]){
700 HDF5_error_exit("HDF5Reader::read: mismatching lattice extents.");
701 }
702 }
703 }
704 obj_size=sizes[Nd];
705 //if( (obj_size*hdf5_float_size) != sizeof(T) ){
706 // HDF5_error_exit("HDF5Reader::read: error size of input vectors differ from those in record!");
707 //}
708 if(profile) swatch_datatypes.stop();
709
710 //determine local sizes, allocate memory and read
711 if(profile) swatch_read.start();
712 const int mynode=Layout::nodeNumber();
713 const int nodeSites = Layout::sitesOnNode();
714 size_t tot_size = obj_size*nodeSites;
715 char* buf = new(std::nothrow) char[tot_size*hdf5_float_size];
716 if( buf == 0x0 ) {
717 HDF5_error_exit("Unable to allocate buf\n");
718 }
719 readLattice(name,type_id,type_id,obj_size,tot_size,buf,invert_order);
720 H5Tclose(type_id);
721 if(profile) swatch_read.stop();
722
723 //put lattice into u-field and reconstruct as well as reorder them on the fly:
724 // Reconstruct the gauge field
725 if(profile) swatch_reorder.start();
726 /*#pragma omp parallel for firstprivate(nodeSites,obj_size,float_size) shared(buf,field)
727 for(unsigned int run=0; run<nodeSites; run++){
728 memcpy(&(field.elem(reordermap[run])),reinterpret_cast<char*>(buf+run*obj_size),float_size*obj_size);
729 }*/
730 if(hdf5_float_size==field_float_size){
731 //convert layout directly
732 CvtToLayout(field,reinterpret_cast<void*>(buf),nodeSites,sizeof(T));
733 }
734 else{
735 //convert precision first
736 wtd* tmpbuf=new wtd[tot_size];
737 for(unsigned int i=0; i<tot_size; i++){
738 if(hdf5_float_size==4){
739 REAL32 tmpfloat;
740 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
741 tmpbuf[i]=static_cast< wtd >(tmpfloat);
742 }
743 else{
744 REAL64 tmpfloat;
745 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
746 tmpbuf[i]=static_cast< wtd >(tmpfloat);
747 }
748 }
749 CvtToLayout(field,reinterpret_cast<void*>(tmpbuf),nodeSites,sizeof(T));
750 delete [] tmpbuf;
751 }
752 delete [] buf;
753 if(profile) swatch_reorder.stop();
754
755 if(profile){
756 QDPIO::cout << "HDF5-I/O statistics. Read:" << std::endl;
757 QDPIO::cout << "\t preparing: " << swatch_prepare.getTimeInSeconds() << std::endl;
758 QDPIO::cout << "\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() << std::endl;
759 QDPIO::cout << "\t reordering: " << swatch_reorder.getTimeInSeconds() << std::endl;
760 QDPIO::cout << "\t read: " << swatch_read.getTimeInSeconds() << std::endl;
761 QDPIO::cout << "\t MB read: " << static_cast<int>(Layout::vol()*obj_size*hdf5_float_size)/1024/1024 << std::endl;
762 }
763 }
764
765 //read multi1d<OLattice> object:
766 template<class T>
767 void read(const std::string& name, multi1d< OLattice<T> >& fieldarray, const HDF5Base::accessmode& accmode=HDF5Base::transpose_order)
768 {
769 StopWatch swatch_datatypes, swatch_prepare, swatch_reorder, swatch_read;
770
771 //define a new type
772 typedef typename WordType<T>::Type_t wtd;
773
774 bool invert_order;
775 switch(accmode){
777 invert_order=true;
778 break;
780 invert_order=false;
781 break;
782 }
783
784 //read dataset extents:
785 if(profile) swatch_prepare.start();
786 multi1d<ullong> sizes;
787 ullong obj_size=0;
788 hid_t type_id;
789 readPrepareLattice(name,type_id,sizes);
790 swatch_prepare.stop();
791
792 //check sanity
793 if(profile) swatch_datatypes.start();
794 ullong hdf5_float_size=H5Tget_size(type_id);
795 ullong field_float_size=sizeof(wtd);
796
797 //checks
798 if( hdf5_float_size!=4 && hdf5_float_size!=8 ){
799 HDF5_error_exit("HDF5Reader::read: error, datatype mismatch. The datatype should be either 32 or 64 bit!\n");
800 }
801 if(sizes.size()!=(Nd+1)){
802 HDF5_error_exit("HDF5Reader::read: error, wrong dimensionality!");
803 }
804 if(invert_order){
805 for(unsigned int dd=0; dd<Nd; dd++){
806 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
807 HDF5_error_exit("HDF5Reader::read: mismatching lattice extents.");
808 }
809 }
810 }
811 else{
812 for(unsigned int dd=0; dd<Nd; dd++){
813 if(sizes[dd]!=Layout::lattSize()[dd]){
814 HDF5_error_exit("HDF5Reader::read: mismatching lattice extents.");
815 }
816 }
817 }
818 obj_size=sizes[Nd];
819 //if( (obj_size*hdf5_float_size)%sizeof(T) != 0 ){
820 // HDF5_error_exit("HDF5Reader::read: error size of input vectors differ from those in record!");
821 //}
822 //this calculation is build on top of field float size since it involves type T, which is based on the same base prec.
823 ullong arr_size=(obj_size*field_float_size)/sizeof(T);
824 obj_size/=arr_size;
825 if(profile) swatch_datatypes.stop();
826
827 //determine local sizes, allocate memory and read
828 if(profile) swatch_read.start();
829 const int mynode=Layout::nodeNumber();
830 const int nodeSites = Layout::sitesOnNode();
831 size_t tot_size = obj_size*arr_size*nodeSites;
832 char* buf = new(std::nothrow) char[tot_size*hdf5_float_size];
833 if( buf == 0x0 ) {
834 HDF5_error_exit("Unable to allocate buf!");
835 }
836 readLattice(name,type_id,type_id,obj_size*arr_size,tot_size,buf,invert_order);
837 H5Tclose(type_id);
838 if(profile) swatch_read.stop();
839
840 //put lattice into u-field and reconstruct as well as reorder them on the fly:
841 // Reconstruct the gauge field
842 if(profile) swatch_reorder.start();
843 fieldarray.resize(arr_size);
844 /*#pragma omp parallel for firstprivate(nodeSites,arr_size,obj_size,float_size) shared(buf,fieldarray)
845 for(unsigned int run=0; run<nodeSites; run++){
846 for(unsigned int dd=0; dd<arr_size; dd++){
847 memcpy(&(fieldarray[dd].elem(reordermap[run])),reinterpret_cast<char*>(buf+(dd+arr_size*run)*obj_size),float_size*obj_size);
848 }
849 }*/
850 if(hdf5_float_size==field_float_size){
851 //convert layout directly
852 CvtToLayout(fieldarray,reinterpret_cast<void*>(buf),nodeSites,arr_size,sizeof(T));
853 }
854 else{
855 //convert precision first
856 wtd* tmpbuf=new wtd[tot_size];
857 for(unsigned int i=0; i<tot_size; i++){
858 if(hdf5_float_size==4){
859 REAL32 tmpfloat;
860 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
861 tmpbuf[i]=static_cast< wtd >(tmpfloat);
862 }
863 else{
864 REAL64 tmpfloat;
865 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
866 tmpbuf[i]=static_cast< wtd >(tmpfloat);
867 }
868 }
869 CvtToLayout(fieldarray,reinterpret_cast<void*>(tmpbuf),nodeSites,arr_size,sizeof(T));
870 delete [] tmpbuf;
871 }
872 delete [] buf;
873 if(profile) swatch_reorder.stop();
874
875 if(profile){
876 QDPIO::cout << "HDF5-I/O statistics. Read:" << std::endl;
877 QDPIO::cout << "\t preparing: " << swatch_prepare.getTimeInSeconds() << " s." << std::endl;
878 QDPIO::cout << "\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() << " s." << std::endl;
879 QDPIO::cout << "\t reordering: " << swatch_reorder.getTimeInSeconds() << " s." << std::endl;
880 QDPIO::cout << "\t read: " << swatch_read.getTimeInSeconds() << " s." << std::endl;
881 QDPIO::cout << "\t MB read: " << static_cast<int>(Layout::vol()*fieldarray.size()*obj_size*hdf5_float_size)/1024/1024 << std::endl;
882 }
883 }
884
885 //special file formats
886 //Qlua
887 void readQlua(const std::string& name, multi1d<LatticeColorMatrixD3>& field);
888 void readQlua(const std::string& name, LatticeDiracPropagatorD3& prop);
889
890 };
891
892 template<typename ctype>
893 bool get_global(ctype& global, const ctype& local);
894
895 template<typename ctype>
897
898 template<typename ctype>
899 inline bool is_global(const ctype l)
900 {
901 ctype g;
902 return get_global(g,l);
903 }
904
905 template <typename ctype>
906 inline void assert_global_size(const multi1d<ctype>& datum)
907 {
908 if (not is_global(datum.size()))
909 QDP_error_exit("qdp_hdf5.h assert_global_size: multi1d.size not global!");
910 }
911
912 template <typename ctype>
913 inline void assert_global_size(const multi2d<ctype>& datum)
914 {
915 if (not is_global(datum.size2()))
916 QDP_error_exit("qdp_hdf5.h assert_global_size: multi2d.size2 not global!");
917
918 if (not is_global(datum.size1()))
919 QDP_error_exit("qdp_hdf5.h assert_global_size: multi2d.size1 not global!");
920 }
921
922 //template specializations:
923 //complex types
924 //single datum
925 template<>void HDF5::read< PScalar< PScalar< RComplex<float> > > >(const std::string& dataname, ComplexF& datum);
926 template<>void HDF5::read< PScalar< PScalar< RComplex<double> > > >(const std::string& dataname, ComplexD& datum);
927
928 //array value
929 template<>void HDF5::read< PScalar< PScalar< RComplex<float> > > >(const std::string& dataname, multi1d<ComplexF>& datum);
930 template<>void HDF5::read< PScalar< PScalar< RComplex<double> > > >(const std::string& dataname, multi1d<ComplexD>& datum);
931
932 //specializations for Lattice objects
933 template<>void HDF5::read< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(const std::string& name,
934 LatticeColorMatrixD3& field,
935 const HDF5Base::accessmode& accmode);
936
937 template<>void HDF5::read< PSpinMatrix< PColorMatrix< RComplex<REAL32>, 3>, 4> >(const std::string& name,
939 const HDF5Base::accessmode& accmode);
940
941 template<>void HDF5::read< PSpinMatrix< PColorMatrix< RComplex<REAL64>, 3>, 4> >(const std::string& name,
943 const HDF5Base::accessmode& accmode);
944
945 //specializations for multi1d<OLattice> objects
946 template<>void HDF5::read< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(const std::string& name,
948 const HDF5Base::accessmode& accmode);
949 //--------------------------------------------------------------------------------
951
954 class HDF5Reader : public HDF5
955 {
956 public:
959 HDF5Reader(const long int& stripesize, const long int& maxalign=0);
960
962
965 HDF5Reader(const std::string& filename);
966
969
970 //open file and other useful stuff:
971 void open(const std::string& filename);
972
973 };
974
975 //--------------------------------------------------------------------------------
977
980 class HDF5Writer : public HDF5
981 {
982 private:
983 //helpers for committing datatypes:
984 void commitType(const std::string& name, hid_t dtype_id){
985 //first, check if type is already committed:
986 htri_t iscommitted=H5Tcommitted(dtype_id);
987 if(iscommitted==0){
988 //not commit, commit type:
989 herr_t errhandle=H5Tcommit(file_id,name.c_str(),dtype_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
990 }
991 }
992
993 //helpers for attribute handling
994 static herr_t rmAtt(hid_t location_id, const char *attr_name, const H5A_info_t* attrinfo, void* opdata);
995
996 //***********************************************************************************************************************************
997 //***********************************************************************************************************************************
998 //WRITING ATTRIBUTES HELPERS
999 //***********************************************************************************************************************************
1000 //***********************************************************************************************************************************
1001 template<typename ctype>
1002 void wtAtt(const std::string& obj_name, const std::string& attr_name, const ctype& datum, const hid_t& hdftype, const HDF5Base::writemode& mode){
1003 std::string oname(obj_name), aname(attr_name);
1004
1005 ctype datum_0;
1006 if (not get_global(datum_0, datum)) {
1007 QDPIO::cerr << "HDF5Writer::writeAttribute() warning: " << obj_name
1008 << ".attrib(" << attr_name
1009 << ") was NOT global. Using node=0 value now." << std::endl;
1010 }
1011
1012 bool exists=objectExists(current_group,oname);
1013 if(!exists){
1014 HDF5_error_exit("HDF5Writer::writeAttribute: error, object "+oname+" you try to write attribute to does not exists!");
1015 }
1016
1017 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1018 if(ex==1){
1019 if(!(mode&HDF5Base::trunc)){
1020 HDF5_error_exit("HDF5Writer::writeAttribute: error, attribute "+aname+" already exists!");
1021 }
1022 herr_t errhandle=H5Adelete_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1023 }
1024
1025 hid_t attr_space_id=H5Screate(H5S_SCALAR);
1026 hid_t attr_id=H5Acreate_by_name(current_group,oname.c_str(),aname.c_str(),hdftype,attr_space_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1027 H5Awrite(attr_id,hdftype,reinterpret_cast<void*>(&datum_0));
1028 H5Aclose(attr_id);
1029 H5Sclose(attr_space_id);
1030 }
1031
1032 template<typename ctype>
1033 void wtAtt(const std::string& obj_name, const std::string& attr_name, const multi1d<ctype>& datum, const hid_t& hdftype, const HDF5Base::writemode& mode){
1034 std::string oname(obj_name), aname(attr_name);
1035
1036 multi1d<ctype> datum_0;
1037 if (not get_global(datum_0, datum)) {
1038 QDPIO::cerr << "HDF5Writer::writeAttribute() warning: " << obj_name
1039 << ".attrib(" << attr_name
1040 << ") was NOT global. Using node=0 value now." << std::endl;
1041 }
1042
1043 bool exists=objectExists(current_group,oname);
1044 if(!exists){
1045 HDF5_error_exit("HDF5Writer::writeAttribute: error, object "+oname+" you try to write attribute to does not exists!");
1046 }
1047
1048 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1049 if(ex==1){
1050 if(!(mode&HDF5Base::trunc)){
1051 HDF5_error_exit("HDF5Writer::writeAttribute: error, attribute "+aname+" already exists!");
1052 }
1053 herr_t errhandle=H5Adelete_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1054 }
1055
1056 hsize_t dimcount=datum_0.size();
1057 if (dimcount*H5Tget_size(hdftype)>64*1024) {
1058 QDPIO::cerr << "HDF5Writer::writeAttribute() error: " << obj_name
1059 << ".attrib(" << attr_name
1060 << ") exceeds the maximum hdf5 attrib size (64kB)." << std::endl;
1061
1062 HDF5_error_exit("bad multi1d attrib write");
1063 }
1064
1065 ctype* tmpdim=new ctype[dimcount];
1066 for(unsigned int i=0; i<dimcount; i++) tmpdim[i]=datum_0[i];
1067 hid_t attr_space_id=H5Screate_simple(1,const_cast<const hsize_t*>(&dimcount),const_cast<const hsize_t*>(&dimcount));
1068 hid_t attr_id=H5Acreate_by_name(current_group,oname.c_str(),aname.c_str(),hdftype,attr_space_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1069 H5Awrite(attr_id,hdftype,reinterpret_cast<void*>(tmpdim));
1070 delete [] tmpdim;
1071 H5Aclose(attr_id);
1072 H5Sclose(attr_space_id);
1073 }
1074
1075 //***********************************************************************************************************************************
1076 //***********************************************************************************************************************************
1077 //WRITING DATASETS HELPERS
1078 //***********************************************************************************************************************************
1079 //***********************************************************************************************************************************
1080 template<typename ctype>
1081 void wt(const std::string& dataname, const ctype& datum, const hid_t& hdftype, const HDF5Base::writemode& mode){
1082 std::string dname(dataname);
1083 hid_t dataid, spaceid;
1084
1085 bool exists=objectExists(current_group,dname);
1086 if(exists){
1087 if(!(mode&HDF5Base::trunc)){
1088 HDF5_error_exit("HDF5Writer::write: error, dataset already exists and you specified not to overwrite!\n");
1089 }
1090 H5O_info_t objinfo;
1091 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
1092 if(objinfo.type!=H5O_TYPE_DATASET){
1093 HDF5_error_exit("HDF5Writer::write: error, object you try to write does already exist and is of different type!");
1094 }
1095 errhandle=H5Ldelete(current_group,dname.c_str(),H5P_DEFAULT);
1096 }
1097
1098 spaceid=H5Screate(H5S_SCALAR);
1099 dataid=H5Dcreate(current_group,dname.c_str(),hdftype,spaceid,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1100 H5Sclose(spaceid);
1101
1102 ctype datumcpy=datum;
1103 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1104 //H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
1105 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1106 //H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,reinterpret_cast<void*>(&datumcpy));
1107 if(Layout::nodeNumber()==0) H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,reinterpret_cast<void*>(&datumcpy));
1108 H5Pclose(plist_id);
1109 H5Dclose(dataid);
1110 }
1111
1112 template<typename ctype>
1113 void wt(const std::string& dataname, const multi1d<ctype>& datum, const hid_t& hdftype, const HDF5Base::writemode& mode){
1114 std::string dname(dataname);
1115 hid_t dataid, spaceid;
1116 assert_global_size(datum);
1117
1118 bool exists=objectExists(current_group,dname);
1119 if(exists){
1120 if(!(mode&HDF5Base::trunc)){
1121 HDF5_error_exit("HDF5Writer::write: error, object named "+dname+" already exists and you specified not to overwrite it!");
1122 }
1123 H5O_info_t objinfo;
1124 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
1125 if(objinfo.type!=H5O_TYPE_DATASET){
1126 HDF5_error_exit("HDF5Writer::write: error, object you try to write does already exist and is of different type!");
1127 }
1128 errhandle=H5Ldelete(current_group,dname.c_str(),H5P_DEFAULT);
1129 }
1130
1131 spaceid=H5Screate(H5S_SIMPLE);
1132 hsize_t size[1];
1133 size[0]=static_cast<hsize_t>(datum.size());
1134 herr_t errhandle=H5Sset_extent_simple(spaceid,1,size,size);
1135 dataid=H5Dcreate(current_group,dname.c_str(),hdftype,spaceid,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1136 H5Sclose(spaceid);
1137
1138 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1139 herr_t status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1140
1141 if (Layout::nodeNumber()==0) { // CAREFULL THIS IS ONLY ON NODE=0!!!,
1142 // do nothing collective, throw or exit here
1143 ctype* datumcpy=new(std::nothrow) ctype[datum.size()];
1144
1145 if ( datumcpy != 0x0 ) {
1146 for(ullong i=0; i<datum.size(); i++)
1147 datumcpy[i]=datum[i];
1148
1149 status = H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,static_cast<void*>(datumcpy));
1150 delete [] datumcpy;
1151 }
1152 else {
1153 QDPIO::cerr << "HDF5Writer::wt - buffer alloc failed" << std::endl;
1154 status = -1; // I cannot throw in here
1155 }
1156 }
1157
1158 int g_stat = 0;
1159 get_global(g_stat, (int)status); // get node 0 value
1160 if (g_stat < 0)
1161 HDF5_error_exit("write from node ZERO failed");
1162
1163 status = H5Pclose(plist_id);
1164 status = H5Dclose(dataid);
1165 }
1166
1167 template<typename ctype>
1168 void wt(const std::string& dataname, const multi2d<ctype>& datum, const hid_t& hdftype, const HDF5Base::writemode& mode){
1169 std::string dname(dataname);
1170 hid_t dataid, spaceid;
1171 assert_global_size(datum);
1172
1173 bool exists=objectExists(current_group,dname);
1174 if(exists){
1175 if(!(mode&HDF5Base::trunc)){
1176 HDF5_error_exit("HDF5Writer::write: error, object named "+dname+" already exists and you specified not to overwrite it!");
1177 }
1178 H5O_info_t objinfo;
1179 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
1180 if(objinfo.type!=H5O_TYPE_DATASET){
1181 HDF5_error_exit("HDF5Writer::write: error, object you try to write does already exist and is of different type!");
1182 }
1183 errhandle=H5Ldelete(current_group,dname.c_str(),H5P_DEFAULT);
1184 }
1185
1186 //create dataspace and dataset:
1187 hsize_t rank = static_cast<hsize_t>(2);
1188 hsize_t spacesize[2];
1189 //twist in how HDF5 handles data description
1190 spacesize[1]=datum.size1();
1191 spacesize[0]=datum.size2();
1192 spaceid = H5Screate_simple(static_cast<int>(rank), const_cast<const hsize_t*>(spacesize), NULL);
1193 hid_t dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
1194 dataid=H5Dcreate(current_group,dname.c_str(),hdftype,spaceid,H5P_DEFAULT,dcpl_id,H5P_DEFAULT);
1195 H5Pclose(dcpl_id);
1196 H5Sclose(spaceid);
1197
1198 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1199 herr_t status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1200
1201 if (Layout::nodeNumber()==0) { // CAREFULL THIS IS ONLY ON NODE=0!!!,
1202 // do nothing collective, throw or exit here
1203 ctype* datumcpy = new(std::nothrow) ctype[spacesize[0]*spacesize[1]];
1204
1205 if ( datumcpy != 0x0 ) {
1206 for (ullong i=0; i<spacesize[0]; i++) {
1207 for (ullong j=0; j<spacesize[1]; j++) {
1208 datumcpy[j+spacesize[1]*i]=datum(i,j); //row-major
1209 }
1210 }
1211
1212 status = H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,static_cast<void*>(datumcpy));
1213 delete [] datumcpy;
1214 }
1215 else {
1216 QDPIO::cerr << "HDF5Writer::wt - buffer alloc failed" << std::endl;
1217 status = -1; // I cannot throw in here
1218 }
1219 }
1220
1221 int g_stat = 0;
1222 get_global(g_stat, (int)status); // get node 0 value
1223 if (g_stat < 0)
1224 HDF5_error_exit("write from node ZERO failed");
1225
1226 status = H5Pclose(plist_id);
1227 status = H5Dclose(dataid);
1228 }
1229 //***********************************************************************************************************************************
1230 //***********************************************************************************************************************************
1231 //WRITING CUSTOM OBJECTS HELPERS
1232 //***********************************************************************************************************************************
1233 //***********************************************************************************************************************************
1234 //helper routines for Lattice field I/O:
1235 void writePrepare(const std::string& name, const HDF5Base::writemode& mode);
1236 void writeLattice(const std::string& name, const hid_t& datatype, const ullong& obj_size, char* buf);
1237
1238 public:
1241 HDF5Writer(const long int& stripesize, const long int& maxalign=0);
1242
1244 HDF5Writer(const std::string& filename, const HDF5Base::writemode& mode=HDF5Base::ate);
1245
1248
1249 //open file:
1250 void open(const std::string& filename){
1251 open(filename,HDF5Base::ate);
1252 }
1253
1254 void open(const std::string& filename, const HDF5Base::writemode& mode);
1255
1259 void push(const std::string& name);
1260 void mkdir(const ::std::string& name);
1261
1262 //delete all attributes attached to a dataset with name "obj_name"
1263 void deleteAllAttributes(const std::string& obj_name);
1264 void deleteAttribute(const std::string& obj_name, const std::string& attr_name);
1265
1266 //***********************************************************************************************************************************
1267 //***********************************************************************************************************************************
1268 //WRITING ATTRIBUTES
1269 //***********************************************************************************************************************************
1270 //***********************************************************************************************************************************
1271 //single datum
1272 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const short& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1273 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const unsigned short& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1274 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const int& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1275 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const unsigned int& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1276 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const unsigned long long& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1277 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const float& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1278 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const double& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1279 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const std::string& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1280
1281 //array value:
1282 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1283 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<unsigned short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1284 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1285 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<unsigned int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1286 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<unsigned long long>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1287 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<float>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1288 void writeAttribute(const std::string& obj_name, const std::string& attr_name, const multi1d<double>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1289 //***********************************************************************************************************************************
1290 //***********************************************************************************************************************************
1291 //WRITING DATASETS
1292 //***********************************************************************************************************************************
1293 //***********************************************************************************************************************************
1294 //single datum
1295 void write(const std::string& obj_name, const short& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1296 void write(const std::string& obj_name, const unsigned short& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1297 void write(const std::string& obj_name, const int& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1298 void write(const std::string& obj_name, const unsigned int& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1299 void write(const std::string& obj_name, const unsigned long long& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1300 void write(const std::string& obj_name, const float& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1301 void write(const std::string& obj_name, const double& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1302 void write(const std::string& dataname, const std::string& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1303
1304 //array value
1305 //1D
1306 void write(const std::string& obj_name, const multi1d<short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1307 void write(const std::string& obj_name, const multi1d<unsigned short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1308 void write(const std::string& obj_name, const multi1d<int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1309 void write(const std::string& obj_name, const multi1d<unsigned int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1310 void write(const std::string& obj_name, const multi1d<unsigned long long>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1311 void write(const std::string& obj_name, const multi1d<float>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1312 void write(const std::string& obj_name, const multi1d<double>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1313 //2D
1314 void write(const std::string& obj_name, const multi2d<short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1315 void write(const std::string& obj_name, const multi2d<unsigned short>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1316 void write(const std::string& obj_name, const multi2d<int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1317 void write(const std::string& obj_name, const multi2d<unsigned int>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1318 void write(const std::string& obj_name, const multi2d<unsigned long long>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1319 void write(const std::string& obj_name, const multi2d<float>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1320 void write(const std::string& obj_name, const multi2d<double>& datum, const HDF5Base::writemode& mode=HDF5Base::ate);
1321 //***********************************************************************************************************************************
1322 //***********************************************************************************************************************************
1323 //WRITING Compound Datatypes
1324 //***********************************************************************************************************************************
1325 //***********************************************************************************************************************************
1326 //single datum
1327 template<class T>
1328 void write(const std::string& name, const OScalar<T>& scalar, const HDF5Base::writemode& mode=HDF5Base::ate)
1329 {
1330 //copy buffer into data
1331 size_t float_size=sizeof(REAL);
1332 size_t obj_size=sizeof(T)/float_size;
1333 multi1d<REAL> buf(obj_size);
1334 memcpy(reinterpret_cast<char*>(&buf[0]),&(scalar.elem()),sizeof(T));
1335 write(name,buf,mode);
1336 }
1337
1338 //array:
1339 template<class T>
1340 void write(const std::string& name, const multi1d< OScalar<T> >& scalararray, const HDF5Base::writemode& mode=HDF5Base::ate)
1341 {
1342 //copy buffer into data
1343 size_t float_size=sizeof(REAL);
1344 size_t obj_size=sizeof(T)/float_size;
1345 size_t arr_size=scalararray.size();
1346 multi1d<REAL> buf(obj_size*arr_size);
1347 for(ullong i=0; i<arr_size; i++){
1348 memcpy(reinterpret_cast<char*>(&buf[i*obj_size]),&(scalararray[i].elem()),sizeof(T));
1349 }
1350 write(name,buf,mode);
1351 }
1352
1353 //***********************************************************************************************************************************
1354 //***********************************************************************************************************************************
1355 //WRITING OLATTICE OBJECTS
1356 //***********************************************************************************************************************************
1357 //***********************************************************************************************************************************
1358 template<class T>
1359 void write(const std::string& name, const OLattice<T>& field, const HDF5Base::writemode& mode=HDF5Base::ate)
1360 {
1361 StopWatch swatch_prepare, swatch_reorder, swatch_write;
1362
1363 //before writing is performed, check if dataset exists:
1364 if(profile) swatch_prepare.start();
1365 writePrepare(name,mode);
1366 if(profile) swatch_prepare.stop();
1367
1368 //get node information:
1369 if(profile) swatch_reorder.start();
1370 const int mynode=Layout::nodeNumber();
1371 const int nodeSites = Layout::sitesOnNode();
1372
1373 //copy buffer into data
1374 size_t float_size=sizeof(REAL);
1375 size_t obj_size=sizeof(T)/float_size;
1376 REAL* buf=new REAL[nodeSites*obj_size];
1377 /*#pragma omp parallel for firstprivate(nodeSites,obj_size,float_size) shared(buf,field)
1378 for(unsigned int run=0; run<nodeSites; run++){
1379 memcpy(reinterpret_cast<char*>(buf+run*obj_size),&(field.elem(reordermap[run])),float_size*obj_size);
1380 }*/
1381 CvtToHost(reinterpret_cast<void*>(buf),field,nodeSites,float_size*obj_size);
1382 if(profile) swatch_reorder.stop();
1383
1384 //determine datatype:
1385 hid_t type_id;
1386 if(float_size==4){
1387 type_id=H5Tcopy(H5T_NATIVE_FLOAT);
1388 }
1389 else if(float_size==8){
1390 type_id=H5Tcopy(H5T_NATIVE_DOUBLE);
1391 }
1392 else{
1393 HDF5_error_exit("HDF5Writer::write: error, unknown datatype in Lattice IO!");
1394 }
1395
1396 //write out the stuff:
1397 if(profile) swatch_write.start();
1398 writeLattice(name,type_id,obj_size,reinterpret_cast<char*>(buf));
1399
1400 //clean up
1401 H5Tclose(type_id);
1402 delete [] buf;
1403 if(profile) swatch_write.stop();
1404
1405 if(profile){
1406 QDPIO::cout << "HDF5-I/O statistics. Write:" << std::endl;
1407 QDPIO::cout << "\t preparing: " << swatch_prepare.getTimeInSeconds() << " s." << std::endl;
1408 QDPIO::cout << "\t reordering: " << swatch_reorder.getTimeInSeconds() << " s." << std::endl;
1409 QDPIO::cout << "\t write: " << swatch_write.getTimeInSeconds() << " s." << std::endl;
1410 QDPIO::cout << "\t MB written: " << Layout::vol()*sizeof(T)/1024/1024 << std::endl;
1411 }
1412 }
1413
1414 template<class T>
1415 void write(const std::string& name, const multi1d< OLattice<T> >& fieldarray, const HDF5Base::writemode& mode=HDF5Base::ate)
1416 {
1417 StopWatch swatch_prepare, swatch_reorder, swatch_write;
1418
1419 //before writing is performed, check if dataset exists:
1420 if(profile) swatch_prepare.start();
1421 writePrepare(name,mode);
1422 if(profile) swatch_prepare.stop();
1423
1424 //get node information:
1425 if(profile) swatch_reorder.start();
1426 const int mynode=Layout::nodeNumber();
1427 const int nodeSites = Layout::sitesOnNode();
1428
1429 //copy buffer into data
1430 size_t float_size=sizeof(REAL);
1431 size_t obj_size=sizeof(T)/float_size;
1432 size_t arr_size=fieldarray.size();
1433 REAL* buf=new REAL[nodeSites*obj_size*arr_size];
1434 /*#pragma omp parallel for firstprivate(nodeSites,arr_size,obj_size,float_size) shared(buf,fieldarray)
1435 for(unsigned int run=0; run<nodeSites; run++){
1436 for(unsigned int dd=0; dd<arr_size; dd++){
1437 memcpy(reinterpret_cast<char*>(buf+(dd+arr_size*run)*obj_size),&(fieldarray[dd].elem(reordermap[run])),float_size*obj_size);
1438 }
1439 }*/
1440 CvtToHost(reinterpret_cast<void*>(buf),fieldarray,nodeSites,arr_size,float_size*obj_size);
1441
1442 hid_t type_id;
1443 if(float_size==4){
1444 type_id=H5Tcopy(H5T_NATIVE_FLOAT);
1445 }
1446 else if(float_size==8){
1447 type_id=H5Tcopy(H5T_NATIVE_DOUBLE);
1448 }
1449 else{
1450 HDF5_error_exit("HDF5Writer::write: error, unknown datatype in Lattice IO!");
1451 }
1452 if(profile) swatch_reorder.stop();
1453
1454 //write out the stuff:
1455 if(profile) swatch_write.start();
1456 writeLattice(name,type_id,obj_size*arr_size,reinterpret_cast<char*>(buf));
1457
1458 //clean up
1459 H5Tclose(type_id);
1460 delete [] buf;
1461 if(profile) swatch_write.stop();
1462
1463 if(profile){
1464 QDPIO::cout << "HDF5-I/O statistics. Write:" << std::endl;
1465 QDPIO::cout << "\t preparing: " << swatch_prepare.getTimeInSeconds() << " s." << std::endl;
1466 QDPIO::cout << "\t reordering: " << swatch_reorder.getTimeInSeconds() << " s." << std::endl;
1467 QDPIO::cout << "\t write: " << swatch_write.getTimeInSeconds() << " s." << std::endl;
1468 QDPIO::cout << "\t MB written: " << Layout::vol()*fieldarray.size()*sizeof(T)/1024/1024 << std::endl;
1469 }
1470 }
1471
1472 //special gauge archive IO:
1473 //Qlua:
1474 void writeQlua(const std::string& name, const multi1d<LatticeColorMatrixD3>& field, const HDF5Base::writemode& mode=HDF5Base::ate);
1475
1476 };
1477
1478 //template specializations for OScalar<T> datatypes:
1479 //complex types
1480 //single datum
1481 template<>
1482 void HDF5Writer::write< PScalar< PScalar< RComplex<float> > > >(const std::string& dataname, const ComplexF& datum, const HDF5Base::writemode& mode);
1483 template<>
1484 void HDF5Writer::write< PScalar< PScalar< RComplex<double> > > >(const std::string& dataname, const ComplexD& datum, const HDF5Base::writemode& mode);
1485
1486 //array:
1487 template<>
1488 void HDF5Writer::write< PScalar< PScalar< RComplex<float> > > >(const std::string& dataname, const multi1d<ComplexF>& datum, const HDF5Base::writemode& mode);
1489 template<>
1490 void HDF5Writer::write< PScalar< PScalar< RComplex<double> > > >(const std::string& dataname, const multi1d<ComplexD>& datum, const HDF5Base::writemode& mode);
1491
1492 //ColorMatrix
1493 //single datum
1494 template<>
1495 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL32>, 3> > >(const std::string& dataname, const ColorMatrixF3& datum, const HDF5Base::writemode& mode);
1496 template<>
1497 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(const std::string& dataname, const ColorMatrixD3& datum, const HDF5Base::writemode& mode);
1498
1499 //template specializations for OLattice<T> datatypes:
1500 //LatticeColorMatrix
1501 template<>
1502 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL32>, 3> > >(const std::string& name, const LatticeColorMatrixF3& field, const HDF5Base::writemode& mode);
1503 template<>
1504 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(const std::string& name, const LatticeColorMatrixD3& field, const HDF5Base::writemode& mode);
1505
1506 //LatticePropagator
1507 template<>
1508 void HDF5Writer::write< PSpinMatrix< PColorMatrix< RComplex<REAL32>, 3>, 4> >(const std::string& name, const LatticePropagatorF3& field, const HDF5Base::writemode& mode);
1509 template<>
1510 void HDF5Writer::write< PSpinMatrix< PColorMatrix< RComplex<REAL64>, 3>, 4> >(const std::string& name, const LatticePropagatorD3& field, const HDF5Base::writemode& mode);
1511
1512 //template specializations for multi1d<OLattice<T> > datatypes:
1513 //multi1d<LatticeColorMatrix>
1514 template<>
1516}
1517#endif
void open(const std::string &filename)
HDF5Reader()
Empty constructor.
~HDF5Reader()
Destructor:
HDF5Reader(const long int &stripesize, const long int &maxalign=0)
HDF5Reader(const std::string &filename)
Construct from contents of file.
void push(const std::string &name)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const std::string &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &dataname, const std::string &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const unsigned long long &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void open(const std::string &filename)
Definition qdp_hdf5.h:1250
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const double &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const unsigned short &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void deleteAllAttributes(const std::string &obj_name)
void write(const std::string &obj_name, const multi1d< unsigned long long > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi1d< double > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
HDF5Writer()
Empty constructors.
void write(const std::string &obj_name, const multi1d< unsigned int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi1d< short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const short &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &name, const multi1d< OLattice< T > > &fieldarray, const HDF5Base::writemode &mode=HDF5Base::ate)
Definition qdp_hdf5.h:1415
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< double > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< float > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< float > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeQlua(const std::string &name, const multi1d< LatticeColorMatrixD3 > &field, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi1d< int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< unsigned long long > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< unsigned short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void mkdir(const ::std::string &name)
void write(const std::string &obj_name, const int &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi1d< unsigned short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void open(const std::string &filename, const HDF5Base::writemode &mode)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const unsigned int &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const int &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
~HDF5Writer()
Destructor.
void write(const std::string &obj_name, const float &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const unsigned int &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
HDF5Writer(const long int &stripesize, const long int &maxalign=0)
void deleteAttribute(const std::string &obj_name, const std::string &attr_name)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const float &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const unsigned long long &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &name, const OScalar< T > &scalar, const HDF5Base::writemode &mode=HDF5Base::ate)
Definition qdp_hdf5.h:1328
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< unsigned int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< unsigned int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi1d< float > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &name, const multi1d< OScalar< T > > &scalararray, const HDF5Base::writemode &mode=HDF5Base::ate)
Definition qdp_hdf5.h:1340
void write(const std::string &name, const OLattice< T > &field, const HDF5Base::writemode &mode=HDF5Base::ate)
Definition qdp_hdf5.h:1359
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< double > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const multi2d< unsigned long long > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const double &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void write(const std::string &obj_name, const unsigned short &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const short &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
HDF5Writer(const std::string &filename, const HDF5Base::writemode &mode=HDF5Base::ate)
Construct from contents of file.
void write(const std::string &obj_name, const multi2d< unsigned short > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void writeAttribute(const std::string &obj_name, const std::string &attr_name, const multi1d< int > &datum, const HDF5Base::writemode &mode=HDF5Base::ate)
void rdAtt(const std::string &obj_name, const std::string &attr_name, multi1d< ctype > &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
Definition qdp_hdf5.h:207
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< unsigned long long > &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, unsigned short &datum)
virtual void open(const std::string &filename)=0
void cd(const std::string &dirname)
void read(const std::string &obj_name, multi1d< int > &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, unsigned int &datum)
MPI_Comm * mpicomm
Definition qdp_hdf5.h:55
void rd(const std::string &dataname, multi1d< ctype > &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
Definition qdp_hdf5.h:325
void read(const std::string &obj_name, multi2d< unsigned short > &datum)
void read(const std::string &obj_name, float &datum)
std::vector< std::string > splitPathname(const std::string &name)
hid_t current_group
Definition qdp_hdf5.h:44
bool profile
Definition qdp_hdf5.h:53
void read(const std::string &obj_name, multi1d< float > &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, int &datum)
void read(const std::string &name, OLattice< T > &field, const HDF5Base::accessmode &accmode=HDF5Base::transpose_order)
Definition qdp_hdf5.h:653
HDF5(const long int &stripesizee=-1, const long int &maxalign=0)
hid_t error_stack
Definition qdp_hdf5.h:44
void readAttribute(const std::string &obj_name, const std::string &attr_name, std::string &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< int > &datum)
void rdAtt(const std::string &obj_name, const std::string &attr_name, ctype &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
Definition qdp_hdf5.h:157
void readQlua(const std::string &name, LatticeDiracPropagatorD3 &prop)
void set_profiling(const bool &profilee)
Definition qdp_hdf5.h:489
void CvtToLayout(OLattice< T > &field, void *buf, const unsigned int &nodeSites, const unsigned int &elemSize)
Definition qdp_hdf5.h:91
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< double > &datum)
int close()
std::string getNameById(hid_t id) const
bool isprefetched
Definition qdp_hdf5.h:46
bool objectExists(hid_t loc_id, const std::string &name)
bool checkComplexType(const hid_t &type_id, hid_t &base_type_id)
void CvtToHost(void *buf, const OLattice< T > &field, const unsigned int &nodeSites, const unsigned int &elemSize)
Definition qdp_hdf5.h:110
hid_t file_id
Definition qdp_hdf5.h:44
void read(const std::string &obj_name, multi2d< short > &datum)
multi1d< int > reordermap
Definition qdp_hdf5.h:45
void read(const std::string &obj_name, unsigned int &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, double &datum)
bool objectExists(const std::string &name)
void read(const std::string &obj_name, multi2d< unsigned int > &datum)
void read(const std::string &obj_name, unsigned long long &datum)
long int maxalign
Definition qdp_hdf5.h:49
void rd(const std::string &dataname, multi2d< ctype > &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
Definition qdp_hdf5.h:393
void read(const std::string &name, OScalar< T > &scalar)
Definition qdp_hdf5.h:565
hid_t createComplexType(const unsigned int &float_size)
hid_t createPropagatorType(const hid_t &colmat_id, const unsigned int &spinrank)
std::string parentDir() const
void HDF5_error_exit(const std::string &message)
Definition qdp_hdf5.h:76
void read(const std::string &obj_name, multi1d< double > &datum)
void readAttribute(const std::string &obj_name, const std::string &attr_name, unsigned long long &datum)
static bool check_exists(const std::string &filename)
void rd(const std::string &dataname, ctype &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
Definition qdp_hdf5.h:272
void readAttribute(const std::string &obj_name, const std::string &attr_name, short &datum)
void read(const std::string &dataname, std::string &datum)
bool checkColorMatrixType(const hid_t &type_id, const unsigned int &rank, hid_t &base_type_id)
void read(const std::string &obj_name, int &datum)
void readQlua(const std::string &name, multi1d< LatticeColorMatrixD3 > &field)
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< short > &datum)
void CvtToLayout(multi1d< OLattice< T > > &fieldarray, void *buf, const unsigned int &nodeSites, const unsigned int &arraySize, const unsigned int &elemSize)
Definition qdp_hdf5.h:99
void readAttribute(const std::string &obj_name, const std::string &attr_name, float &datum)
bool checkDiracPropagatorType(const hid_t &type_id, const unsigned int &spinrank, const unsigned int &colorrank, hid_t &base_type_id)
void read(const std::string &obj_name, multi1d< unsigned long long > &datum)
long int stripesize
Definition qdp_hdf5.h:49
void read(const std::string &obj_name, multi2d< unsigned long long > &datum)
bool par_init
Definition qdp_hdf5.h:52
int prefetchLatticeCoordinates()
static hid_t errorHandler(hid_t errstack, void *unused)
void CvtToHost(void *buf, const multi1d< OLattice< T > > &fieldarray, const unsigned int &nodeSites, const unsigned int &arraySize, const unsigned int &elemSize)
Definition qdp_hdf5.h:118
void read(const std::string &obj_name, multi2d< float > &datum)
void read(const std::string &obj_name, multi2d< double > &datum)
void read(const std::string &name, multi1d< OScalar< T > > &scalararray)
Definition qdp_hdf5.h:604
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< unsigned short > &datum)
void read(const std::string &obj_name, short &datum)
void read(const std::string &obj_name, multi1d< unsigned short > &datum)
std::string objectType(const ::std::string &name)
void tokenize(const ::std::string &str, ::std::vector< ::std::string > &tokens, const ::std::string &delimiters)
void readLattice(const std::string &name, const hid_t &type_id, const hid_t &base_type_id, const ullong &obj_size, const ullong &tot_size, char *buf, bool invert_order=true)
hid_t file_comm
Definition qdp_hdf5.h:44
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< float > &datum)
void read(const std::string &name, multi1d< OLattice< T > > &fieldarray, const HDF5Base::accessmode &accmode=HDF5Base::transpose_order)
Definition qdp_hdf5.h:767
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< unsigned int > &datum)
void read(const std::string &obj_name, unsigned short &datum)
void readPrepare(const std::string &name, hid_t &type_id)
void read(const std::string &obj_name, multi1d< short > &datum)
void read(const std::string &obj_name, double &datum)
void read(const std::string &obj_name, multi2d< int > &datum)
hid_t createColorMatrixType(const hid_t &complex_id, const unsigned int &rank)
std::string pwd() const
std::string objectType(hid_t loc_id, const ::std::string &name)
void pop()
void read(const std::string &obj_name, multi1d< unsigned int > &datum)
void set_stripesize(const int &stripesizee)
Definition qdp_hdf5.h:486
void readPrepareLattice(const std::string &name, hid_t &type_id, multi1d< ullong > &sizes)
Outer grid Lattice type.
Definition qdp_outer.h:264
T & elem(int i)
Definition qdp_outer.h:400
Outer grid Scalar class *‍/.
Definition qdp_outer.h:37
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
int size() const
Size of array.
Definition qdp_multi.h:60
void resize(int ns1)
Resize routine, call a templated resize, using *this to disambiguate.
Definition qdp_multi.h:56
Container for a multi-dimensional 2D array.
Definition qdp_multi.h:640
void resize(int ns2, int ns1)
Allocate mem for the array.
Definition qdp_multi.h:657
int size1() const
Size of array.
Definition qdp_multi.h:673
int size2() const
Definition qdp_multi.h:674
OScalar< PScalar< PScalar< RComplex< REAL32 > > > > ComplexF
OScalar< PScalar< PColorMatrix< RComplex< REAL32 >, 3 > > > ColorMatrixF3
OLattice< PSpinMatrix< PColorMatrix< RComplex< REAL64 >, 3 >, 4 > > LatticeDiracPropagatorD3
OScalar< PScalar< PColorMatrix< RComplex< REAL64 >, 3 > > > ColorMatrixD3
OScalar< PScalar< PScalar< RComplex< REAL64 > > > > ComplexD
OLattice< PSpinMatrix< PColorMatrix< RComplex< REAL32 >, 3 >, 4 > > LatticeDiracPropagatorF3
REAL32 REAL
double REAL64
OLattice< PScalar< PColorMatrix< RComplex< REAL32 >, 3 > > > LatticeColorMatrixF3
OLattice< PScalar< PColorMatrix< RComplex< REAL64 >, 3 > > > LatticeColorMatrixD3
OLattice< PSpinMatrix< PColorMatrix< RComplex< REAL32 >, 3 >, Ns > > LatticePropagatorF3
OLattice< PSpinMatrix< PColorMatrix< RComplex< REAL64 >, 3 >, Ns > > LatticePropagatorD3
const int Nd
Definition qdp_params.h:24
double getTimeInSeconds()
Get time in seconds.
void start()
Start the timer.
void stop()
Stop the timer.
int nodeNumber()
Returns the node number of this node.
int sitesOnNode()
Subgrid lattice volume.
const multi1d< int > & lattSize()
Virtual grid (problem grid) lattice size.
int vol()
Total lattice volume.
StandardOutputStream cout
Definition qdp_stdio.cc:21
StandardOutputStream cerr
Definition qdp_stdio.cc:22
Yet another random number generator.
void assert_global_size(const multi1d< ctype > &datum)
Definition qdp_hdf5.h:906
bool is_global(const ctype l)
Definition qdp_hdf5.h:899
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
bool get_global(ctype &global, const ctype &local)
#define local
Definition qdp_crc32.cc:51
unsigned long long ullong
Definition qdp_hdf5.h:24
Timer support.