58 explicit HDF5(
const long int& stripesizee=-1,
const long int&
maxalign=0);
64 void tokenize(const ::std::string& str, ::std::vector< ::std::string >& tokens, const ::std::string& delimiters);
71 std::string
objectType(hid_t loc_id, const ::std::string& name);
93 for(
unsigned int run=0; run<nodeSites; run++){
94 memcpy(&(field.
elem(
reordermap[run])),
reinterpret_cast<char*
>(buf)+run*elemSize,elemSize);
99 inline void CvtToLayout(
multi1d<
OLattice<T> >& fieldarray,
void* buf,
const unsigned int& nodeSites,
const unsigned int& arraySize,
const unsigned int& elemSize){
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);
110 inline void CvtToHost(
void* buf,
const OLattice<T>& field,
const unsigned int& nodeSites,
const unsigned int& elemSize){
112 for(
unsigned int run=0; run<nodeSites; run++){
113 memcpy(
reinterpret_cast<char*
>(buf)+run*elemSize,&(field.
elem(
reordermap[run])),elemSize);
118 inline void CvtToHost(
void* buf,
const multi1d<
OLattice<T> >& fieldarray,
const unsigned int& nodeSites,
const unsigned int& arraySize,
const unsigned int& elemSize){
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);
148 bool checkDiracPropagatorType(
const hid_t& type_id,
const unsigned int& spinrank,
const unsigned int& colorrank, hid_t& base_type_id);
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){
159 unsigned int size=
sizeof(ctype);
161 std::string oname(obj_name), aname(attr_name);
164 HDF5_error_exit(
"HDF5Reader::readAttribute: error, object "+oname+
" you try to read attribute from does not exists!");
168 hid_t ex=H5Aexists_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
170 HDF5_error_exit(
"HDF5Reader::readAttribute: error, the attribute "+aname+
" you try to read does not exists!");
172 hid_t attr_id=H5Aopen_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT,H5P_DEFAULT);
174 HDF5_error_exit(
"HDF5Reader::readAttribute: error, cannot open attribute "+aname+
" attached to "+oname+
"!");
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!");
181 if(H5Tget_size(type_id)!=size){
182 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype size mismatch!");
184 if( hdfclass==H5T_INTEGER ){
186 if(H5Tget_sign(type_id)!=H5T_SGN_2){
187 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype sign mismatch!");
191 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
192 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype sign mismatch!");
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);
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){
209 unsigned int size=
sizeof(ctype);
211 std::string oname(obj_name), aname(attr_name);
214 HDF5_error_exit(
"HDF5Reader::readAttribute: error, object "+oname+
" you try to read attribute from does not exists!");
218 hid_t ex=H5Aexists_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
220 HDF5_error_exit(
"HDF5Reader::readAttribute: error, the attribute "+aname+
" you try to read does not exists!");
222 hid_t attr_id=H5Aopen_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT,H5P_DEFAULT);
224 HDF5_error_exit(
"HDF5Reader::readAttribute: error, cannot open attribute "+aname+
" attached to "+oname+
"!");
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!");
231 if(H5Tget_size(type_id)!=size){
232 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype size mismatch!");
234 if( hdfclass==H5T_INTEGER ){
236 if(H5Tget_sign(type_id)!=H5T_SGN_2){
237 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype sign mismatch!");
241 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
242 HDF5_error_exit(
"HDF5Reader::readAttribute: error reading "+attr_name+
", datatype sign mismatch!");
249 hid_t space_id=H5Aget_space(attr_id);
253 hsize_t space_size=H5Sget_simple_extent_npoints(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));
259 H5Tclose(nat_type_id);
262 for(hsize_t i=0; i<space_size; i++) datum[i]=token[i];
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){
274 unsigned int size=
sizeof(ctype);
276 std::string dname(dataname);
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!");
286 hid_t dset_id=H5Dopen(
current_group,dname.c_str(),H5P_DEFAULT);
288 HDF5_error_exit(
"HDF5Reader::read: error reading "+dataname+
", cannot open dataset!");
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!");
296 if(H5Tget_size(type_id)!=size){
297 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype size mismatch!");
299 if( hdfclass==H5T_INTEGER ){
301 if(H5Tget_sign(type_id)!=H5T_SGN_2){
302 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
306 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
307 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
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));
320 H5Tclose(nat_type_id);
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){
327 unsigned int size=
sizeof(ctype);
329 std::string dname(dataname);
332 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", dataset does not exists!");
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!");
339 hid_t dset_id=H5Dopen(
current_group,dname.c_str(),H5P_DEFAULT);
341 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", cannot open dataset!");
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!");
349 if(H5Tget_size(type_id)!=size){
350 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype size mismatch!");
352 if( hdfclass==H5T_INTEGER ){
354 if(H5Tget_sign(type_id)!=H5T_SGN_2){
355 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
359 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
360 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
367 hid_t space_id=H5Dget_space(dset_id);
372 hsize_t dim=H5Sget_simple_extent_ndims(space_id);
376 hsize_t space_size=H5Sget_simple_extent_npoints(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));
385 H5Tclose(nat_type_id);
388 for(hsize_t i=0; i<space_size; i++) datum[i]=token[i];
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){
395 unsigned int size=
sizeof(ctype);
397 std::string dname(dataname);
400 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", dataset does not exists!");
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!");
407 hid_t dset_id=H5Dopen(
current_group,dname.c_str(),H5P_DEFAULT);
409 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", cannot open dataset!");
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!");
417 if(H5Tget_size(type_id)!=size){
418 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype size mismatch!");
420 if( hdfclass==H5T_INTEGER ){
422 if(H5Tget_sign(type_id)!=H5T_SGN_2){
423 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
427 if(H5Tget_sign(type_id)!=H5T_SGN_NONE){
428 HDF5_error_exit(
"HDF5::read: error reading "+dataname+
", datatype sign mismatch!");
435 hid_t space_id=H5Dget_space(dset_id);
439 hsize_t dim=H5Sget_simple_extent_ndims(space_id);
444 errhandle=H5Sget_simple_extent_dims(space_id, dims, NULL);
445 hsize_t space_size=H5Sget_simple_extent_npoints(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));
454 H5Tclose(nat_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];
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);
479 virtual void open(
const std::string& filename) = 0;
498 void cd(
const std::string& dirname);
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);
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);
574 ullong float_size=H5Tget_size(type_id);
575 if( float_size!=4 && float_size!=8 ){
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");
591 this->
read(name,buf32);
592 for(
ullong i=0; i<obj_size; i++) buf[i]=static_cast<REAL>(buf32[i]);
596 this->
read(name,buf64);
597 for(
ullong i=0; i<obj_size; i++) buf[i]=static_cast<REAL>(buf64[i]);
599 memcpy(
reinterpret_cast<void*
>(&scalar.
elem()),&buf[0],
sizeof(T));
613 ullong float_size=H5Tget_size(type_id);
614 if( float_size!=4 && float_size!=8 ){
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");
625 ullong arr_size=(obj_size*float_size)/
sizeof(T);
632 this->
read(name,buf32);
633 for(
ullong i=0; i<(obj_size*arr_size); i++) buf[i]=static_cast<REAL>(buf32[i]);
637 this->
read(name,buf64);
638 for(
ullong i=0; i<(obj_size*arr_size); i++) buf[i]=static_cast<REAL>(buf64[i]);
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));
655 StopWatch swatch_datatypes, swatch_prepare, swatch_reorder, swatch_read;
680 ullong hdf5_float_size=H5Tget_size(type_id);
681 ullong field_float_size=
sizeof(wtd);
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");
691 for(
unsigned int dd=0; dd<
Nd; dd++){
698 for(
unsigned int dd=0; dd<
Nd; dd++){
714 size_t tot_size = obj_size*nodeSites;
715 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
719 readLattice(name,type_id,type_id,obj_size,tot_size,buf,invert_order);
730 if(hdf5_float_size==field_float_size){
732 CvtToLayout(field,
reinterpret_cast<void*
>(buf),nodeSites,
sizeof(T));
736 wtd* tmpbuf=
new wtd[tot_size];
737 for(
unsigned int i=0; i<tot_size; i++){
738 if(hdf5_float_size==4){
740 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
741 tmpbuf[i]=
static_cast< wtd
>(tmpfloat);
745 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
746 tmpbuf[i]=
static_cast< wtd
>(tmpfloat);
749 CvtToLayout(field,
reinterpret_cast<void*
>(tmpbuf),nodeSites,
sizeof(T));
756 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
761 QDPIO::cout <<
"\t MB read: " <<
static_cast<int>(
Layout::vol()*obj_size*hdf5_float_size)/1024/1024 << std::endl;
769 StopWatch swatch_datatypes, swatch_prepare, swatch_reorder, swatch_read;
790 swatch_prepare.
stop();
794 ullong hdf5_float_size=H5Tget_size(type_id);
795 ullong field_float_size=
sizeof(wtd);
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");
805 for(
unsigned int dd=0; dd<
Nd; dd++){
812 for(
unsigned int dd=0; dd<
Nd; dd++){
823 ullong arr_size=(obj_size*field_float_size)/
sizeof(T);
831 size_t tot_size = obj_size*arr_size*nodeSites;
832 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
836 readLattice(name,type_id,type_id,obj_size*arr_size,tot_size,buf,invert_order);
843 fieldarray.resize(arr_size);
850 if(hdf5_float_size==field_float_size){
852 CvtToLayout(fieldarray,
reinterpret_cast<void*
>(buf),nodeSites,arr_size,
sizeof(T));
856 wtd* tmpbuf=
new wtd[tot_size];
857 for(
unsigned int i=0; i<tot_size; i++){
858 if(hdf5_float_size==4){
860 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
861 tmpbuf[i]=
static_cast< wtd
>(tmpfloat);
865 memcpy(&tmpfloat,&buf[i*hdf5_float_size],hdf5_float_size);
866 tmpbuf[i]=
static_cast< wtd
>(tmpfloat);
869 CvtToLayout(fieldarray,
reinterpret_cast<void*
>(tmpbuf),nodeSites,arr_size,
sizeof(T));
876 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
881 QDPIO::cout <<
"\t MB read: " <<
static_cast<int>(
Layout::vol()*fieldarray.size()*obj_size*hdf5_float_size)/1024/1024 << std::endl;
892 template<
typename ctype>
895 template<
typename ctype>
898 template<
typename ctype>
905 template <
typename ctype>
909 QDP_error_exit(
"qdp_hdf5.h assert_global_size: multi1d.size not global!");
912 template <
typename ctype>
916 QDP_error_exit(
"qdp_hdf5.h assert_global_size: multi2d.size2 not global!");
919 QDP_error_exit(
"qdp_hdf5.h assert_global_size: multi2d.size1 not global!");
971 void open(
const std::string& filename);
984 void commitType(
const std::string& name, hid_t dtype_id){
986 htri_t iscommitted=H5Tcommitted(dtype_id);
989 herr_t errhandle=H5Tcommit(
file_id,name.c_str(),dtype_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
994 static herr_t rmAtt(hid_t location_id,
const char *attr_name,
const H5A_info_t* attrinfo,
void* opdata);
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);
1007 QDPIO::cerr <<
"HDF5Writer::writeAttribute() warning: " << obj_name
1008 <<
".attrib(" << attr_name
1009 <<
") was NOT global. Using node=0 value now." << std::endl;
1014 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, object "+oname+
" you try to write attribute to does not exists!");
1017 hid_t ex=H5Aexists_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1020 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, attribute "+aname+
" already exists!");
1022 herr_t errhandle=H5Adelete_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
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));
1029 H5Sclose(attr_space_id);
1032 template<
typename ctype>
1034 std::string oname(obj_name), aname(attr_name);
1038 QDPIO::cerr <<
"HDF5Writer::writeAttribute() warning: " << obj_name
1039 <<
".attrib(" << attr_name
1040 <<
") was NOT global. Using node=0 value now." << std::endl;
1045 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, object "+oname+
" you try to write attribute to does not exists!");
1048 hid_t ex=H5Aexists_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1051 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, attribute "+aname+
" already exists!");
1053 herr_t errhandle=H5Adelete_by_name(
current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
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;
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));
1072 H5Sclose(attr_space_id);
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;
1088 HDF5_error_exit(
"HDF5Writer::write: error, dataset already exists and you specified not to overwrite!\n");
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!");
1095 errhandle=H5Ldelete(
current_group,dname.c_str(),H5P_DEFAULT);
1098 spaceid=H5Screate(H5S_SCALAR);
1099 dataid=H5Dcreate(
current_group,dname.c_str(),hdftype,spaceid,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1102 ctype datumcpy=datum;
1103 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1105 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1107 if(
Layout::nodeNumber()==0) H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,
reinterpret_cast<void*
>(&datumcpy));
1112 template<
typename ctype>
1114 std::string dname(dataname);
1115 hid_t dataid, spaceid;
1121 HDF5_error_exit(
"HDF5Writer::write: error, object named "+dname+
" already exists and you specified not to overwrite it!");
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!");
1128 errhandle=H5Ldelete(
current_group,dname.c_str(),H5P_DEFAULT);
1131 spaceid=H5Screate(H5S_SIMPLE);
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);
1138 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1139 herr_t status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1143 ctype* datumcpy=
new(std::nothrow) ctype[datum.size()];
1145 if ( datumcpy != 0x0 ) {
1146 for(
ullong i=0; i<datum.size(); i++)
1147 datumcpy[i]=datum[i];
1149 status = H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,
static_cast<void*
>(datumcpy));
1153 QDPIO::cerr <<
"HDF5Writer::wt - buffer alloc failed" << std::endl;
1163 status = H5Pclose(plist_id);
1164 status = H5Dclose(dataid);
1167 template<
typename ctype>
1169 std::string dname(dataname);
1170 hid_t dataid, spaceid;
1176 HDF5_error_exit(
"HDF5Writer::write: error, object named "+dname+
" already exists and you specified not to overwrite it!");
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!");
1183 errhandle=H5Ldelete(
current_group,dname.c_str(),H5P_DEFAULT);
1187 hsize_t rank =
static_cast<hsize_t
>(2);
1188 hsize_t spacesize[2];
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);
1198 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1199 herr_t status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
1203 ctype* datumcpy =
new(std::nothrow) ctype[spacesize[0]*spacesize[1]];
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);
1212 status = H5Dwrite(dataid,hdftype,H5S_ALL,H5S_ALL,plist_id,
static_cast<void*
>(datumcpy));
1216 QDPIO::cerr <<
"HDF5Writer::wt - buffer alloc failed" << std::endl;
1226 status = H5Pclose(plist_id);
1227 status = H5Dclose(dataid);
1236 void writeLattice(
const std::string& name,
const hid_t& datatype,
const ullong& obj_size,
char* buf);
1250 void open(
const std::string& filename){
1259 void push(
const std::string& name);
1331 size_t float_size=
sizeof(
REAL);
1332 size_t obj_size=
sizeof(T)/float_size;
1334 memcpy(
reinterpret_cast<char*
>(&buf[0]),&(scalar.
elem()),
sizeof(T));
1335 write(name,buf,mode);
1343 size_t float_size=
sizeof(
REAL);
1344 size_t obj_size=
sizeof(T)/float_size;
1345 size_t arr_size=scalararray.size();
1347 for(
ullong i=0; i<arr_size; i++){
1348 memcpy(
reinterpret_cast<char*
>(&buf[i*obj_size]),&(scalararray[i].elem()),
sizeof(T));
1350 write(name,buf,mode);
1361 StopWatch swatch_prepare, swatch_reorder, swatch_write;
1365 writePrepare(name,mode);
1374 size_t float_size=
sizeof(
REAL);
1375 size_t obj_size=
sizeof(T)/float_size;
1376 REAL* buf=
new REAL[nodeSites*obj_size];
1381 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,float_size*obj_size);
1387 type_id=H5Tcopy(H5T_NATIVE_FLOAT);
1389 else if(float_size==8){
1390 type_id=H5Tcopy(H5T_NATIVE_DOUBLE);
1393 HDF5_error_exit(
"HDF5Writer::write: error, unknown datatype in Lattice IO!");
1398 writeLattice(name,type_id,obj_size,
reinterpret_cast<char*
>(buf));
1406 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
1417 StopWatch swatch_prepare, swatch_reorder, swatch_write;
1421 writePrepare(name,mode);
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];
1440 CvtToHost(
reinterpret_cast<void*
>(buf),fieldarray,nodeSites,arr_size,float_size*obj_size);
1444 type_id=H5Tcopy(H5T_NATIVE_FLOAT);
1446 else if(float_size==8){
1447 type_id=H5Tcopy(H5T_NATIVE_DOUBLE);
1450 HDF5_error_exit(
"HDF5Writer::write: error, unknown datatype in Lattice IO!");
1456 writeLattice(name,type_id,obj_size*arr_size,
reinterpret_cast<char*
>(buf));
1464 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
void open(const std::string &filename)
HDF5Reader()
Empty constructor.
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)
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)
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)
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)
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)
void write(const std::string &name, const OLattice< T > &field, const HDF5Base::writemode &mode=HDF5Base::ate)
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)
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)
void rd(const std::string &dataname, multi1d< ctype > &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
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)
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)
HDF5(const long int &stripesizee=-1, const long int &maxalign=0)
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)
void readQlua(const std::string &name, LatticeDiracPropagatorD3 &prop)
void set_profiling(const bool &profilee)
void CvtToLayout(OLattice< T > &field, void *buf, const unsigned int &nodeSites, const unsigned int &elemSize)
void readAttribute(const std::string &obj_name, const std::string &attr_name, multi1d< double > &datum)
std::string getNameById(hid_t id) const
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)
void read(const std::string &obj_name, multi2d< short > &datum)
multi1d< int > reordermap
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)
void rd(const std::string &dataname, multi2d< ctype > &datum, const H5T_class_t &hdfclass, const bool &sign, const bool &rigid_checks=true)
void read(const std::string &name, OScalar< T > &scalar)
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)
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)
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)
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)
void read(const std::string &obj_name, multi2d< unsigned long long > &datum)
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)
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)
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)
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)
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 objectType(hid_t loc_id, const ::std::string &name)
void read(const std::string &obj_name, multi1d< unsigned int > &datum)
void set_stripesize(const int &stripesizee)
void readPrepareLattice(const std::string &name, hid_t &type_id, multi1d< ullong > &sizes)
Outer grid Scalar class */.
Container for a multi-dimensional 1D array.
int size() const
Size of array.
void resize(int ns1)
Resize routine, call a templated resize, using *this to disambiguate.
Container for a multi-dimensional 2D array.
void resize(int ns2, int ns1)
Allocate mem for the array.
int size1() const
Size of array.
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
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
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
StandardOutputStream cerr
Yet another random number generator.
void assert_global_size(const multi1d< ctype > &datum)
bool is_global(const ctype l)
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
bool get_global(ctype &global, const ctype &local)
unsigned long long ullong