47 #ifdef HAVE_EPETRAEXT_HDF5
52 # include <H5FDmpio.h>
53 # include "Epetra_MpiComm.h"
60 #include "Epetra_SerialComm.h"
62 #include "Teuchos_ParameterList.hpp"
63 #include "Teuchos_RCP.hpp"
64 #include "Epetra_Map.h"
65 #include "Epetra_BlockMap.h"
66 #include "Epetra_CrsGraph.h"
67 #include "Epetra_FECrsGraph.h"
68 #include "Epetra_RowMatrix.h"
69 #include "Epetra_CrsMatrix.h"
70 #include "Epetra_FECrsMatrix.h"
71 #include "Epetra_IntVector.h"
72 #include "Epetra_MultiVector.h"
73 #include "Epetra_Import.h"
78 #define CHECK_HID(hid_t) \
80 throw(EpetraExt::Exception(__FILE__, __LINE__, \
81 "hid_t is negative")); }
83 #define CHECK_STATUS(status) \
85 throw(EpetraExt::Exception(__FILE__, __LINE__, \
86 "function H5Giterater returned a negative value")); }
96 static herr_t
FindDataset(hid_t loc_id,
const char *name,
void *opdata)
110 Teuchos::ParameterList::ConstIterator it = params.begin();
111 for (; it != params.end(); ++ it)
113 std::string key(params.name(it));
114 if (params.isSublist(key))
119 hid_t child_group_id = H5Gcreate(group_id, key.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
121 H5Gclose(child_group_id);
132 hid_t dataspace_id, dataset_id;
136 if (params.isType<std::string>(key))
138 std::string value = params.get<std::string>(key);
139 hsize_t len = value.size() + 1;
140 dataspace_id = H5Screate_simple(1, &len, NULL);
141 dataset_id = H5Dcreate(group_id, key.c_str(), H5T_C_S1, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
142 status = H5Dwrite(dataset_id, H5T_C_S1, H5S_ALL, H5S_ALL,
143 H5P_DEFAULT, value.c_str());
145 status = H5Dclose(dataset_id);
147 status = H5Sclose(dataspace_id);
152 if (params.isType<
bool>(key))
155 unsigned short value = params.get<
bool>(key) ? 1 : 0;
156 dataspace_id = H5Screate_simple(1, &one, NULL);
157 dataset_id = H5Dcreate(group_id, key.c_str(), H5T_NATIVE_USHORT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
158 status = H5Dwrite(dataset_id, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL,
159 H5P_DEFAULT, &value);
161 status = H5Dclose(dataset_id);
163 status = H5Sclose(dataspace_id);
168 if (params.isType<
int>(key))
170 int value = params.get<
int>(key);
171 dataspace_id = H5Screate_simple(1, &one, NULL);
172 dataset_id = H5Dcreate(group_id, key.c_str(), H5T_NATIVE_INT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
173 status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
174 H5P_DEFAULT, &value);
176 status = H5Dclose(dataset_id);
178 status = H5Sclose(dataspace_id);
183 if (params.isType<
double>(key))
185 double value = params.get<
double>(key);
186 dataspace_id = H5Screate_simple(1, &one, NULL);
187 dataset_id = H5Dcreate(group_id, key.c_str(), H5T_NATIVE_DOUBLE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
188 status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
189 H5P_DEFAULT, &value);
191 status = H5Dclose(dataset_id);
193 status = H5Sclose(dataspace_id);
201 "type for parameter " + key +
" not supported"));
210 static herr_t
f_operator(hid_t loc_id,
const char *name,
void *opdata)
213 hid_t dataset_id, space_id, type_id;
214 Teuchos::ParameterList* sublist;
215 Teuchos::ParameterList* params = (Teuchos::ParameterList*)opdata;
221 H5Gget_objinfo(loc_id, name, 0, &statbuf);
222 if (strcmp(name,
"__type__") == 0)
225 switch (statbuf.type) {
227 sublist = ¶ms->sublist(name);
228 H5Giterate(loc_id, name , NULL,
f_operator, sublist);
232 dataset_id = H5Dopen(loc_id, name, H5P_DEFAULT);
233 space_id = H5Dget_space(dataset_id);
234 if (H5Sget_simple_extent_ndims(space_id) != 1)
236 "dimensionality of parameters must be 1."));
237 H5Sget_simple_extent_dims(space_id, &len, NULL);
238 type_id = H5Dget_type(dataset_id);
239 if (H5Tequal(type_id, H5T_NATIVE_DOUBLE) > 0) {
241 H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
242 params->set(name, value);
243 }
else if (H5Tequal(type_id, H5T_NATIVE_INT) > 0) {
245 H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
246 params->set(name, value);
247 }
else if (H5Tequal(type_id, H5T_C_S1) > 0) {
248 char* buf =
new char[len];
249 H5Dread(dataset_id, H5T_C_S1, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
250 params->set(name, std::string(buf));
252 }
else if (H5Tequal(type_id, H5T_NATIVE_USHORT) > 0) {
253 unsigned short value;
254 H5Dread(dataset_id, H5T_NATIVE_USHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
255 params->set(name, value != 0 ?
true :
false);
258 "unsupported datatype"));
262 H5Dclose(dataset_id);
266 "unsupported datatype"));
282 "an HDF5 is already open, first close the current one",
283 "using method Close(), then open/create a new one"));
285 FileName_ = FileName;
288 plist_id_ = H5Pcreate(H5P_FILE_ACCESS);
298 MPI_Comm mpiComm = MPI_COMM_NULL;
303 if (mpiWrapper != NULL) {
304 mpiComm = mpiWrapper->
Comm();
311 if (serialWrapper != NULL) {
317 mpiComm = MPI_COMM_SELF;
321 const char*
const errMsg =
"EpetraExt::HDF5::Create: This HDF5 object "
322 "was created with an Epetra_Comm instance which is neither an "
323 "Epetra_MpiComm nor a Epetra_SerialComm. As a result, we do not "
324 "know how to get an MPI communicator from it. Our HDF5 class only "
325 "understands Epetra_Comm objects which are instances of one of these "
333 if (mpiComm == MPI_COMM_NULL) {
334 const char*
const errMsg =
"EpetraExt::HDF5::Create: The Epetra_Comm "
335 "object with which this HDF5 instance was created wraps MPI_COMM_NULL, "
336 "which is an invalid MPI communicator. HDF5 requires a valid MPI "
347 H5Pset_fapl_mpio(plist_id_, mpiComm, MPI_INFO_NULL);
352 unsigned int boh = H5Z_FILTER_MAX;
353 H5Pset_filter(plist_id_, H5Z_FILTER_DEFLATE, H5Z_FILTER_MAX, 0, &boh);
357 file_id_ = H5Fcreate(FileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
369 "an HDF5 is already open, first close the current one",
370 "using method Close(), then open/create a new one"));
372 FileName_ = FileName;
375 plist_id_ = H5Pcreate(H5P_FILE_ACCESS);
379 const Epetra_MpiComm* MpiComm ( dynamic_cast<const Epetra_MpiComm*> (&Comm_) );
382 H5Pset_fapl_mpio(plist_id_, MPI_COMM_WORLD, MPI_INFO_NULL);
384 H5Pset_fapl_mpio(plist_id_, MpiComm->
Comm(), MPI_INFO_NULL);
388 file_id_ = H5Fopen(FileName.c_str(), AccessType, plist_id_);
398 throw(
Exception(__FILE__, __LINE__,
"no file open yet"));
405 size_t pos = Name.find(
"/");
406 if (pos != std::string::npos)
408 std::string NewGroupName = Name.substr(0, pos);
410 NewGroupName = GroupName +
"/" + NewGroupName;
411 std::string NewName = Name.substr(pos + 1);
412 return IsContained(NewName, NewGroupName);
415 GroupName =
"/" + GroupName;
418 H5Giterate(file_id_, GroupName.c_str(), NULL,
FindDataset, (
void*)&data);
437 std::vector<int> NumMyElements_v(Comm_.NumProc());
438 Comm_.GatherAll(&NumMyElements, &NumMyElements_v[0], 1);
440 std::vector<int> NumMyPoints_v(Comm_.NumProc());
441 Comm_.GatherAll(&NumMyPoints, &NumMyPoints_v[0], 1);
443 Write(Name,
"MyGlobalElements", NumMyElements, NumGlobalElements,
444 H5T_NATIVE_INT, MyGlobalElements);
445 Write(Name,
"ElementSizeList", NumMyElements, NumGlobalElements,
446 H5T_NATIVE_INT, ElementSizeList);
447 Write(Name,
"NumMyPoints", H5T_NATIVE_INT, Comm_.NumProc(), &NumMyPoints_v[0]);
450 Write(Name,
"NumProc", Comm_.NumProc());
452 Write(Name,
"NumGlobalPoints", 1, Comm_.NumProc(), H5T_NATIVE_INT, &NumGlobalPoints);
453 Write(Name,
"NumGlobalElements", 1, Comm_.NumProc(), H5T_NATIVE_INT, &NumGlobalElements);
454 Write(Name,
"IndexBase", BlockMap.
IndexBase());
455 Write(Name,
"__type__",
"Epetra_BlockMap");
461 int NumGlobalElements, NumGlobalPoints, IndexBase, NumProc;
463 ReadBlockMapProperties(GroupName, NumGlobalElements, NumGlobalPoints,
466 std::vector<int> NumMyPoints_v(Comm_.NumProc());
467 std::vector<int> NumMyElements_v(Comm_.NumProc());
469 Read(GroupName,
"NumMyElements", H5T_NATIVE_INT, Comm_.NumProc(), &NumMyElements_v[0]);
470 Read(GroupName,
"NumMyPoints", H5T_NATIVE_INT, Comm_.NumProc(), &NumMyPoints_v[0]);
471 int NumMyElements = NumMyElements_v[Comm_.MyPID()];
474 if (NumProc != Comm_.NumProc())
476 "requested map not compatible with current number of",
477 "processors, " +
toString(Comm_.NumProc()) +
480 std::vector<int> MyGlobalElements(NumMyElements);
481 std::vector<int> ElementSizeList(NumMyElements);
483 Read(GroupName,
"MyGlobalElements", NumMyElements, NumGlobalElements,
484 H5T_NATIVE_INT, &MyGlobalElements[0]);
486 Read(GroupName,
"ElementSizeList", NumMyElements, NumGlobalElements,
487 H5T_NATIVE_INT, &ElementSizeList[0]);
490 &MyGlobalElements[0], &ElementSizeList[0],
496 int& NumGlobalElements,
497 int& NumGlobalPoints,
501 if (!IsContained(GroupName))
503 "requested group " + GroupName +
" not found"));
506 Read(GroupName,
"__type__", Label);
508 if (Label !=
"Epetra_BlockMap")
510 "requested group " + GroupName +
" is not an Epetra_BlockMap",
511 "__type__ = " + Label));
513 Read(GroupName,
"NumGlobalElements", NumGlobalElements);
514 Read(GroupName,
"NumGlobalPoints", NumGlobalPoints);
515 Read(GroupName,
"IndexBase", IndexBase);
516 Read(GroupName,
"NumProc", NumProc);
526 std::vector<int> NumMyElements(Comm_.NumProc());
527 Comm_.GatherAll(&MySize, &NumMyElements[0], 1);
529 Write(Name,
"MyGlobalElements", MySize, GlobalSize,
530 H5T_NATIVE_INT, MyGlobalElements);
531 Write(Name,
"NumMyElements", H5T_NATIVE_INT, Comm_.NumProc(), &NumMyElements[0]);
532 Write(Name,
"NumGlobalElements", 1, Comm_.NumProc(), H5T_NATIVE_INT, &GlobalSize);
533 Write(Name,
"NumProc", Comm_.NumProc());
534 Write(Name,
"IndexBase", Map.
IndexBase());
535 Write(Name,
"__type__",
"Epetra_Map");
541 int NumGlobalElements, IndexBase, NumProc;
543 ReadMapProperties(GroupName, NumGlobalElements, IndexBase, NumProc);
545 std::vector<int> NumMyElements_v(Comm_.NumProc());
547 Read(GroupName,
"NumMyElements", H5T_NATIVE_INT, Comm_.NumProc(), &NumMyElements_v[0]);
548 int NumMyElements = NumMyElements_v[Comm_.MyPID()];
550 if (NumProc != Comm_.NumProc())
552 "requested map not compatible with current number of",
553 "processors, " +
toString(Comm_.NumProc()) +
556 std::vector<int> MyGlobalElements(NumMyElements);
558 Read(GroupName,
"MyGlobalElements", NumMyElements, NumGlobalElements,
559 H5T_NATIVE_INT, &MyGlobalElements[0]);
561 Map =
new Epetra_Map(-1, NumMyElements, &MyGlobalElements[0], IndexBase, Comm_);
566 int& NumGlobalElements,
570 if (!IsContained(GroupName))
572 "requested group " + GroupName +
" not found"));
575 Read(GroupName,
"__type__", Label);
577 if (Label !=
"Epetra_Map")
579 "requested group " + GroupName +
" is not an Epetra_Map",
580 "__type__ = " + Label));
582 Read(GroupName,
"NumGlobalElements", NumGlobalElements);
583 Read(GroupName,
"IndexBase", IndexBase);
584 Read(GroupName,
"NumProc", NumProc);
594 if (x.Map().LinearMap())
597 Write(Name,
"Values", x.Map().NumMyElements(), x.Map().NumGlobalElements(),
598 H5T_NATIVE_INT, x.
Values());
609 LinearX.Import(x, Importer,
Insert);
612 Write(Name,
"Values", LinearMap.NumMyElements(), LinearMap.NumGlobalElements(),
613 H5T_NATIVE_INT, LinearX.
Values());
615 Write(Name,
"__type__",
"Epetra_IntVector");
623 ReadIntVectorProperties(GroupName, GlobalLength);
639 ReadIntVectorProperties(GroupName, GlobalLength);
646 H5T_NATIVE_INT, X->
Values());
656 Read(GroupName,
"Values", LinearMap.NumMyElements(),
657 LinearMap.NumGlobalElements(),
658 H5T_NATIVE_INT, LinearX.Values());
662 X->Import(LinearX, Importer,
Insert);
670 if (!IsContained(GroupName))
672 "requested group " + GroupName +
" not found"));
675 Read(GroupName,
"__type__", Label);
677 if (Label !=
"Epetra_IntVector")
679 "requested group " + GroupName +
" is not an Epetra_IntVector",
680 "__type__ = " + Label));
682 Read(GroupName,
"GlobalLength", GlobalLength);
694 "input Epetra_CrsGraph is not FillComplete()'d"));
699 std::vector<int> ROW(MySize);
700 std::vector<int> COL(MySize);
706 for (
int i = 0; i < Graph.
NumMyRows(); ++i)
709 for (
int j = 0; j < NumEntries; ++j)
711 ROW[count] = Graph.
GRID(i);
712 COL[count] = Graph.
GCID(RowIndices[j]);
717 Write(Name,
"ROW", MySize, GlobalSize, H5T_NATIVE_INT, &ROW[0]);
718 Write(Name,
"COL", MySize, GlobalSize, H5T_NATIVE_INT, &COL[0]);
724 Write(Name,
"__type__",
"Epetra_CrsGraph");
730 int NumGlobalRows, NumGlobalCols;
731 int NumGlobalNonzeros, NumGlobalDiagonals, MaxNumIndices;
733 ReadCrsGraphProperties(GroupName, NumGlobalRows,
734 NumGlobalCols, NumGlobalNonzeros,
735 NumGlobalDiagonals, MaxNumIndices);
738 Epetra_Map DomainMap(NumGlobalCols, 0, Comm_);
740 Read(GroupName, DomainMap, RangeMap, Graph);
747 int& NumGlobalNonzeros,
748 int& NumGlobalDiagonals,
751 if (!IsContained(GroupName))
753 "requested group " + GroupName +
" not found"));
756 Read(GroupName,
"__type__", Label);
758 if (Label !=
"Epetra_CrsGraph")
760 "requested group " + GroupName +
" is not an Epetra_CrsGraph",
761 "__type__ = " + Label));
763 Read(GroupName,
"NumGlobalRows", NumGlobalRows);
764 Read(GroupName,
"NumGlobalCols", NumGlobalCols);
765 Read(GroupName,
"NumGlobalNonzeros", NumGlobalNonzeros);
766 Read(GroupName,
"NumGlobalDiagonals", NumGlobalDiagonals);
767 Read(GroupName,
"MaxNumIndices", MaxNumIndices);
774 if (!IsContained(GroupName))
776 "requested group " + GroupName +
" not found in database"));
779 Read(GroupName,
"__type__", Label);
781 if (Label !=
"Epetra_CrsGraph")
783 "requested group " + GroupName +
" is not an Epetra_CrsGraph",
784 "__type__ = " + Label));
786 int NumGlobalRows, NumGlobalCols, NumGlobalNonzeros;
787 Read(GroupName,
"NumGlobalNonzeros", NumGlobalNonzeros);
788 Read(GroupName,
"NumGlobalRows", NumGlobalRows);
789 Read(GroupName,
"NumGlobalCols", NumGlobalCols);
792 int NumMyNonzeros = NumGlobalNonzeros / Comm_.NumProc();
793 if (Comm_.MyPID() == 0)
794 NumMyNonzeros += NumGlobalNonzeros % Comm_.NumProc();
796 std::vector<int> ROW(NumMyNonzeros);
797 Read(GroupName,
"ROW", NumMyNonzeros, NumGlobalNonzeros, H5T_NATIVE_INT, &ROW[0]);
799 std::vector<int> COL(NumMyNonzeros);
800 Read(GroupName,
"COL", NumMyNonzeros, NumGlobalNonzeros, H5T_NATIVE_INT, &COL[0]);
804 for (
int i = 0; i < NumMyNonzeros; )
807 while (ROW[i + count] == ROW[i])
828 "input Epetra_RowMatrix is not FillComplete()'d"));
832 std::vector<int> ROW(MySize);
833 std::vector<int> COL(MySize);
834 std::vector<double> VAL(MySize);
838 std::vector<int> Indices(Length);
839 std::vector<double> Values(Length);
842 for (
int i = 0; i < Matrix.
NumMyRows(); ++i)
845 for (
int j = 0; j < NumEntries; ++j)
849 VAL[count] = Values[j];
854 Write(Name,
"ROW", MySize, GlobalSize, H5T_NATIVE_INT, &ROW[0]);
855 Write(Name,
"COL", MySize, GlobalSize, H5T_NATIVE_INT, &COL[0]);
856 Write(Name,
"VAL", MySize, GlobalSize, H5T_NATIVE_DOUBLE, &VAL[0]);
862 Write(Name,
"NormOne", Matrix.
NormOne());
863 Write(Name,
"NormInf", Matrix.
NormInf());
864 Write(Name,
"__type__",
"Epetra_RowMatrix");
870 int NumGlobalRows, NumGlobalCols, NumGlobalNonzeros;
871 int NumGlobalDiagonals, MaxNumEntries;
872 double NormOne, NormInf;
874 ReadCrsMatrixProperties(GroupName, NumGlobalRows, NumGlobalCols,
875 NumGlobalNonzeros, NumGlobalDiagonals, MaxNumEntries,
880 Epetra_Map DomainMap(NumGlobalCols, 0, Comm_);
882 Read(GroupName, DomainMap, RangeMap, A);
889 int NumGlobalRows, NumGlobalCols, NumGlobalNonzeros;
890 int NumGlobalDiagonals, MaxNumEntries;
891 double NormOne, NormInf;
893 ReadCrsMatrixProperties(GroupName, NumGlobalRows, NumGlobalCols,
894 NumGlobalNonzeros, NumGlobalDiagonals, MaxNumEntries,
897 int NumMyNonzeros = NumGlobalNonzeros / Comm_.NumProc();
898 if (Comm_.MyPID() == 0)
899 NumMyNonzeros += NumGlobalNonzeros % Comm_.NumProc();
901 std::vector<int> ROW(NumMyNonzeros);
902 Read(GroupName,
"ROW", NumMyNonzeros, NumGlobalNonzeros, H5T_NATIVE_INT, &ROW[0]);
904 std::vector<int> COL(NumMyNonzeros);
905 Read(GroupName,
"COL", NumMyNonzeros, NumGlobalNonzeros, H5T_NATIVE_INT, &COL[0]);
907 std::vector<double> VAL(NumMyNonzeros);
908 Read(GroupName,
"VAL", NumMyNonzeros, NumGlobalNonzeros, H5T_NATIVE_DOUBLE, &VAL[0]);
912 for (
int i = 0; i < NumMyNonzeros; )
915 while (ROW[i + count] == ROW[i])
931 int& NumGlobalNonzeros,
932 int& NumGlobalDiagonals,
937 if (!IsContained(GroupName))
939 "requested group " + GroupName +
" not found"));
942 Read(GroupName,
"__type__", Label);
944 if (Label !=
"Epetra_RowMatrix")
946 "requested group " + GroupName +
" is not an Epetra_RowMatrix",
947 "__type__ = " + Label));
949 Read(GroupName,
"NumGlobalRows", NumGlobalRows);
950 Read(GroupName,
"NumGlobalCols", NumGlobalCols);
951 Read(GroupName,
"NumGlobalNonzeros", NumGlobalNonzeros);
952 Read(GroupName,
"NumGlobalDiagonals", NumGlobalDiagonals);
953 Read(GroupName,
"MaxNumEntries", MaxNumEntries);
954 Read(GroupName,
"NormOne", NormOne);
955 Read(GroupName,
"NormInf", NormInf);
966 throw(
Exception(__FILE__, __LINE__,
"no file open yet"));
968 hid_t group_id = H5Gcreate(file_id_, GroupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
974 status = H5Gclose(group_id);
977 Write(GroupName,
"__type__",
"Teuchos::ParameterList");
984 throw(
Exception(__FILE__, __LINE__,
"no file open yet"));
987 Read(GroupName,
"__type__", Label);
989 if (Label !=
"Teuchos::ParameterList")
991 "requested group " + GroupName +
" is not a Teuchos::ParameterList",
992 "__type__ = " + Label));
999 group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1003 std::string xxx =
"/" + GroupName;
1004 status = H5Giterate(group_id, xxx.c_str() , NULL,
f_operator, ¶ms);
1008 status = H5Gclose(group_id);
1021 throw(
Exception(__FILE__, __LINE__,
"no file open yet"));
1023 hid_t group_id, dset_id;
1024 hid_t filespace_id, memspace_id;
1028 Teuchos::RCP<Epetra_MultiVector> LinearX;
1030 if (X.Map().LinearMap())
1031 LinearX = Teuchos::rcp(const_cast<Epetra_MultiVector*>(&X),
false);
1034 Epetra_Map LinearMap(X.GlobalLength(), X.Map().IndexBase(), Comm_);
1037 LinearX->Import(X, Importer,
Insert);
1040 int NumVectors = X.NumVectors();
1041 int GlobalLength = X.GlobalLength();
1047 if (writeTranspose) indexT = 1;
1049 hsize_t q_dimsf[] = {
static_cast<hsize_t
>(GlobalLength), static_cast<hsize_t>(GlobalLength)};
1050 q_dimsf[indexT] = NumVectors;
1052 filespace_id = H5Screate_simple(2, q_dimsf, NULL);
1054 if (!IsContained(GroupName))
1055 CreateGroup(GroupName);
1057 group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1060 dset_id = H5Dcreate(group_id,
"Values", H5T_NATIVE_DOUBLE, filespace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1063 plist_id_ = H5Pcreate(H5P_DATASET_XFER);
1065 H5Pset_dxpl_mpio(plist_id_, H5FD_MPIO_COLLECTIVE);
1070 hsize_t offset[] = {
static_cast<hsize_t
>(LinearX->Map().GID(0)-X.Map().IndexBase()),
1071 static_cast<hsize_t>(LinearX->Map().GID(0)-X.Map().IndexBase())};
1072 hsize_t stride[] = {1, 1};
1073 hsize_t count[] = {
static_cast<hsize_t
>(LinearX->MyLength()),
1074 static_cast<hsize_t>(LinearX->MyLength())};
1075 hsize_t block[] = {1, 1};
1078 for (
int n(0); n < NumVectors; ++n)
1084 filespace_id = H5Dget_space(dset_id);
1085 H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET, offset, stride,
1089 hsize_t dimsm[] = {
static_cast<hsize_t
>(LinearX->MyLength())};
1090 memspace_id = H5Screate_simple(1, dimsm, NULL);
1093 status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, memspace_id, filespace_id,
1094 plist_id_, LinearX->operator[](n));
1096 H5Sclose(memspace_id);
1099 H5Sclose(filespace_id);
1101 H5Pclose(plist_id_);
1103 Write(GroupName,
"GlobalLength", GlobalLength);
1104 Write(GroupName,
"NumVectors", NumVectors);
1105 Write(GroupName,
"__type__",
"Epetra_MultiVector");
1114 Read(GroupName, LinearX, writeTranspose, Map.
IndexBase());
1119 X->Import(*LinearX, Importer,
Insert);
1127 bool readTranspose,
const int& indexBase)
1129 int GlobalLength, NumVectors;
1131 ReadMultiVectorProperties(GroupName, GlobalLength, NumVectors);
1140 if (readTranspose) indexT = 1;
1142 hsize_t q_dimsf[] = {
static_cast<hsize_t
>(GlobalLength), static_cast<hsize_t>(GlobalLength)};
1143 q_dimsf[indexT] = NumVectors;
1145 hid_t filespace_id = H5Screate_simple(2, q_dimsf, NULL);
1147 if (!IsContained(GroupName))
1149 "requested group " + GroupName +
" not found"));
1151 group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1154 hid_t dset_id = H5Dopen(group_id,
"Values", H5P_DEFAULT);
1157 plist_id_ = H5Pcreate(H5P_DATASET_XFER);
1159 H5Pset_dxpl_mpio(plist_id_, H5FD_MPIO_COLLECTIVE);
1161 H5Pclose(plist_id_);
1163 Epetra_Map LinearMap(GlobalLength, indexBase, Comm());
1167 hsize_t offset[] = {
static_cast<hsize_t
>(LinearMap.
GID(0) - indexBase), static_cast<hsize_t>(LinearMap.
GID(0) - indexBase)};
1168 hsize_t stride[] = {1, 1};
1175 hsize_t count[] = {1, 1};
1176 hsize_t block[] = {
static_cast<hsize_t
>(LinearX->MyLength()), static_cast<hsize_t>(LinearX->MyLength())};
1179 count [indexT] = NumVectors;
1182 filespace_id = H5Dget_space(dset_id);
1183 H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET, offset, stride,
1187 hsize_t dimsm[] = {NumVectors *
static_cast<hsize_t
>(LinearX->MyLength())};
1188 memspace_id = H5Screate_simple(1, dimsm, NULL);
1191 CHECK_STATUS(H5Dread(dset_id, H5T_NATIVE_DOUBLE, memspace_id, filespace_id,
1192 H5P_DEFAULT, LinearX->Values()));
1198 hsize_t count[] = {
static_cast<hsize_t
>(LinearX->MyLength()),
1199 static_cast<hsize_t>(LinearX->MyLength())};
1200 hsize_t block[] = {1, 1};
1203 for (
int n(0); n < NumVectors; ++n)
1209 filespace_id = H5Dget_space(dset_id);
1210 H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET, offset, stride,
1214 hsize_t dimsm[] = {
static_cast<hsize_t
>(LinearX->MyLength())};
1215 memspace_id = H5Screate_simple(1, dimsm, NULL);
1218 CHECK_STATUS(H5Dread(dset_id, H5T_NATIVE_DOUBLE, memspace_id, filespace_id,
1219 H5P_DEFAULT, LinearX->operator[](n)));
1235 if (!IsContained(GroupName))
1237 "requested group " + GroupName +
" not found"));
1240 Read(GroupName,
"__type__", Label);
1242 if (Label !=
"Epetra_MultiVector")
1244 "requested group " + GroupName +
" is not an Epetra_MultiVector",
1245 "__type__ = " + Label));
1247 Read(GroupName,
"GlobalLength", GlobalLength);
1248 Read(GroupName,
"NumVectors", NumVectors);
1258 if (x.Map().LinearMap())
1260 Write(GroupName,
"Values", x.Map().NumMyElements() * x.
RowSize(),
1261 x.Map().NumGlobalElements() * x.
RowSize(),
1262 H5T_NATIVE_INT, x.
Values());
1273 LinearX.Import(x, Importer,
Insert);
1277 H5T_NATIVE_INT, LinearX.Values());
1280 Write(GroupName,
"__type__",
"EpetraExt::DistArray<int>");
1282 Write(GroupName,
"RowSize", x.
RowSize());
1290 int GlobalLength, RowSize;
1291 ReadIntDistArrayProperties(GroupName, GlobalLength, RowSize);
1297 Read(GroupName,
"Values", Map.NumMyElements() * RowSize,
1298 Map.NumGlobalElements() * RowSize, H5T_NATIVE_INT, X->
Values());
1307 Read(GroupName,
"Values", LinearMap.
NumMyElements() * RowSize,
1309 H5T_NATIVE_INT, LinearX.Values());
1313 X->Import(LinearX, Importer,
Insert);
1321 int GlobalLength, RowSize;
1322 ReadIntDistArrayProperties(GroupName, GlobalLength, RowSize);
1325 Epetra_Map LinearMap(GlobalLength, 0, Comm_);
1328 Read(GroupName,
"Values", LinearMap.NumMyElements() * RowSize,
1329 LinearMap.NumGlobalElements() * RowSize, H5T_NATIVE_INT, X->
Values());
1337 if (!IsContained(GroupName))
1339 "requested group " + GroupName +
" not found"));
1342 Read(GroupName,
"__type__", Label);
1344 if (Label !=
"EpetraExt::DistArray<int>")
1346 "requested group " + GroupName +
" is not an EpetraExt::DistArray<int>",
1347 "__type__ = " + Label));
1349 Read(GroupName,
"GlobalLength", GlobalLength);
1350 Read(GroupName,
"RowSize", RowSize);
1360 if (x.Map().LinearMap())
1362 Write(GroupName,
"Values", x.Map().NumMyElements() * x.
RowSize(),
1363 x.Map().NumGlobalElements() * x.
RowSize(),
1364 H5T_NATIVE_DOUBLE, x.
Values());
1375 LinearX.Import(x, Importer,
Insert);
1379 H5T_NATIVE_DOUBLE, LinearX.Values());
1382 Write(GroupName,
"__type__",
"EpetraExt::DistArray<double>");
1384 Write(GroupName,
"RowSize", x.
RowSize());
1392 int GlobalLength, RowSize;
1393 ReadDoubleDistArrayProperties(GroupName, GlobalLength, RowSize);
1399 Read(GroupName,
"Values", Map.NumMyElements() * RowSize,
1400 Map.NumGlobalElements() * RowSize, H5T_NATIVE_DOUBLE, X->
Values());
1409 Read(GroupName,
"Values", LinearMap.
NumMyElements() * RowSize,
1411 H5T_NATIVE_DOUBLE, LinearX.Values());
1415 X->Import(LinearX, Importer,
Insert);
1423 int GlobalLength, RowSize;
1424 ReadDoubleDistArrayProperties(GroupName, GlobalLength, RowSize);
1427 Epetra_Map LinearMap(GlobalLength, 0, Comm_);
1430 Read(GroupName,
"Values", LinearMap.NumMyElements() * RowSize,
1431 LinearMap.NumGlobalElements() * RowSize, H5T_NATIVE_DOUBLE, X->
Values());
1439 if (!IsContained(GroupName))
1441 "requested group " + GroupName +
" not found"));
1444 Read(GroupName,
"__type__", Label);
1446 if (Label !=
"EpetraExt::DistArray<double>")
1448 "requested group " + GroupName +
" is not an EpetraExt::DistArray<double>",
1449 "__type__ = " + Label));
1451 Read(GroupName,
"GlobalLength", GlobalLength);
1452 Read(GroupName,
"RowSize", RowSize);
1463 if (!IsContained(GroupName))
1464 CreateGroup(GroupName);
1466 hid_t filespace_id = H5Screate(H5S_SCALAR);
1467 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1468 hid_t dset_id = H5Dcreate(group_id, DataSetName.c_str(), H5T_NATIVE_INT,
1469 filespace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1471 herr_t status = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, filespace_id,
1472 H5P_DEFAULT, &what);
1478 H5Sclose(filespace_id);
1485 if (!IsContained(GroupName))
1486 CreateGroup(GroupName);
1488 hid_t filespace_id = H5Screate(H5S_SCALAR);
1489 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1490 hid_t dset_id = H5Dcreate(group_id, DataSetName.c_str(), H5T_NATIVE_DOUBLE,
1491 filespace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1493 herr_t status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL,
1494 filespace_id, H5P_DEFAULT, &what);
1500 H5Sclose(filespace_id);
1506 if (!IsContained(GroupName))
1508 "requested group " + GroupName +
" not found"));
1511 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1513 hid_t filespace_id = H5Screate(H5S_SCALAR);
1514 hid_t dset_id = H5Dopen(group_id, DataSetName.c_str(), H5P_DEFAULT);
1516 herr_t status = H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, filespace_id,
1517 H5P_DEFAULT, &data);
1520 H5Sclose(filespace_id);
1528 if (!IsContained(GroupName))
1530 "requested group " + GroupName +
" not found"));
1533 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1535 hid_t filespace_id = H5Screate(H5S_SCALAR);
1536 hid_t dset_id = H5Dopen(group_id, DataSetName.c_str(), H5P_DEFAULT);
1538 herr_t status = H5Dread(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, filespace_id,
1539 H5P_DEFAULT, &data);
1542 H5Sclose(filespace_id);
1549 const std::string& DataSetName,
1550 const std::string& data)
1552 if (!IsContained(GroupName))
1553 CreateGroup(GroupName);
1557 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1559 hid_t dataspace_id = H5Screate_simple(1, &len, NULL);
1561 hid_t atype = H5Tcopy(H5T_C_S1);
1562 H5Tset_size(atype, data.size() + 1);
1564 hid_t dataset_id = H5Dcreate(group_id, DataSetName.c_str(), atype,
1565 dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1566 CHECK_STATUS(H5Dwrite(dataset_id, atype, H5S_ALL, H5S_ALL,
1567 H5P_DEFAULT, data.c_str()));
1580 const std::string& DataSetName,
1583 if (!IsContained(GroupName))
1585 "requested group " + GroupName +
" not found"));
1587 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1589 hid_t dataset_id = H5Dopen(group_id, DataSetName.c_str(), H5P_DEFAULT);
1591 hid_t datatype_id = H5Dget_type(dataset_id);
1593 H5T_class_t typeclass_id = H5Tget_class(datatype_id);
1595 if(typeclass_id != H5T_STRING)
1597 "requested group " + GroupName +
" is not a std::string"));
1599 CHECK_STATUS(H5Dread(dataset_id, datatype_id, H5S_ALL, H5S_ALL,
1600 H5P_DEFAULT, data2));
1603 H5Dclose(dataset_id);
1613 const hid_t type,
const int Length,
1616 if (!IsContained(GroupName))
1617 CreateGroup(GroupName);
1619 hsize_t dimsf = Length;
1621 hid_t filespace_id = H5Screate_simple(1, &dimsf, NULL);
1623 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1625 hid_t dset_id = H5Dcreate(group_id, DataSetName.c_str(), type,
1626 filespace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1628 herr_t status = H5Dwrite(dset_id, type, H5S_ALL, H5S_ALL,
1635 H5Sclose(filespace_id);
1640 const hid_t type,
const int Length,
1643 if (!IsContained(GroupName))
1645 "requested group " + GroupName +
" not found"));
1647 hsize_t dimsf = Length;
1649 hid_t filespace_id = H5Screate_simple(1, &dimsf, NULL);
1651 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1653 hid_t dset_id = H5Dopen(group_id, DataSetName.c_str(), H5P_DEFAULT);
1655 herr_t status = H5Dread(dset_id, type, H5S_ALL, filespace_id,
1662 H5Sclose(filespace_id);
1671 int MySize,
int GlobalSize, hid_t type,
const void* data)
1674 Comm_.ScanSum(&MySize, &Offset, 1);
1677 hsize_t MySize_t = MySize;
1678 hsize_t GlobalSize_t = GlobalSize;
1679 hsize_t Offset_t = Offset;
1681 hid_t filespace_id = H5Screate_simple(1, &GlobalSize_t, NULL);
1684 if (!IsContained(GroupName))
1685 CreateGroup(GroupName);
1687 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1688 hid_t dset_id = H5Dcreate(group_id, DataSetName.c_str(), type, filespace_id,
1689 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1691 H5Sclose(filespace_id);
1696 hid_t memspace_id = H5Screate_simple(1, &MySize_t, NULL);
1699 filespace_id = H5Dget_space(dset_id);
1700 H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET, &Offset_t, NULL, &MySize_t, NULL);
1702 plist_id_ = H5Pcreate(H5P_DATASET_XFER);
1704 H5Pset_dxpl_mpio(plist_id_, H5FD_MPIO_COLLECTIVE);
1707 status = H5Dwrite(dset_id, type, memspace_id, filespace_id,
1714 H5Sclose(filespace_id);
1715 H5Sclose(memspace_id);
1716 H5Pclose(plist_id_);
1721 int MySize,
int GlobalSize,
1722 const hid_t type,
void* data)
1725 throw(
Exception(__FILE__, __LINE__,
"no file open yet"));
1727 hsize_t MySize_t = MySize;
1731 Comm_.ScanSum(&MySize, &itmp, 1);
1732 hsize_t Offset_t = itmp - MySize;
1734 hid_t group_id = H5Gopen(file_id_, GroupName.c_str(), H5P_DEFAULT);
1735 hid_t dataset_id = H5Dopen(group_id, DataSetName.c_str(), H5P_DEFAULT);
1739 hid_t filespace_id = H5Dget_space(dataset_id);
1740 H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET, &Offset_t, NULL,
1743 hid_t mem_dataspace = H5Screate_simple (1, &MySize_t, NULL);
1745 herr_t status = H5Dread(dataset_id, type, mem_dataspace, filespace_id,
1749 H5Sclose(mem_dataspace);
1752 H5Dclose(dataset_id);
void ReadDoubleDistArrayProperties(const std::string &GroupName, int &GlobalLength, int &RowSize)
Read the global number of elements and type for a generic handle object.
int NumGlobalElements() const
int NumGlobalRows() const
void Write(const std::string &GroupName, const std::string &DataSetName, int data)
Write an integer in group GroupName using the given DataSetName.
int InsertGlobalIndices(int numRows, const int *rows, int numCols, const int *cols)
virtual const Epetra_Map & RowMatrixRowMap() const =0
virtual double NormOne() const =0
int MyGlobalElements(int *MyGlobalElementList) const
int GlobalLength() const
Returns the global length of the array.
void ReadMapProperties(const std::string &GroupName, int &NumGlobalElements, int &IndexBase, int &NumProc)
Read basic properties of specified Epetra_Map.
static void WriteParameterListRecursive(const Teuchos::ParameterList ¶ms, hid_t group_id)
bool IsContained(std::string Name, std::string GroupName="")
Return true if Name is contained in the database.
void Read(const std::string &GroupName, const std::string &DataSetName, int &data)
Read an integer from group /GroupName/DataSetName.
virtual int NumGlobalNonzeros() const =0
int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
int NumMyElements() const
virtual int MaxNumEntries() const =0
int NumGlobalCols() const
T * Values()
Returns a pointer to the internally stored data (non-const version).
void ReadBlockMapProperties(const std::string &GroupName, int &NumGlobalElements, int &NumGlobalPoints, int &IndexBase, int &NumProc)
Read basic properties of specified Epetra_BlockMap.
void ReadIntVectorProperties(const std::string &GroupName, int &GlobalLength)
Read basic properties of specified Epetra_IntVector.
void ReadCrsGraphProperties(const std::string &GroupName, int &NumGlobalRows, int &NumGlobalCols, int &NumGlobalNonzeros, int &NumGlobalDiagonals, int &MaxNumIndices)
Read basic properties of specified Epetra_CrsGraph.
virtual double NormInf() const =0
virtual int NumMyRows() const =0
int GlobalAssemble(bool callFillComplete=true, Epetra_CombineMode combineMode=Add, bool save_off_and_reuse_map_exporter=false)
int GCID(int LCID_in) const
int * ElementSizeList() const
virtual bool Filled() const =0
int NumGlobalNonzeros() const
virtual int NumGlobalDiagonals() const =0
virtual int NumGlobalCols() const =0
int RowSize() const
Returns the row size, that is, the amount of data associated with each element.
int ExtractMyRowView(int LocalRow, int &NumIndices, int *&Indices) const
void Open(const std::string FileName, int AccessType=H5F_ACC_RDWR)
Open specified file with given access type.
#define CHECK_STATUS(status)
int GRID(int LRID_in) const
static herr_t f_operator(hid_t loc_id, const char *name, void *opdata)
int MaxNumIndices() const
HDF5(const Epetra_Comm &Comm)
Constructor.
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const =0
void Create(const std::string FileName)
Create a new file.
virtual const Epetra_Map & RowMatrixColMap() const =0
int NumGlobalPoints() const
void ReadIntDistArrayProperties(const std::string &GroupName, int &GlobalLength, int &RowSize)
Read the global number of elements and type for a generic handle object.
void ReadCrsMatrixProperties(const std::string &GroupName, int &NumGlobalRows, int &NumGlobalCols, int &NumNonzeros, int &NumGlobalDiagonals, int &MaxNumEntries, double &NormOne, double &NormInf)
Read basic properties of specified Epetra_CrsMatrix.
static herr_t FindDataset(hid_t loc_id, const char *name, void *opdata)
int NumMyNonzeros() const
virtual int NumGlobalRows() const =0
void ReadMultiVectorProperties(const std::string &GroupName, int &GlobalLength, int &NumVectors)
Read basic properties of specified Epetra_MultiVector.
virtual int NumMyNonzeros() const =0
std::string toString(const int &x)
int NumGlobalDiagonals() const
DistArray<T>: A class to store row-oriented multivectors of type T.