24 HDF5::HDF5(
const long int& stripesizee,
const long int& maxalignn) :
25 error_stack(H5E_DEFAULT), par_init(false), file_comm(H5P_DEFAULT),
26 file_id(-1), current_group(-1),
27 stripesize(stripesizee),
35 herr_t err=H5dont_atexit();
42 H5Eget_auto(error_stack, &oldfunc, &client_data);
50 bool HDF5::check_exists(
const std::string& filename){
53 if(Layout::nodeNumber()==0){
54 std::ifstream input(filename.c_str(),std::ios_base::binary);
61 htri_t ex=H5Fis_hdf5(filename.c_str());
62 if(ex<=0) exists=
false;
65 QDPInternal::broadcast(exists);
71 hid_t HDF5::errorHandler(hid_t errstack,
void* unused){
72 QDPIO::cout <<
"Some error occured, but we do not care at the moment!" << std::endl;
77 std::string HDF5::pwd()
const{
78 return getNameById(current_group);
81 std::string HDF5::parentDir()
const{
83 std::string dir=pwd();
84 if((pos=dir.find_last_of(
"/"))==0)
return std::string(
"/");
85 return dir.substr(0,pos);
88 std::string HDF5::getNameById(hid_t
id)
const{
89 ssize_t size=H5Iget_name(
id,NULL,0);
90 char* val=
new char[size+1];
91 H5Iget_name(
id,val,size+1);
92 std::string name(val);
97 void HDF5::tokenize(const ::std::string& str, ::std::vector< ::std::string >& tokens, const ::std::string& delimiters){
99 ::std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
101 ::std::string::size_type pos = str.find_first_of(delimiters, lastPos);
103 while (::std::string::npos != pos || ::std::string::npos != lastPos){
105 tokens.push_back(str.substr(lastPos, pos - lastPos));
107 lastPos = str.find_first_not_of(delimiters, pos);
109 pos = str.find_first_of(delimiters, lastPos);
113 std::vector<std::string> HDF5::splitPathname(
const std::string& name){
115 ::std::vector<std::string> dirlist;
116 tokenize(name, dirlist,
"/");
119 ::std::vector<std::string>::iterator it;
120 for(it=dirlist.begin(); it!=dirlist.end(); it++){
121 if(*it==
"") dirlist.erase(it);
128 bool HDF5::objectExists(const ::std::string& name){
129 return objectExists(file_id,name);
132 bool HDF5::objectExists(hid_t loc_id,
const std::string& name){
133 std::vector<std::string> dirlist=splitPathname(name);
136 if(name.find_first_of(
"/")==0){
139 else start_group=loc_id;
142 htri_t exists=H5Lexists(start_group,dirlist[0].c_str(),H5P_DEFAULT);
143 if(exists!=1)
return false;
144 exists=H5Oexists_by_name(start_group,dirlist[0].c_str(),H5P_DEFAULT);
145 if(exists!=1)
return false;
146 std::string tmpstring=dirlist[0];
147 for(
unsigned int i=1; i<dirlist.size(); i++){
148 tmpstring+=
"/"+dirlist[i];
149 exists=H5Lexists(start_group,tmpstring.c_str(),H5P_DEFAULT);
150 if(exists!=1)
return false;
151 exists=H5Oexists_by_name(start_group,tmpstring.c_str(),H5P_DEFAULT);
152 if(exists!=1)
return false;
157 ::std::string HDF5::objectType(const ::std::string& name){
158 return objectType(file_id, name);
161 ::std::string HDF5::objectType(hid_t loc_id, const ::std::string& name){
162 std::string result=
"Null";
163 if(objectExists(loc_id, name)){
165 herr_t errhandle=H5Oget_info_by_name(loc_id,name.c_str(),&objinfo,H5P_DEFAULT);
167 ::std::cerr <<
"HDF5::objectType: error, something went wrong with looking up " << name <<
"!" << std::endl;
170 switch(objinfo.type){
175 case H5O_TYPE_DATASET:
179 case H5O_TYPE_NAMED_DATATYPE:
180 result=
"NamedDatatype";
183 case H5O_TYPE_NTYPES:
184 result=
"VariousTypes";
200 if(pwd().compare(
"/")!=0){
204 ::std::string cdir=pwd();
205 ::std::string pdir=parentDir();
208 H5Gclose(current_group);
209 tmp_group=H5Gopen(file_id,pdir.c_str(),H5P_DEFAULT);
211 current_group=tmp_group;
215 void HDF5::cd(
const std::string& dirname){
216 std::string tmpdirname(dirname);
217 if(tmpdirname.compare(
"..")==0){
220 else if(tmpdirname.compare(pwd())!=0){
224 tmp_group=H5Gopen(current_group,tmpdirname.c_str(),H5P_DEFAULT);
227 QDPIO::cerr <<
"HDF5::cd: error, the group " << tmpdirname <<
" does not exist!" << std::endl;
232 std::string ndir=getNameById(tmp_group);
233 std::string cdir=pwd();
236 if(ndir.find(cdir)==::std::string::npos || ndir.compare(
"/")==0){
238 while(pwd().compare(
"/")!=0){
242 else if(cdir.find(ndir)==0){
244 while(current_group!=tmp_group){
248 current_group=tmp_group;
257 unsigned int types=H5F_OBJ_DATASET | H5F_OBJ_GROUP |
258 H5F_OBJ_DATATYPE | H5F_OBJ_ATTR;
261 ssize_t num_open = H5Fget_obj_count(file_id,types);
263 std::vector<hid_t> open_object_ids(num_open, 0);
264 H5Fget_obj_ids(file_id, types, num_open, &(open_object_ids.front()) );
265 for(
unsigned int i=0; i<num_open; i++){
266 err=H5Oclose(open_object_ids[i]);
269 err=H5Fclose(file_id);
279 int HDF5::prefetchLatticeCoordinates(){
280 const int mynode = Layout::nodeNumber();
283 reordermap.resize(Layout::sitesOnNode());
286 for(
int site=0; site < Layout::vol(); ++site){
287 multi1d<int> coord =
crtesn(site, Layout::lattSize());
288 int node = Layout::nodeNumber(coord);
291 reordermap[run]=Layout::linearSiteIndex(coord);
306 hid_t HDF5::createComplexType(
const unsigned int& float_size){
307 hid_t complex_id = H5Tcreate(H5T_COMPOUND, 2*float_size);
310 if(float_size==4) base_type=H5Tcopy(H5T_NATIVE_FLOAT);
311 else base_type=H5Tcopy(H5T_NATIVE_DOUBLE);
313 H5Tinsert(complex_id,
"r", 0, base_type);
314 H5Tinsert(complex_id,
"i", float_size, base_type);
321 bool HDF5::checkComplexType(
const hid_t& type_id, hid_t& base_type_id){
323 if(H5Tget_class(type_id)!=H5T_COMPOUND){
327 if(H5Tget_nmembers(type_id)!=2)
return false;
328 base_type_id=H5Tget_member_type(type_id,0);
329 htri_t err=H5Tequal(base_type_id,H5Tget_member_type(type_id,1));
337 char* name=H5Tget_member_name(type_id,0);
338 if( strcmp(name,
"r") != 0 ) error=
true;
340 name=H5Tget_member_name(type_id,1);
341 if( strcmp(name,
"i") != 0 ) error=
true;
352 hid_t HDF5::createColorMatrixType(
const hid_t& complex_id,
const unsigned int& rank){
353 if(rank>Nc || rank==0){
354 HDF5_error_exit(
"HDF::createColorMatrixType: error, the rank should be between 1 and Nc");
356 hsize_t dims[]={rank,rank};
357 hid_t colmat_id = H5Tarray_create(complex_id,2,dims);
363 bool HDF5::checkColorMatrixType(
const hid_t& type_id,
const unsigned int& rank, hid_t& base_type_id){
365 if( (H5Tget_class(type_id)!=H5T_ARRAY) || (H5Tget_array_ndims(type_id)!=2) ){
371 H5Tget_array_dims(type_id,dims);
372 if( (dims[0]!=dims[1]) || (dims[0]!=rank) ){
377 hid_t member_type=H5Tget_super(type_id);
378 if(!checkComplexType(member_type,base_type_id)){
381 H5Tclose(member_type);
387 hid_t HDF5::createPropagatorType(
const hid_t& colmat_id,
const unsigned int& spinrank){
388 if(spinrank>Ns || spinrank==0){
389 HDF5_error_exit(
"HDF::createPropagatorType: error, the spinrank should be between 1 and Ns");
391 hsize_t dims[]={spinrank,spinrank};
392 hid_t prop_id = H5Tarray_create(colmat_id,2,dims);
398 bool HDF5::checkDiracPropagatorType(
const hid_t& type_id,
const unsigned int& spinrank,
const unsigned int& colorrank, hid_t& base_type_id){
402 if( (H5Tget_class(type_id)!=H5T_ARRAY) || (H5Tget_array_ndims(type_id)!=2) ){
408 H5Tget_array_dims(type_id,dims);
409 if( (dims[0]!=dims[1]) || (dims[0]!=spinrank) ){
414 hid_t member_type=H5Tget_super(type_id);
415 if(!checkColorMatrixType(member_type,colorrank,base_type_id)){
418 H5Tclose(member_type);
430 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
short& datum){
431 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
true);
434 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
unsigned short& datum){
435 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
438 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
int& datum){
439 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
true);
442 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
unsigned int& datum){
443 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
446 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
unsigned long long& datum){
447 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
450 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
float& datum){
451 rdAtt(obj_name,attr_name,datum,H5T_FLOAT,
true);
454 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name,
double& datum){
455 rdAtt(obj_name,attr_name,datum,H5T_FLOAT,
true);
458 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, std::string& datum){
459 std::string oname(obj_name), aname(attr_name);
460 bool exists=objectExists(current_group,oname);
462 HDF5_error_exit(
"HDF5::readAttribute: error, object "+oname+
" you try to read attribute from does not exists!");
466 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
468 HDF5_error_exit(
"HDF5::readAttribute: error, the attribute "+aname+
" you try to read does not exists!");
470 hid_t attr_id=H5Aopen_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT,H5P_DEFAULT);
472 HDF5_error_exit(
"HDF5::readAttribute: error, cannot open attribute "+aname+
" attached to "+oname+
"!");
474 hid_t type_id=H5Aget_type(attr_id);
475 if(H5Tget_class(type_id)!=H5T_STRING){
476 HDF5_error_exit(
"HDF5::readAttribute: error, datatype mismatch in attribute "+aname+
"!");
480 hsize_t size=H5Tget_size(type_id);
481 char* datumcpy=
new char[size];
482 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
483 H5Aread(attr_id,nat_type_id,
reinterpret_cast<void*
>(datumcpy));
484 datum=std::string(datumcpy);
487 H5Tclose(nat_type_id);
492 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<short>& datum){
493 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
true);
496 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<unsigned short>& datum){
497 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
500 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<int>& datum){
501 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
true);
504 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<unsigned int>& datum){
505 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
508 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<unsigned long long>& datum){
509 rdAtt(obj_name,attr_name,datum,H5T_INTEGER,
false);
512 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<float>& datum){
513 rdAtt(obj_name,attr_name,datum,H5T_FLOAT,
true);
516 void HDF5::readAttribute(
const std::string& obj_name,
const std::string& attr_name, multi1d<double>& datum){
517 rdAtt(obj_name,attr_name,datum,H5T_FLOAT,
true);
526 void HDF5::read(
const std::string& obj_name,
short& datum){
527 rd(obj_name,datum,H5T_INTEGER,
true);
530 void HDF5::read(
const std::string& obj_name,
unsigned short& datum){
531 rd(obj_name,datum,H5T_INTEGER,
false);
534 void HDF5::read(
const std::string& obj_name,
int& datum){
535 rd(obj_name,datum,H5T_INTEGER,
true);
538 void HDF5::read(
const std::string& obj_name,
unsigned int& datum){
539 rd(obj_name,datum,H5T_INTEGER,
false);
542 void HDF5::read(
const std::string& obj_name,
unsigned long long& datum){
543 rd(obj_name,datum,H5T_INTEGER,
false);
546 void HDF5::read(
const std::string& obj_name,
float& datum){
547 rd(obj_name,datum,H5T_FLOAT,
true);
550 void HDF5::read(
const std::string& obj_name,
double& datum){
551 rd(obj_name,datum,H5T_FLOAT,
true);
554 void HDF5::read(
const std::string& dataname, std::string& datum){
555 std::string dname(dataname);
557 bool exists=objectExists(current_group,dname);
559 HDF5_error_exit(
"HDF5::read: error, dataset does not exists!");
562 herr_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
563 if(objinfo.type!=H5O_TYPE_DATASET){
564 HDF5_error_exit(
"HDF5::read: error, "+dname+
" exists but it is not a dataset!");
566 hid_t dset_id=H5Dopen(current_group,dname.c_str(),H5P_DEFAULT);
568 HDF5_error_exit(
"HDF5::read: error, cannot open dataset!");
570 hid_t type_id=H5Dget_type(dset_id);
571 if(H5Tget_class(type_id)!=H5T_STRING){
572 HDF5_error_exit(
"HDF5::read: error, datatype mismatch in dataset "+dataname+
"!");
576 hsize_t size=H5Tget_size(type_id);
577 char* datumcpy=
new char[size];
578 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
579 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
580 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
581 H5Dread(dset_id,nat_type_id,H5S_ALL,H5S_ALL,plist_id,
reinterpret_cast<void*
>(datumcpy));
582 datum=std::string(datumcpy);
586 H5Tclose(nat_type_id);
592 void HDF5::read(
const std::string& obj_name, multi1d<short>& datum){
593 rd(obj_name,datum,H5T_INTEGER,
true);
596 void HDF5::read(
const std::string& obj_name, multi1d<unsigned short>& datum){
597 rd(obj_name,datum,H5T_INTEGER,
false);
600 void HDF5::read(
const std::string& obj_name, multi1d<int>& datum){
601 rd(obj_name,datum,H5T_INTEGER,
true);
604 void HDF5::read(
const std::string& obj_name, multi1d<unsigned int>& datum){
605 rd(obj_name,datum,H5T_INTEGER,
false);
608 void HDF5::read(
const std::string& obj_name, multi1d<unsigned long long>& datum){
609 rd(obj_name,datum,H5T_INTEGER,
false);
612 void HDF5::read(
const std::string& obj_name, multi1d<float>& datum){
613 rd(obj_name,datum,H5T_FLOAT,
true);
616 void HDF5::read(
const std::string& obj_name, multi1d<double>& datum){
617 rd(obj_name,datum,H5T_FLOAT,
true);
620 void HDF5::read(
const std::string& obj_name, multi2d<short>& datum){
621 rd(obj_name,datum,H5T_INTEGER,
true);
624 void HDF5::read(
const std::string& obj_name, multi2d<unsigned short>& datum){
625 rd(obj_name,datum,H5T_INTEGER,
false);
628 void HDF5::read(
const std::string& obj_name, multi2d<int>& datum){
629 rd(obj_name,datum,H5T_INTEGER,
true);
632 void HDF5::read(
const std::string& obj_name, multi2d<unsigned int>& datum){
633 rd(obj_name,datum,H5T_INTEGER,
false);
636 void HDF5::read(
const std::string& obj_name, multi2d<unsigned long long>& datum){
637 rd(obj_name,datum,H5T_INTEGER,
false);
640 void HDF5::read(
const std::string& obj_name, multi2d<float>& datum){
641 rd(obj_name,datum,H5T_FLOAT,
true);
644 void HDF5::read(
const std::string& obj_name, multi2d<double>& datum){
645 rd(obj_name,datum,H5T_FLOAT,
true);
653 void HDF5::readPrepare(
const std::string& name, hid_t& type_id){
655 bool exists=objectExists(current_group,name);
657 HDF5_error_exit(
"HDF5::read: error, dataset does not exists!");
660 herr_t errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
661 if(objinfo.type!=H5O_TYPE_DATASET){
662 HDF5_error_exit(
"HDF5::read: error, "+name+
" exists but it is not a dataset!");
666 hid_t dset_id=H5Dopen(current_group,name.c_str(),H5P_DEFAULT);
668 HDF5_error_exit(
"HDF5::read: error, cannot open dataset!");
670 type_id=H5Dget_type(dset_id);
676 template<>
void HDF5::read< PScalar< PScalar< RComplex<float> > > >(
const std::string& dataname,
ComplexF& datum){
679 readPrepare(dataname,type_id);
681 HDF5_error_exit(
"HDF5::read: error, cannot open datatype!");
684 if(!checkComplexType(type_id,base_type_id)){
685 HDF5_error_exit(
"HDF5::read: error, datatype mismatch!");
687 unsigned int float_size=H5Tget_size(base_type_id);
689 HDF5_error_exit(
"HDF5:read: error, datatype size mismatch!");
692 H5Tclose(base_type_id);
695 rd(dataname,datum,H5T_COMPOUND,
true,
false);
698 template<>
void HDF5::read< PScalar< PScalar< RComplex<double> > > >(
const std::string& dataname,
ComplexD& datum){
701 readPrepare(dataname,type_id);
703 HDF5_error_exit(
"HDF5::read: error, cannot open datatype!");
706 if(!checkComplexType(type_id,base_type_id)){
707 HDF5_error_exit(
"HDF5::read: error, datatype mismatch!");
709 unsigned int float_size=H5Tget_size(base_type_id);
711 HDF5_error_exit(
"HDF5:read: error, datatype size mismatch!");
714 H5Tclose(base_type_id);
717 rd(dataname,datum,H5T_COMPOUND,
true,
false);
721 template<>
void HDF5::read< PScalar< PScalar< RComplex<float> > > >(
const std::string& dataname, multi1d<ComplexF>& datum){
724 readPrepare(dataname,type_id);
726 HDF5_error_exit(
"HDF5::read: error, cannot open datatype!");
729 if(!checkComplexType(type_id,base_type_id)){
730 HDF5_error_exit(
"HDF5::read: error, datatype mismatch!");
732 unsigned int float_size=H5Tget_size(base_type_id);
734 HDF5_error_exit(
"HDF5:read: error, datatype size mismatch!");
737 H5Tclose(base_type_id);
740 rd(dataname,datum,H5T_COMPOUND,
true,
false);
743 template<>
void HDF5::read< PScalar< PScalar< RComplex<double> > > >(
const std::string& dataname, multi1d<ComplexD>& datum){
746 readPrepare(dataname,type_id);
748 HDF5_error_exit(
"HDF5::read: error, cannot open datatype!");
751 if(!checkComplexType(type_id,base_type_id)){
752 HDF5_error_exit(
"HDF5::read: error, datatype mismatch!");
754 unsigned int float_size=H5Tget_size(base_type_id);
756 HDF5_error_exit(
"HDF5:read: error, datatype size mismatch!");
759 H5Tclose(base_type_id);
762 rd(dataname,datum,H5T_COMPOUND,
true,
false);
770 void HDF5::readPrepareLattice(
const std::string& name, hid_t& type_id, multi1d<ullong>& sizes){
772 bool exists=objectExists(current_group,name);
774 HDF5_error_exit(
"HDF5::read: error, dataset does not exists!");
777 herr_t errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
778 if(objinfo.type!=H5O_TYPE_DATASET){
779 HDF5_error_exit(
"HDF5::read: error, "+name+
" exists but it is not a dataset!");
784 hid_t dset_id=H5Dopen(current_group,name.c_str(),H5P_DEFAULT);
786 HDF5_error_exit(
"HDF5::read: error, cannot open dataset!");
788 type_id=H5Dget_type(dset_id);
791 hid_t filespace=H5Dget_space(dset_id);
792 int Ndims=H5Sget_simple_extent_ndims(filespace);
794 hsize_t* inttoken=
new hsize_t[Ndims];
795 errhandle=H5Sget_simple_extent_dims(filespace,inttoken, NULL);
796 for(
unsigned int dd=0; dd<Ndims; dd++){
797 sizes[dd]=inttoken[dd];
805 if(!isprefetched && sizes.size()>1) prefetchLatticeCoordinates();
808 void HDF5::readLattice(
const std::string& name,
const hid_t& type_id,
809 const hid_t& base_type_id,
const ullong& obj_size,
810 const ullong& tot_size,
char* buf,
bool invert_order) {
812 const int mynode = Layout::nodeNumber();
813 const int nodeSites = Layout::sitesOnNode();
816 unsigned int dimensions;
817 if(obj_size>1) dimensions=
Nd+1;
819 hsize_t* node_offset =
new hsize_t[dimensions];
820 hsize_t* offset =
new hsize_t[dimensions];
821 hsize_t* total_count =
new hsize_t[dimensions];
822 hsize_t* dim_size =
new hsize_t[dimensions];
827 for(
unsigned int i = 0; i <
Nd; i ++) {
828 dim_size[i] = total_count[i] = Layout::subgridLattSize()[(
Nd - 1) - i];
829 offset[i] = node_offset[i] = Layout::nodeCoord()[(
Nd - 1) - i] * total_count[i];
834 for(
unsigned int i = 0; i <
Nd; i ++) {
835 dim_size[i] = total_count[i] = Layout::subgridLattSize()[i];
836 offset[i] = node_offset[i] = Layout::nodeCoord()[i] * total_count[i];
840 dim_size[
Nd] = total_count[
Nd] = obj_size;
841 offset[
Nd] = node_offset[
Nd] = 0;
845 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
846 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
849 hid_t dset_id = H5Dopen(current_group, name.c_str(), H5P_DEFAULT);
850 hid_t filespace = H5Dget_space(dset_id);
852 unsigned int hdf5_float_size=H5Tget_size(base_type_id);
853 if( (hdf5_float_size!=4) && (hdf5_float_size!=8) ){
854 HDF5_error_exit(
"HDF5Reader::read: error, invalid base datatype while trying to read lattice!");
856 if(H5Tget_class(base_type_id)!=H5T_FLOAT){
857 HDF5_error_exit(
"HDF5Reader::read: error, invalid base datatype while trying to read lattice!");
862 size_t two_gb = (size_t) 2 * 1024 * 1024 * 1024;
863 size_t total_size = tot_size;
864 unsigned int blocks = 1;
865 while( (total_size * hdf5_float_size) > two_gb) {
866 dim_size[0] = dim_size[0] >> 1;
867 total_size = total_size >> 1;
868 blocks = blocks << 1;
872 char* buf_small =
new (std::nothrow)
char[total_size*hdf5_float_size];
873 if(buf_small == 0x0) {
874 HDF5_error_exit(
"Unable to allocate buf\n");
877 hsize_t rank =
static_cast<hsize_t
>(dimensions);
878 hid_t memspace = H5Screate_simple(rank, dim_size, NULL);
879 hid_t nat_type_id=H5Tget_native_type(type_id,H5T_DIR_ASCEND);
882 for(
int i = 0; i < blocks; ++ i) {
883 offset[0] = node_offset[0] + i * dim_size[0];
884 H5Sselect_hyperslab(filespace, H5S_SELECT_SET,
const_cast<const hsize_t*
>(offset),
885 NULL,
const_cast<const hsize_t*
>(dim_size), NULL);
886 err = H5Dread(dset_id, nat_type_id, memspace, filespace, plist_id,
static_cast<void*
>(buf_small));
887 for(
ullong j = 0; j < (total_size*hdf5_float_size); j++){
888 (buf + i * (total_size*hdf5_float_size) )[j] = buf_small[j];
895 multi1d<int> locsizes=Layout::subgridLattSize();
896 int dstruct_size=tot_size/nodeSites;
899 char* tmpbuf=
new char[nodeSites*dstruct_size*hdf5_float_size];
900 for(
unsigned int x=0; x<locsizes[0]; x++){
901 for(
unsigned int y=0; y<locsizes[1]; y++){
902 for(
unsigned int z=0; z<locsizes[2]; z++){
903 for(
unsigned int t=0; t<locsizes[3]; t++){
905 memcpy(&tmpbuf[dstruct_size*hdf5_float_size*(x+locsizes[0]*(y+locsizes[1]*(z+locsizes[2]*t)))],
906 &buf[dstruct_size*hdf5_float_size*(t+locsizes[3]*(z+locsizes[2]*(y+locsizes[1]*x)))],
907 dstruct_size*hdf5_float_size);
912 memcpy(buf,tmpbuf,nodeSites*dstruct_size*hdf5_float_size);
918 delete [] total_count;
920 delete [] node_offset;
924 H5Tclose(nat_type_id);
930 template<>
void HDF5::read< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(
const std::string& name,
932 const HDF5Base::accessmode& accmode){
933 StopWatch swatch_prepare, swatch_datatypes, swatch_reorder, swatch_read;
937 case HDF5Base::transpose_order:
940 case HDF5Base::maintain_order:
946 if(profile) swatch_prepare.start();
947 multi1d<ullong> sizes;
949 readPrepareLattice(name,type_id,sizes);
950 if(profile) swatch_prepare.stop();
953 if(profile) swatch_datatypes.start();
955 if( !checkColorMatrixType(type_id,Nc,base_type_id) ){
956 HDF5_error_exit(
"HDF5::read: object is not a color matrix!");
959 ullong hdf5_float_size=H5Tget_size(base_type_id);
962 if(sizes.size()!=Nd){
963 HDF5_error_exit(
"HDF5::read: error, wrong dimensionality!");
967 for(
unsigned int dd=0; dd<
Nd; dd++){
968 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
969 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
974 for(
unsigned int dd=0; dd<
Nd; dd++){
975 if(sizes[dd]!=Layout::lattSize()[dd]){
976 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
980 if(profile) swatch_datatypes.stop();
983 if(profile) swatch_read.start();
984 const int mynode=Layout::nodeNumber();
985 const int nodeSites = Layout::sitesOnNode();
987 size_t tot_size = nodeSites*obj_size;
988 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
990 HDF5_error_exit(
"Unable to allocate buf\n");
993 readLattice(name,type_id,base_type_id,1,tot_size,buf,invert_order);
995 H5Tclose(base_type_id);
996 if(profile) swatch_read.stop();
1000 if(profile) swatch_reorder.start();
1005 if(hdf5_float_size==field_float_size){
1006 CvtToLayout(field,
reinterpret_cast<void*
>(buf),nodeSites,
sizeof(ColorMatrixD3));
1011 for(
unsigned int i=0; i<tot_size; i++){
1012 memcpy(&tmpfloat,&buf[i*hdf5_float_size],
sizeof(
REAL32));
1013 tmpbuf[i]=
static_cast< REAL64 >(tmpfloat);
1015 CvtToLayout(field,
reinterpret_cast<void*
>(tmpbuf),nodeSites,
sizeof(ColorMatrixD3));
1019 if(profile) swatch_reorder.stop();
1022 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
1023 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
1024 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
1025 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
1026 QDPIO::cout <<
"\t read: " << swatch_read.getTimeInSeconds() <<
" s." << std::endl;
1027 QDPIO::cout <<
"\t MB read: " << Layout::vol()*obj_size*
static_cast<int>(hdf5_float_size)/1024/1024 << std::endl;
1032 template<>
void HDF5::read< PSpinMatrix< PColorMatrix< RComplex<REAL32>, 3>, 4> >(
const std::string& name,
1034 const HDF5Base::accessmode& accmode){
1035 StopWatch swatch_prepare, swatch_datatypes, swatch_reorder, swatch_read;
1039 case HDF5Base::transpose_order:
1042 case HDF5Base::maintain_order:
1048 if(profile) swatch_prepare.start();
1049 multi1d<ullong> sizes;
1051 readPrepareLattice(name,type_id,sizes);
1052 if(profile) swatch_prepare.stop();
1055 if(profile) swatch_datatypes.start();
1057 if( !checkDiracPropagatorType(type_id,Ns,Nc,base_type_id) ){
1058 HDF5_error_exit(
"HDF5::read: object is not a dirac propagator!");
1061 ullong hdf5_float_size=H5Tget_size(base_type_id);
1063 if(sizes.size()!=Nd){
1064 HDF5_error_exit(
"HDF5::read: error, wrong dimensionality!");
1068 for(
unsigned int dd=0; dd<
Nd; dd++){
1069 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
1070 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1075 for(
unsigned int dd=0; dd<
Nd; dd++){
1076 if(sizes[dd]!=Layout::lattSize()[dd]){
1077 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1081 if(profile) swatch_datatypes.stop();
1084 if(profile) swatch_read.start();
1085 const int mynode=Layout::nodeNumber();
1086 const int nodeSites = Layout::sitesOnNode();
1088 size_t tot_size = nodeSites*obj_size;
1089 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
1091 HDF5_error_exit(
"Unable to allocate buf\n");
1094 readLattice(name,type_id,base_type_id,1,tot_size,buf,invert_order);
1096 H5Tclose(base_type_id);
1097 if(profile) swatch_read.stop();
1101 if(profile) swatch_reorder.start();
1102 if(hdf5_float_size==field_float_size){
1104 CvtToLayout(field,
reinterpret_cast<void*
>(buf),nodeSites,
sizeof(DiracPropagatorF3));
1110 for(
unsigned int i=0; i<tot_size; i++){
1111 memcpy(&tmpfloat,&buf[i*hdf5_float_size],
sizeof(
REAL64));
1112 tmpbuf[i]=
static_cast< REAL32 >(tmpfloat);
1114 CvtToLayout(field,
reinterpret_cast<void*
>(tmpbuf),nodeSites,
sizeof(DiracPropagatorF3));
1118 if(profile) swatch_reorder.stop();
1121 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
1122 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
1123 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
1124 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
1125 QDPIO::cout <<
"\t read: " << swatch_read.getTimeInSeconds() <<
" s." << std::endl;
1126 QDPIO::cout <<
"\t MB read: " << Layout::vol()*
sizeof(
DiracPropagatorF3)/1024/1024 << std::endl;
1131 template<>
void HDF5::read< PSpinMatrix< PColorMatrix< RComplex<REAL64>, 3>, 4> >(
const std::string& name,
1133 const HDF5Base::accessmode& accmode){
1134 StopWatch swatch_prepare, swatch_datatypes, swatch_reorder, swatch_read;
1138 case HDF5Base::transpose_order:
1141 case HDF5Base::maintain_order:
1147 if(profile) swatch_prepare.start();
1148 multi1d<ullong> sizes;
1150 readPrepareLattice(name,type_id,sizes);
1151 if(profile) swatch_prepare.stop();
1154 if(profile) swatch_datatypes.start();
1156 if( !checkDiracPropagatorType(type_id,Ns,Nc,base_type_id) ){
1157 HDF5_error_exit(
"HDF5::read: object is not a dirac propagator!");
1160 ullong hdf5_float_size=H5Tget_size(base_type_id);
1162 if(sizes.size()!=Nd){
1163 HDF5_error_exit(
"HDF5::read: error, wrong dimensionality!");
1167 for(
unsigned int dd=0; dd<
Nd; dd++){
1168 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
1169 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1174 for(
unsigned int dd=0; dd<
Nd; dd++){
1175 if(sizes[dd]!=Layout::lattSize()[dd]){
1176 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1180 if(profile) swatch_datatypes.stop();
1183 if(profile) swatch_read.start();
1184 const int mynode=Layout::nodeNumber();
1185 const int nodeSites = Layout::sitesOnNode();
1187 size_t tot_size = nodeSites*obj_size;
1188 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
1190 HDF5_error_exit(
"Unable to allocate buf\n");
1193 readLattice(name,type_id,base_type_id,1,tot_size,buf,invert_order);
1195 H5Tclose(base_type_id);
1196 if(profile) swatch_read.stop();
1200 if(profile) swatch_reorder.start();
1201 if(hdf5_float_size==field_float_size){
1203 CvtToLayout(field,
reinterpret_cast<void*
>(buf),nodeSites,
sizeof(DiracPropagatorD3));
1209 for(
unsigned int i=0; i<tot_size; i++){
1210 memcpy(&tmpfloat,&buf[i*hdf5_float_size],
sizeof(
REAL32));
1211 tmpbuf[i]=
static_cast< REAL64 >(tmpfloat);
1213 CvtToLayout(field,
reinterpret_cast<void*
>(tmpbuf),nodeSites,
sizeof(DiracPropagatorD3));
1217 if(profile) swatch_reorder.stop();
1220 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
1221 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
1222 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
1223 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
1224 QDPIO::cout <<
"\t read: " << swatch_read.getTimeInSeconds() <<
" s." << std::endl;
1225 QDPIO::cout <<
"\t MB read: " << Layout::vol()*
sizeof(
DiracPropagatorD3)/1024/1024 << std::endl;
1230 template<>
void HDF5::read< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(
const std::string& name,
1231 multi1d<LatticeColorMatrixD3>& fieldarray,
1232 const HDF5Base::accessmode& accmode){
1233 StopWatch swatch_prepare, swatch_datatypes, swatch_reorder, swatch_read;
1237 case HDF5Base::transpose_order:
1240 case HDF5Base::maintain_order:
1246 if(profile) swatch_prepare.start();
1248 multi1d<ullong> sizes;
1250 readPrepareLattice(name,type_id,sizes);
1251 unsigned int arr_size=sizes[
Nd];
1252 if(profile) swatch_prepare.stop();
1255 if(profile) swatch_datatypes.start();
1257 if( !checkColorMatrixType(type_id,Nc,base_type_id) ){
1258 HDF5_error_exit(
"HDF5::read: object is not a color matrix!");
1261 ullong hdf5_float_size=H5Tget_size(base_type_id);
1263 if(sizes.size()!=(Nd+1)){
1264 HDF5_error_exit(
"HDF5::read: error, wrong dimensionality!");
1268 for(
unsigned int dd=0; dd<
Nd; dd++){
1269 if(sizes[Nd-dd-1]!=Layout::lattSize()[dd]){
1270 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1275 for(
unsigned int dd=0; dd<
Nd; dd++){
1276 if(sizes[dd]!=Layout::lattSize()[dd]){
1277 HDF5_error_exit(
"HDF5::read: mismatching lattice extents.");
1281 fieldarray.resize(sizes[Nd]);
1282 if(profile) swatch_datatypes.stop();
1285 if(profile) swatch_read.start();
1286 const int mynode=Layout::nodeNumber();
1287 const int nodeSites = Layout::sitesOnNode();
1289 size_t tot_size = nodeSites*arr_size*obj_size;
1290 char* buf =
new(std::nothrow)
char[tot_size*hdf5_float_size];
1292 HDF5_error_exit(
"Unable to allocate buf\n");
1295 readLattice(name,type_id,base_type_id,sizes[Nd],tot_size,buf,invert_order);
1297 H5Tclose(base_type_id);
1298 if(profile) swatch_read.stop();
1302 if(profile) swatch_reorder.start();
1309 if(hdf5_float_size==field_float_size){
1311 CvtToLayout(fieldarray,
reinterpret_cast<void*
>(buf),nodeSites,arr_size,
sizeof(ColorMatrixD3));
1317 for(
unsigned int i=0; i<tot_size; i++){
1318 memcpy(&tmpfloat,&buf[i*hdf5_float_size],
sizeof(
REAL32));
1319 tmpbuf[i]=
static_cast< REAL64 >(tmpfloat);
1321 CvtToLayout(fieldarray,
reinterpret_cast<void*
>(tmpbuf),nodeSites,arr_size,
sizeof(ColorMatrixD3));
1325 if(profile) swatch_reorder.stop();
1328 QDPIO::cout <<
"HDF5-I/O statistics. Read:" << std::endl;
1329 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
1330 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
1331 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
1332 QDPIO::cout <<
"\t read: " << swatch_read.getTimeInSeconds() <<
" s." << std::endl;
1333 QDPIO::cout <<
"\t MB read: " << Layout::vol()*fieldarray.size()*obj_size*
static_cast<int>(hdf5_float_size)/1024/1024 << std::endl;
1343 void HDF5::readQlua(
const std::string& name, multi1d<LatticeColorMatrixD3>& field){
1344 StopWatch swatch_complete;
1346 QDPIO::cout <<
"Reading Qlua config ..." << std::flush;
1349 if(profile) swatch_complete.start();
1350 if(!objectExists(current_group,name)){
1351 HDF5_error_exit(
"HDF5::readQlua: error, configuration "+name+
"does not exist!");
1355 herr_t errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
1356 if(objinfo.type!=H5O_TYPE_GROUP){
1357 HDF5_error_exit(
"HDF5::readQlua: error, "+name+
" exists but it is not a Qlua config!");
1360 for(
unsigned int dd=0; dd<
Nd; dd++){
1361 std::stringstream stream;
1362 stream << name <<
"/" << dd;
1363 std::string dname=stream.str();
1364 if(!objectExists(current_group,dname)){
1365 HDF5_error_exit(
"HDF5::readQlua: error, "+name+
" exists but it is not a Qlua config! Dataset "+dname+
" was not found!");
1369 std::stringstream stream;
1370 stream << name <<
"/" <<
Nd;
1371 std::string dname=stream.str();
1372 if(objectExists(current_group,dname)){
1373 HDF5_error_exit(
"HDF5::readQlua: error, "+name+
" exists but it is not a Qlua config!");
1378 for(
unsigned int dd=0; dd<
Nd; dd++){
1379 std::stringstream stream;
1380 stream << name <<
"/" << dd;
1381 std::string dname=stream.str();
1382 read(dname,field[dd],HDF5Base::maintain_order);
1384 if(profile) swatch_complete.stop();
1385 QDPIO::cout <<
"done!" << std::endl;
1388 QDPIO::cout <<
"HDF5-I/O statistics for Qlua-read: " << std::endl;
1389 QDPIO::cout <<
"\t total: " << swatch_complete.getTimeInSeconds() <<
" s." << std::endl;
1390 QDPIO::cout <<
"\t MB read: " << Layout::vol()*field.size()*
sizeof(
ColorMatrixD3)/1024/1024 << std::endl;
1395 void HDF5::readQlua(
const std::string& name, LatticeDiracPropagatorD3& prop){
1396 StopWatch swatch_complete;
1398 QDPIO::cout <<
"Reading Qlua propagator ..." << std::flush;
1401 if(profile) swatch_complete.start();
1402 if(!objectExists(current_group,name)){
1403 HDF5_error_exit(
"HDF5::readQlua: error, dataset "+name+
"does not exist!");
1407 herr_t errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
1408 if(!objectExists(current_group,name)){
1409 HDF5_error_exit(
"HDF5::readQlua: error, "+name+
" exists but it is not a Qlua propagator!");
1436 read(name,prop,HDF5Base::maintain_order);
1437 if(profile) swatch_complete.stop();
1438 QDPIO::cout <<
"done!" << std::endl;
1441 QDPIO::cout <<
"HDF5-I/O statistics for Qlua-read: " << std::endl;
1442 QDPIO::cout <<
"\t total: " << swatch_complete.getTimeInSeconds() <<
" s." << std::endl;
1443 QDPIO::cout <<
"\t MB read: " << Layout::vol()*
sizeof(
DiracPropagatorD3)/1024/1024 << std::endl;
1453 HDF5Reader::HDF5Reader() : HDF5() {};
1455 HDF5Reader::HDF5Reader(
const long int& blocksize,
const long int& maxalign) : HDF5(blocksize, maxalign) {};
1457 HDF5Reader::HDF5Reader(
const std::string& filename): HDF5(){
1462 HDF5Reader::~HDF5Reader(){
1466 void HDF5Reader::open(
const std::string& filename){
1471 bool exists=check_exists(filename);
1473 HDF5_error_exit(
"HDF5Reader::open: error, file does not exist!");
1477 hid_t fapl_id = H5Pcreate(H5P_FILE_ACCESS);
1482 H5Pset_alignment(fapl_id,maxalign,stripesize);
1486 MPI_Info info = MPI_INFO_NULL;
1487 QMP_get_hidden_comm(QMP_comm_get_default(),
reinterpret_cast<void**
>(&mpicomm));
1488 H5Pset_fapl_mpio(fapl_id,*mpicomm, info);
1491 file_id=H5Fopen(filename.c_str(),H5F_ACC_RDONLY,fapl_id);
1495 HDF5_error_exit(
"HDF5Reader::open: could not open file "+filename+
" for reading. Some error occured!");
1498 current_group=file_id;
1508 HDF5Writer::HDF5Writer() : HDF5() {};
1510 HDF5Writer::HDF5Writer(
const long int& stripesizee,
const long int& maxalignn) : HDF5(stripesizee,maxalignn) {};
1512 HDF5Writer::HDF5Writer(
const std::string& filename,
const HDF5Base::writemode& mode) : HDF5(){
1513 open(filename,mode);
1517 HDF5Writer::~HDF5Writer(){
1522 void HDF5Writer::open(
const std::string& filename,
const HDF5Base::writemode& mode){
1527 hid_t fapl_id = H5Pcreate(H5P_FILE_ACCESS);
1528 hid_t fcpl_id = H5Pcreate(H5P_FILE_CREATE);
1533 H5Pset_alignment(fapl_id,maxalign,stripesize);
1540 MPI_Info info = MPI_INFO_NULL;
1541 QMP_get_hidden_comm(QMP_comm_get_default(),
reinterpret_cast<void**
>(&mpicomm));
1542 H5Pset_fapl_mpio(fapl_id,*mpicomm,info);
1547 if(Layout::nodeNumber()==0){
1548 std::ifstream input(filename.c_str(),std::ios_base::binary);
1554 QDPInternal::broadcast(exists);
1558 htri_t ex=H5Fis_hdf5(filename.c_str());
1561 if(mode&HDF5Base::trunc){
1563 file_id=H5Fcreate(filename.c_str(),H5F_ACC_TRUNC,fcpl_id,fapl_id);
1567 file_id=H5Fopen(filename.c_str(),H5F_ACC_RDWR,fapl_id);
1572 if(mode&HDF5Base::trunc){
1574 remove(filename.c_str());
1575 file_id=H5Fcreate(filename.c_str(),H5F_ACC_EXCL,fcpl_id,fapl_id);
1578 HDF5_error_exit(
"HDF5Writer::open: error, file "+filename+
" already exists and is not HDF5 file! Please use overwrite=true to create anew file!");
1584 file_id=H5Fcreate(filename.c_str(),H5F_ACC_EXCL,fcpl_id,fapl_id);
1590 HDF5_error_exit(
"HDF5Writer::open: could not open file "+filename+
" for writing.");
1593 current_group=file_id;
1597 void HDF5Writer::mkdir(const ::std::string& name){
1598 if(name!=
"" && name!=
"/"){
1599 std::string cwd=pwd();
1606 void HDF5Writer::push(
const std::string& name){
1607 std::vector<std::string> dirlist=splitPathname(name);
1610 if(name.find_first_of(
"/")==0){
1615 hid_t plist_id = H5Pcreate (H5P_GROUP_CREATE);
1619 for(
unsigned int i=0; i<static_cast<unsigned int>(dirlist.size()); i++){
1620 last_group=current_group;
1623 htri_t ex=H5Lexists(last_group,dirlist[i].c_str(),H5P_DEFAULT);
1626 current_group=H5Gcreate(last_group,dirlist[i].c_str(),H5P_DEFAULT,plist_id,H5P_DEFAULT);
1630 ex=H5Oexists_by_name(last_group,dirlist[i].c_str(),H5P_DEFAULT);
1632 QDPIO::cout <<
"HDF5Writer::push: path traversal error! You seem to have dangling links, I will try to clean up" << std::endl;
1634 H5Ldelete(last_group,dirlist[i].c_str(),H5P_DEFAULT);
1636 current_group=H5Gcreate(last_group,dirlist[i].c_str(),H5P_DEFAULT,plist_id,H5P_DEFAULT);
1641 herr_t errhandle=H5Oget_info_by_name(last_group,dirlist[i].c_str(),&objinfo,H5P_DEFAULT);
1643 QDPIO::cout <<
"HDF5Writer::push: error, cannot get properties of " << name <<
"!" << std::endl;
1644 current_group=last_group;
1647 if(objinfo.type!=H5O_TYPE_GROUP){
1648 QDPIO::cout <<
"HDF5Writer::push: error, the object " << dirlist[i] <<
" in " << getNameById(last_group) <<
" already exists and is not a group!" << std::endl;
1649 current_group=last_group;
1653 current_group=H5Gopen(last_group,dirlist[i].c_str(),H5P_DEFAULT);
1658 if(current_group<0){
1659 HDF5_error_exit(
"HDF5Writer::push: something went wrong, aborting!");
1668 herr_t HDF5Writer::rmAtt(hid_t location_id,
const char *attr_name,
const H5A_info_t* attrinfo,
void* opdata){
1669 return H5Adelete(location_id,attr_name);
1672 void HDF5Writer::deleteAllAttributes(
const std::string& obj_name){
1673 H5Aiterate_by_name(current_group,obj_name.c_str(),H5_INDEX_NAME,H5_ITER_NATIVE,NULL,rmAtt,NULL,H5P_DEFAULT);
1676 void HDF5Writer::deleteAttribute(
const std::string& obj_name,
const std::string& attr_name){
1677 std::string oname(obj_name), aname(attr_name);
1678 htri_t exists=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1680 QDPIO::cout <<
"HDF5Writer::deleteAttribute: error, attribute does not exists!" << std::endl; \
1683 herr_t errhandle=H5Adelete_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1692 template<
typename ctype>
1696 QDPInternal::broadcast(global);
1698 int chcksum = global !=
local ? 1 : 0;
1699 QDPInternal::globalSum(chcksum);
1704 template<
typename ctype>
1710 if (Layout::nodeNumber()==0)
1715 QDPInternal::broadcast(&(global[0]),
sizeof(ctype)*s0);
1720 for (
int j=0; j<s0; ++j)
1721 chcksum += global[j] !=
local[j] ? 1 : 0;
1723 QDPInternal::globalSum(chcksum);
1728 template bool get_global<short>( multi1d<short>& global,
const multi1d<short>&
local);
1729 template bool get_global<int>( multi1d<int>& global,
const multi1d<int>&
local);
1730 template bool get_global<unsigned short>( multi1d<unsigned short>& global,
const multi1d<unsigned short>&
local);
1731 template bool get_global<unsigned int>( multi1d<unsigned int>& global,
const multi1d<unsigned int>&
local);
1732 template bool get_global<unsigned long>( multi1d<unsigned long>& global,
const multi1d<unsigned long>&
local);
1733 template bool get_global<unsigned long long>( multi1d<unsigned long long>& global,
const multi1d<unsigned long long>&
local);
1734 template bool get_global<float>( multi1d<float>& global,
const multi1d<float>&
local);
1735 template bool get_global<double>( multi1d<double>& global,
const multi1d<double>&
local);
1738 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const short& datum,
const HDF5Base::writemode& mode){
1739 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_SHORT,mode);
1742 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const unsigned short& datum,
const HDF5Base::writemode& mode){
1743 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_USHORT,mode);
1746 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const int& datum,
const HDF5Base::writemode& mode){
1747 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_INT,mode);
1750 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const unsigned int& datum,
const HDF5Base::writemode& mode){
1751 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_UINT,mode);
1754 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const unsigned long long& datum,
const HDF5Base::writemode& mode){
1755 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_ULLONG,mode);
1758 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const float& datum,
const HDF5Base::writemode& mode){
1759 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_FLOAT,mode);
1762 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const double& datum,
const HDF5Base::writemode& mode){
1763 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_DOUBLE,mode);
1766 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const std::string& datum,
const HDF5Base::writemode& mode){
1767 std::string oname(obj_name), aname(attr_name);
1769 std::string datum_0;
1771 QDPIO::cerr <<
"HDF5Writer::writeAttribute() warning: " << obj_name
1772 <<
".attrib(" << attr_name <<
") was NOT global. Using node=0 value now." << std::endl;
1775 bool exists=objectExists(current_group,oname);
1777 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, object "+oname+
" you try to write attribute to does not exists!");
1780 hid_t ex=H5Aexists_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1782 if(!(mode&HDF5Base::trunc)){
1783 HDF5_error_exit(
"HDF5Writer::writeAttribute: error, attribute "+aname+
" already exists!");
1785 herr_t errhandle=H5Adelete_by_name(current_group,oname.c_str(),aname.c_str(),H5P_DEFAULT);
1788 if (datum_0.length()+1>64*1024) {
1789 QDPIO::cerr <<
"HDF5Writer::writeAttribute() error: " << obj_name
1790 <<
".attrib(" << attr_name
1791 <<
") exceeds the maximum hdf5 attrib size (64kB)." << std::endl;
1793 HDF5_error_exit(
"bad string attrib write");
1797 hid_t typid=H5Tcreate(H5T_STRING,datum_0.length()+1);
1798 H5Tset_cset(typid,H5T_CSET_UTF8);
1800 hid_t attr_space_id=H5Screate(H5S_SCALAR);
1801 hid_t attr_id=H5Acreate_by_name(current_group,oname.c_str(),aname.c_str(),typid,attr_space_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1802 H5Sclose(attr_space_id);
1805 H5Awrite(attr_id,typid,
reinterpret_cast<void*
>(
const_cast<char*
>(datum_0.c_str())));
1811 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<short>& datum,
const HDF5Base::writemode& mode){
1812 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_SHORT,mode);
1815 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<unsigned short>& datum,
const HDF5Base::writemode& mode){
1816 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_USHORT,mode);
1819 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<int>& datum,
const HDF5Base::writemode& mode){
1820 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_INT,mode);
1823 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<unsigned int>& datum,
const HDF5Base::writemode& mode){
1824 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_UINT,mode);
1827 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<unsigned long long>& datum,
const HDF5Base::writemode& mode){
1828 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_ULLONG,mode);
1831 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<float>& datum,
const HDF5Base::writemode& mode){
1832 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_FLOAT,mode);
1835 void HDF5Writer::writeAttribute(
const std::string& obj_name,
const std::string& attr_name,
const multi1d<double>& datum,
const HDF5Base::writemode& mode){
1836 wtAtt(obj_name,attr_name,datum,H5T_NATIVE_DOUBLE,mode);
1845 void HDF5Writer::write(
const std::string& obj_name,
const short& datum,
const HDF5Base::writemode& mode){
1846 wt(obj_name,datum,H5T_NATIVE_SHORT,mode);
1849 void HDF5Writer::write(
const std::string& obj_name,
const unsigned short& datum,
const HDF5Base::writemode& mode){
1850 wt(obj_name,datum,H5T_NATIVE_USHORT,mode);
1853 void HDF5Writer::write(
const std::string& obj_name,
const int& datum,
const HDF5Base::writemode& mode){
1854 wt(obj_name,datum,H5T_NATIVE_INT,mode);
1857 void HDF5Writer::write(
const std::string& obj_name,
const unsigned int& datum,
const HDF5Base::writemode& mode){
1858 wt(obj_name,datum,H5T_NATIVE_UINT,mode);
1861 void HDF5Writer::write(
const std::string& obj_name,
const unsigned long long& datum,
const HDF5Base::writemode& mode){
1862 wt(obj_name,datum,H5T_NATIVE_ULLONG,mode);
1865 void HDF5Writer::write(
const std::string& obj_name,
const float& datum,
const HDF5Base::writemode& mode){
1866 wt(obj_name,datum,H5T_NATIVE_FLOAT,mode);
1869 void HDF5Writer::write(
const std::string& obj_name,
const double& datum,
const HDF5Base::writemode& mode){
1870 wt(obj_name,datum,H5T_NATIVE_DOUBLE,mode);
1873 void HDF5Writer::write(
const std::string& dataname,
const std::string& datum,
const HDF5Base::writemode& mode){
1874 std::string dname(dataname);
1875 std::string datum_0;
1877 QDPIO::cerr <<
"HDF5Writer::write() warning: " << dataname <<
" was NOT global. Using node=0 value now." << std::endl;
1880 bool exists=objectExists(current_group,dname);
1882 if(!(mode&HDF5Base::trunc)){
1883 QDPIO::cout <<
"HDF5Writer::write: error, object named " << dname <<
" already exists!" << std::endl;
1887 hid_t errhandle=H5Oget_info_by_name(current_group,dname.c_str(),&objinfo,H5P_DEFAULT);
1888 if(objinfo.type!=H5O_TYPE_DATASET){
1889 QDPIO::cout <<
"HDF5Writer::write: error, object you try to write does already exist and is of different type!" << std::endl;
1892 errhandle=H5Ldelete(current_group,dname.c_str(),H5P_DEFAULT);
1896 hid_t dataid, spaceid, typid=H5Tcreate(H5T_STRING,datum_0.length()+1);
1897 H5Tset_cset(typid,H5T_CSET_UTF8);
1899 spaceid=H5Screate(H5S_SCALAR);
1900 dataid=H5Dcreate(current_group,dname.c_str(),typid,spaceid,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
1903 hid_t plist_id = H5Pcreate (H5P_DATASET_XFER);
1904 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
1905 H5Dwrite(dataid,typid,H5S_ALL,H5S_ALL,plist_id,
reinterpret_cast<void*
>(
const_cast<char*
>(datum_0.c_str())));
1913 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<short>& datum,
const HDF5Base::writemode& mode){
1914 wt(obj_name,datum,H5T_NATIVE_SHORT,mode);
1917 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<unsigned short>& datum,
const HDF5Base::writemode& mode){
1918 wt(obj_name,datum,H5T_NATIVE_USHORT,mode);
1921 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<int>& datum,
const HDF5Base::writemode& mode){
1922 wt(obj_name,datum,H5T_NATIVE_INT,mode);
1925 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<unsigned int>& datum,
const HDF5Base::writemode& mode){
1926 wt(obj_name,datum,H5T_NATIVE_UINT,mode);
1929 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<unsigned long long>& datum,
const HDF5Base::writemode& mode){
1930 wt(obj_name,datum,H5T_NATIVE_ULLONG,mode);
1933 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<float>& datum,
const HDF5Base::writemode& mode){
1934 wt(obj_name,datum,H5T_NATIVE_FLOAT,mode);
1937 void HDF5Writer::write(
const std::string& obj_name,
const multi1d<double>& datum,
const HDF5Base::writemode& mode){
1938 wt(obj_name,datum,H5T_NATIVE_DOUBLE,mode);
1941 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<short>& datum,
const HDF5Base::writemode& mode){
1942 wt(obj_name,datum,H5T_NATIVE_SHORT,mode);
1945 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<unsigned short>& datum,
const HDF5Base::writemode& mode){
1946 wt(obj_name,datum,H5T_NATIVE_USHORT,mode);
1949 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<int>& datum,
const HDF5Base::writemode& mode){
1950 wt(obj_name,datum,H5T_NATIVE_INT,mode);
1953 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<unsigned int>& datum,
const HDF5Base::writemode& mode){
1954 wt(obj_name,datum,H5T_NATIVE_UINT,mode);
1957 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<unsigned long long>& datum,
const HDF5Base::writemode& mode){
1958 wt(obj_name,datum,H5T_NATIVE_ULLONG,mode);
1961 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<float>& datum,
const HDF5Base::writemode& mode){
1962 wt(obj_name,datum,H5T_NATIVE_FLOAT,mode);
1965 void HDF5Writer::write(
const std::string& obj_name,
const multi2d<double>& datum,
const HDF5Base::writemode& mode){
1966 wt(obj_name,datum,H5T_NATIVE_DOUBLE,mode);
1977 void HDF5Writer::write< PScalar< PScalar< RComplex<float> > > >(
const std::string& dataname,
const ComplexF& datum,
const HDF5Base::writemode& mode){
1979 bool exists=objectExists(file_id,
".ComplexFloat");
1981 type_id=createComplexType(
sizeof(
REAL32));
1982 commitType(
".ComplexFloat",type_id);
1985 type_id=H5Topen(file_id,
".ComplexFloat",H5P_DEFAULT);
1987 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
1992 wt(dataname,datum,type_id,mode);
1997 void HDF5Writer::write< PScalar< PScalar< RComplex<double> > > >(
const std::string& dataname,
const ComplexD& datum,
const HDF5Base::writemode& mode){
1999 bool exists=objectExists(file_id,
".ComplexDouble");
2001 type_id=createComplexType(
sizeof(
REAL64));
2002 commitType(
".ComplexDouble",type_id);
2005 type_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2007 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2012 wt(dataname,datum,type_id,mode);
2018 void HDF5Writer::write< PScalar< PScalar< RComplex<float> > > >(
const std::string& dataname,
const multi1d<ComplexF>& datum,
const HDF5Base::writemode& mode){
2020 bool exists=objectExists(file_id,
".ComplexFloat");
2022 type_id=createComplexType(
sizeof(
REAL32));
2023 commitType(
".ComplexFloat",type_id);
2026 type_id=H5Topen(file_id,
".ComplexFloat",H5P_DEFAULT);
2028 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2033 wt(dataname,datum,type_id,mode);
2038 void HDF5Writer::write< PScalar< PScalar< RComplex<double> > > >(
const std::string& dataname,
const multi1d<ComplexD>& datum,
const HDF5Base::writemode& mode){
2040 bool exists=objectExists(file_id,
".ComplexDouble");
2042 type_id=createComplexType(
sizeof(
REAL64));
2043 commitType(
".ComplexDouble",type_id);
2046 type_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2048 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2053 wt(dataname,datum,type_id,mode);
2059 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL32>, 3> > >(
const std::string& dataname,
const ColorMatrixF3& datum,
const HDF5Base::writemode& mode){
2061 hid_t complex_id, colmat_id;
2062 bool exists=objectExists(file_id,
".ComplexFloat");
2064 complex_id=createComplexType(
sizeof(
REAL32));
2065 commitType(
".ComplexFloat",complex_id);
2068 complex_id=H5Topen(file_id,
".ComplexFloat",H5P_DEFAULT);
2070 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2075 exists=objectExists(file_id,
".ColorMatrixFloat3");
2077 colmat_id=createColorMatrixType(complex_id,Nc);
2078 commitType(
".ColorMatrixFloat3",colmat_id);
2081 colmat_id=H5Topen(file_id,
".ColorMatrixFloat3",H5P_DEFAULT);
2083 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2087 wt(dataname,datum,colmat_id,mode);
2088 H5Tclose(complex_id);
2089 H5Tclose(colmat_id);
2093 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(
const std::string& dataname,
const ColorMatrixD3& datum,
const HDF5Base::writemode& mode){
2095 hid_t complex_id, colmat_id;
2096 bool exists=objectExists(file_id,
".ComplexDouble");
2098 complex_id=createComplexType(
sizeof(
REAL64));
2099 commitType(
".ComplexDouble",complex_id);
2102 complex_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2104 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2109 exists=objectExists(file_id,
".ColorMatrixDouble3");
2111 colmat_id=createColorMatrixType(complex_id,Nc);
2112 commitType(
".ColorMatrixDouble3",colmat_id);
2115 colmat_id=H5Topen(file_id,
".ColorMatrixDouble3",H5P_DEFAULT);
2117 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2121 wt(dataname,datum,colmat_id,mode);
2122 H5Tclose(complex_id);
2123 H5Tclose(colmat_id);
2132 void HDF5Writer::writePrepare(
const std::string& name,
const HDF5Base::writemode& mode){
2136 bool exists=objectExists(current_group,name);
2138 if(!(mode&HDF5Base::trunc)){
2139 HDF5_error_exit(
"HDF5Writer::write: error, dataset already exists and you specified not to overwrite!");
2142 errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
2143 if(objinfo.type!=H5O_TYPE_DATASET){
2144 HDF5_error_exit(
"HDF5Writer::write: error, the object you try to write does already exist and is of different type!");
2147 deleteAllAttributes(name);
2148 errhandle=H5Ldelete(current_group,name.c_str(),H5P_DEFAULT);
2152 if(!isprefetched) prefetchLatticeCoordinates();
2155 void HDF5Writer::writeLattice(
const std::string& name,
const hid_t& datatype,
const ullong& obj_size,
char* buf){
2159 unsigned int dimension;
2160 if(obj_size>1) dimension=
Nd+1;
2164 hsize_t rank =
static_cast<hsize_t
>(dimension);
2165 hsize_t* spacesize =
new hsize_t[dimension];
2167 for(
unsigned int i = 0; i <
Nd; i ++) {
2168 spacesize[i] = Layout::lattSize()[(
Nd - 1) - i];
2170 if(obj_size>1) spacesize[
Nd] = obj_size;
2171 hid_t filespace = H5Screate_simple(rank,
const_cast<const hsize_t*
>(spacesize), NULL);
2172 hid_t dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
2175 hsize_t* node_offset =
new hsize_t[dimension];
2176 hsize_t* offset =
new hsize_t[dimension];
2177 hsize_t* total_count =
new hsize_t[dimension];
2178 hsize_t* dim_size =
new hsize_t[dimension];
2180 for(
unsigned int i = 0; i <
Nd; ++ i){
2181 dim_size[i] = total_count[i] = Layout::subgridLattSize()[(
Nd - 1) - i];
2182 offset[i] = node_offset[i] = Layout::nodeCoord()[(
Nd - 1) - i] * total_count[i];
2185 dim_size[
Nd] = total_count[
Nd] = obj_size;
2186 offset[
Nd] = node_offset[
Nd] = 0;
2190 if(stripesize > 0) H5Pset_chunk(dcpl_id,dimension, total_count);
2193 hid_t dset_id = H5Dcreate(current_group, name.c_str(), datatype, filespace,
2194 H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
2195 H5Sclose(filespace);
2197 delete [] spacesize;
2200 hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
2201 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
2203 size_t typesize=H5Tget_size(datatype);
2204 size_t total_size = typesize * obj_size * Layout::sitesOnNode();
2205 size_t two_gb = (size_t) 2 * 1024 * 1024 * 1024;
2208 while(total_size *
sizeof(
REAL) > two_gb) {
2209 dim_size[0] = dim_size[0] >> 1;
2210 total_size = total_size >> 1;
2213 int blocks = 1 << power;
2216 hid_t memspace = H5Screate_simple(rank, dim_size, NULL);
2217 filespace = H5Dget_space(dset_id);
2219 for(
int i = 0; i < blocks; ++ i) {
2220 offset[0] = node_offset[0] + i * dim_size[0];
2221 H5Sselect_hyperslab(filespace, H5S_SELECT_SET,
const_cast<const hsize_t*
>(offset), NULL,
2222 const_cast<const hsize_t*
>(dim_size), NULL);
2224 H5Dwrite(dset_id, datatype, memspace, filespace, plist_id, buf + i * total_size);
2229 delete [] total_count;
2231 delete [] node_offset;
2234 H5Sclose(filespace);
2241 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL32>, 3> > >(
const std::string& name,
const LatticeColorMatrixF3& field,
const HDF5Base::writemode& mode){
2242 StopWatch swatch_prepare, swatch_reorder, swatch_write, swatch_datatypes;
2245 if(profile) swatch_prepare.start();
2246 writePrepare(name,mode);
2247 if(profile) swatch_prepare.stop();
2250 if(profile) swatch_datatypes.start();
2251 hid_t complex_id, colmat_id;
2252 bool exists=objectExists(file_id,
".ComplexFloat");
2254 complex_id=createComplexType(
sizeof(
REAL32));
2255 commitType(
".ComplexFloat",complex_id);
2258 complex_id=H5Topen(file_id,
".ComplexFloat",H5P_DEFAULT);
2260 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2263 exists=objectExists(file_id,
".ColorMatrixFloat3");
2265 colmat_id=createColorMatrixType(complex_id,Nc);
2266 commitType(
".ColorMatrixFloat3",colmat_id);
2269 colmat_id=H5Topen(file_id,
".ColorMatrixFloat3",H5P_DEFAULT);
2271 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2274 if(profile) swatch_datatypes.stop();
2277 if(profile) swatch_reorder.start();
2278 const int mynode=Layout::nodeNumber();
2279 const int nodeSites = Layout::sitesOnNode();
2282 size_t float_size=
sizeof(
REAL32);
2289 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,float_size*obj_size);
2290 if(profile) swatch_reorder.stop();
2293 if(profile) swatch_write.start();
2294 writeLattice(name,colmat_id,1,
reinterpret_cast<char*
>(buf));
2297 H5Tclose(colmat_id);
2298 H5Tclose(complex_id);
2300 if(profile) swatch_write.stop();
2303 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
2304 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
2305 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
2306 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
2307 QDPIO::cout <<
"\t write: " << swatch_write.getTimeInSeconds() <<
" s." << std::endl;
2308 QDPIO::cout <<
"\t MB written: " << Layout::vol()*
sizeof(
ColorMatrixF3)/1024/1024 << std::endl;
2314 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(
const std::string& name,
const LatticeColorMatrixD3& field,
const HDF5Base::writemode& mode)
2316 StopWatch swatch_prepare, swatch_reorder, swatch_write, swatch_datatypes;
2319 if(profile) swatch_prepare.start();
2320 writePrepare(name,mode);
2321 if(profile) swatch_prepare.stop();
2324 if(profile) swatch_datatypes.start();
2325 hid_t complex_id, colmat_id;
2326 bool exists=objectExists(file_id,
".ComplexDouble");
2328 complex_id=createComplexType(
sizeof(
REAL64));
2329 commitType(
".ComplexDouble",complex_id);
2332 complex_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2334 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2337 exists=objectExists(file_id,
".ColorMatrixDouble3");
2339 colmat_id=createColorMatrixType(complex_id,Nc);
2340 commitType(
".ColorMatrixDouble3",colmat_id);
2343 colmat_id=H5Topen(file_id,
".ColorMatrixDouble3",H5P_DEFAULT);
2345 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2348 if(profile) swatch_datatypes.stop();
2351 if(profile) swatch_reorder.start();
2352 const int mynode=Layout::nodeNumber();
2353 const int nodeSites = Layout::sitesOnNode();
2356 size_t float_size=
sizeof(
REAL64);
2363 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,float_size*obj_size);
2364 if(profile) swatch_reorder.stop();
2367 if(profile) swatch_write.start();
2368 writeLattice(name,colmat_id,1,
reinterpret_cast<char*
>(buf));
2371 H5Tclose(colmat_id);
2372 H5Tclose(complex_id);
2374 if(profile) swatch_write.stop();
2377 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
2378 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
2379 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
2380 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
2381 QDPIO::cout <<
"\t write: " << swatch_write.getTimeInSeconds() <<
" s." << std::endl;
2382 QDPIO::cout <<
"\t MB written: " << Layout::vol()*
sizeof(
ColorMatrixD3)/1024/1024 << std::endl;
2388 void HDF5Writer::write< PSpinMatrix< PColorMatrix< RComplex<REAL32>, 3>, 4> >(
const std::string& name,
const LatticePropagatorF3& field,
const HDF5Base::writemode& mode){
2389 StopWatch swatch_prepare, swatch_reorder, swatch_write, swatch_datatypes;
2390 QDPIO::cout <<
"\t USING LatticePropagatorF3 writer" << std::endl;
2392 if(profile) swatch_prepare.start();
2393 writePrepare(name,mode);
2394 if(profile) swatch_prepare.stop();
2397 if(profile) swatch_datatypes.start();
2398 hid_t complex_id, colmat_id, prop_id;
2399 bool exists=objectExists(file_id,
".ComplexFloat");
2401 complex_id=createComplexType(
sizeof(
REAL32));
2402 commitType(
".ComplexFloat",complex_id);
2405 complex_id=H5Topen(file_id,
".ComplexFloat",H5P_DEFAULT);
2407 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2410 exists=objectExists(file_id,
".ColorMatrixFloat3");
2412 colmat_id=createColorMatrixType(complex_id,Nc);
2413 commitType(
".ColorMatrixFloat3",colmat_id);
2416 colmat_id=H5Topen(file_id,
".ColorMatrixFloat3",H5P_DEFAULT);
2418 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2421 exists=objectExists(file_id,
".PropagatorFloat3");
2423 prop_id=createPropagatorType(colmat_id,Ns);
2424 commitType(
".PropagatorFloat3",prop_id);
2427 prop_id=H5Topen(file_id,
".PropagatorFloat3",H5P_DEFAULT);
2429 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2432 if(profile) swatch_datatypes.stop();
2435 if(profile) swatch_reorder.start();
2436 const int mynode=Layout::nodeNumber();
2437 const int nodeSites = Layout::sitesOnNode();
2440 size_t float_size=
sizeof(
REAL32);
2447 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,float_size*obj_size);
2448 if(profile) swatch_reorder.stop();
2451 if(profile) swatch_write.start();
2452 writeLattice(name,prop_id,1,
reinterpret_cast<char*
>(buf));
2455 H5Tclose(colmat_id);
2456 H5Tclose(complex_id);
2458 if(profile) swatch_write.stop();
2461 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
2462 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
2463 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
2464 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
2465 QDPIO::cout <<
"\t write: " << swatch_write.getTimeInSeconds() <<
" s." << std::endl;
2466 QDPIO::cout <<
"\t MB written: " << Layout::vol()*
sizeof(
PropagatorF3)/1024/1024 << std::endl;
2472 void HDF5Writer::write< PSpinMatrix< PColorMatrix< RComplex<REAL64>, 3>, 4> >(
const std::string& name,
const LatticePropagatorD3& field,
const HDF5Base::writemode& mode)
2474 StopWatch swatch_prepare, swatch_reorder, swatch_write, swatch_datatypes;
2477 if(profile) swatch_prepare.start();
2478 writePrepare(name,mode);
2479 if(profile) swatch_prepare.stop();
2482 if(profile) swatch_datatypes.start();
2483 hid_t complex_id, colmat_id, prop_id;
2484 bool exists=objectExists(file_id,
".ComplexDouble");
2486 complex_id=createComplexType(
sizeof(
REAL64));
2487 commitType(
".ComplexDouble",complex_id);
2490 complex_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2492 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2495 exists=objectExists(file_id,
".ColorMatrixDouble3");
2497 colmat_id=createColorMatrixType(complex_id,Nc);
2498 commitType(
".ColorMatrixDouble3",colmat_id);
2501 colmat_id=H5Topen(file_id,
".ColorMatrixDouble3",H5P_DEFAULT);
2503 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2506 exists=objectExists(file_id,
".PropagatorDouble3");
2508 prop_id=createPropagatorType(colmat_id,Ns);
2509 commitType(
".PropagatorDouble3",prop_id);
2512 prop_id=H5Topen(file_id,
".PropagatorDouble3",H5P_DEFAULT);
2514 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2517 if(profile) swatch_datatypes.stop();
2520 if(profile) swatch_reorder.start();
2521 const int mynode=Layout::nodeNumber();
2522 const int nodeSites = Layout::sitesOnNode();
2525 size_t float_size=
sizeof(
REAL64);
2532 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,float_size*obj_size);
2533 if(profile) swatch_reorder.stop();
2536 if(profile) swatch_write.start();
2537 writeLattice(name,prop_id,1,
reinterpret_cast<char*
>(buf));
2540 H5Tclose(colmat_id);
2541 H5Tclose(complex_id);
2543 if(profile) swatch_write.stop();
2546 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
2547 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
2548 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
2549 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
2550 QDPIO::cout <<
"\t write: " << swatch_write.getTimeInSeconds() <<
" s." << std::endl;
2551 QDPIO::cout <<
"\t MB written: " << Layout::vol()*
sizeof(
PropagatorD3)/1024/1024 << std::endl;
2557 void HDF5Writer::write< PScalar< PColorMatrix< RComplex<REAL64>, 3> > >(
const std::string& name,
const multi1d<LatticeColorMatrixD3>& field,
const HDF5Base::writemode& mode)
2559 StopWatch swatch_prepare, swatch_reorder, swatch_write, swatch_datatypes;
2562 if(profile) swatch_prepare.start();
2563 writePrepare(name,mode);
2564 if(profile) swatch_prepare.stop();
2567 if(profile) swatch_datatypes.start();
2568 hid_t complex_id, colmat_id;
2569 bool exists=objectExists(file_id,
".ComplexDouble");
2571 complex_id=createComplexType(
sizeof(
REAL64));
2572 commitType(
".ComplexDouble",complex_id);
2575 complex_id=H5Topen(file_id,
".ComplexDouble",H5P_DEFAULT);
2577 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2580 exists=objectExists(file_id,
".ColorMatrixDouble3");
2582 colmat_id=createColorMatrixType(complex_id,Nc);
2583 commitType(
".ColorMatrixDouble3",colmat_id);
2586 colmat_id=H5Topen(file_id,
".ColorMatrixDouble3",H5P_DEFAULT);
2588 HDF5_error_exit(
"HDF5Writer::write: error, cannot open committed Datatype!");
2591 if(profile) swatch_datatypes.stop();
2594 if(profile) swatch_reorder.start();
2595 const int mynode=Layout::nodeNumber();
2596 const int nodeSites = Layout::sitesOnNode();
2599 size_t float_size=
sizeof(
REAL64);
2601 size_t tot_size = nodeSites*field.size()*obj_size;
2603 unsigned int fsize=field.size();
2610 CvtToHost(
reinterpret_cast<void*
>(buf),field,nodeSites,fsize,float_size*obj_size);
2611 if(profile) swatch_reorder.stop();
2614 if(profile) swatch_write.start();
2615 writeLattice(name,colmat_id,field.size(),
reinterpret_cast<char*
>(buf));
2618 H5Tclose(colmat_id);
2619 H5Tclose(complex_id);
2621 if(profile) swatch_write.stop();
2624 QDPIO::cout <<
"HDF5-I/O statistics. Write:" << std::endl;
2625 QDPIO::cout <<
"\t preparing: " << swatch_prepare.getTimeInSeconds() <<
" s." << std::endl;
2626 QDPIO::cout <<
"\t datatype-handling: " << swatch_datatypes.getTimeInSeconds() <<
" s." << std::endl;
2627 QDPIO::cout <<
"\t reordering: " << swatch_reorder.getTimeInSeconds() <<
" s." << std::endl;
2628 QDPIO::cout <<
"\t write: " << swatch_write.getTimeInSeconds() <<
" s." << std::endl;
2629 QDPIO::cout <<
"\t MB written: " << Layout::vol()*field.size()*
sizeof(
ColorMatrixD3)/1024/1024 << std::endl;
2634 void HDF5Writer::writeQlua(
const std::string& name,
const multi1d<LatticeColorMatrixD3>& field,
const HDF5Base::writemode& mode){
2635 StopWatch swatch_complete;
2637 QDPIO::cout<<
"Writing Qlua config..." << std::flush;
2638 if(profile) swatch_complete.start();
2639 if(field.size()!=Nd) HDF5_error_exit(
"HDF5Writer::writeQlua: passed vector is not a gauge field!");
2640 if(objectExists(current_group,name)){
2641 if(!(mode&HDF5Base::trunc)){
2642 HDF5_error_exit(
"HDF5Writer::writeQlua: error, object "+name+
" does already exist!");
2647 herr_t errhandle=H5Oget_info_by_name(current_group,name.c_str(),&objinfo,H5P_DEFAULT);
2648 if(objinfo.type!=H5O_TYPE_GROUP){
2649 HDF5_error_exit(
"HDF5Writer::writeQlua: error, "+name+
" exists but it is not a Qlua config!");
2652 for(
unsigned int i=0; i<
Nd; i++){
2653 std::stringstream stream;
2654 stream << name <<
"/" << i;
2655 std::string dname=stream.str();
2656 if(!objectExists(current_group,dname)){
2657 HDF5_error_exit(
"HDF5Writer::writeQlua: error, "+name+
" exists but it is not a Qlua config! Dataset "+dname+
" was not found!");
2660 deleteAllAttributes(name);
2661 H5Ldelete(current_group,name.c_str(),H5P_DEFAULT);
2666 for(
unsigned int i=0; i<
Nd; i++){
2667 std::stringstream stream;
2669 std::string dname(stream.str());
2670 write(dname,field[i],HDF5Base::ate);
2671 writeAttribute(dname,
".kind",
"LatticeColorMatrix");
2674 if(profile) swatch_complete.stop();
2675 QDPIO::cout<<
"done!" << std::endl;
2678 QDPIO::cout <<
"HDF5-I/O statistics for Qlua-write: " << std::endl;
2679 QDPIO::cout <<
"\t total: " << swatch_complete.getTimeInSeconds() <<
" s." << std::endl;
2680 QDPIO::cout <<
"\t MB written: " << Layout::vol()*field.size()*
sizeof(
ColorMatrixD3)/1024/1024 << std::endl;
HDF5(const long int &stripesizee=-1, const long int &maxalign=0)
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< PSpinMatrix< PColorMatrix< RComplex< REAL64 >, 3 >, Ns > > PropagatorD3
OScalar< PScalar< PScalar< RComplex< REAL64 > > > > ComplexD
OScalar< PSpinMatrix< PColorMatrix< RComplex< REAL32 >, 3 >, Ns > > PropagatorF3
OScalar< PSpinMatrix< PColorMatrix< RComplex< REAL64 >, 3 >, 4 > > DiracPropagatorD3
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
OScalar< PSpinMatrix< PColorMatrix< RComplex< REAL32 >, 3 >, 4 > > DiracPropagatorF3
void write(BinaryWriter &bin, const std::string &output)
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
void close(QDPFileReader &qsw)
Close a QDPFileReader.
Yet another random number generator.
bool get_global(ctype &global, const ctype &local)
void push(XMLWriter &xml, const std::string &s)
Push a group name.
void pop(XMLWriter &xml)
Pop a group name.
multi1d< int > crtesn(int ipos, const multi1d< int > &latt_size)
Decompose a lexicographic site into coordinates.
Primary include file for QDP.
unsigned long long ullong