67 int main (
int argc,
char **argv)
70 MPI_Init(&argc, &argv);
94 List.
set(
"bool type",
true);
95 List.
set(
"int type", 2);
96 List.
set(
"double type", 3.0);
97 List.
set(
"std::string type",
"a std::string");
109 if (Comm.
MyPID() == 0)
110 std::cout <<
"Writing objects to HDF5 file myfile.h5..." << std::endl << std::endl;
115 HDF5.
Write(
"matrix", Matrix);
120 HDF5.
Write(
"matrix",
"integration order", 1);
121 HDF5.
Write(
"matrix",
"numerical drop", 0.1);
122 HDF5.
Write(
"matrix",
"package name",
"EpetraExt");
123 HDF5.
Write(
"matrix",
"author",
"Marzio Sala");
124 HDF5.
Write(
"matrix",
"institution",
"ETHZ/D-INFK");
126 HDF5.
Write(
"my parameters",
"latitude", 12);
127 HDF5.
Write(
"my parameters",
"longitude", 67);
130 HDF5.
Write(
"List", List);
133 std::vector<int> iarray(3);
134 iarray[0] = 0, iarray[1] = 1; iarray[2] = 2;
135 HDF5.
Write(
"my parameters",
"int array", H5T_NATIVE_INT, 3, &iarray[0]);
137 std::vector<double> darray(3);
138 darray[0] = 0.1, darray[1] = 1.1; darray[2] = 2.1;
139 HDF5.
Write(
"my parameters",
"double array", H5T_NATIVE_DOUBLE, 3, &darray[0]);
148 if (Comm.
MyPID() == 0)
149 std::cout <<
"Reading objects from HDF5 file myfile.h5..." << std::endl << std::endl;
160 HDF5.
Read(
"matrix", *NewMap, *NewMap, NewMatrix);
165 HDF5.
Read(
"matrix",
"NumGlobalRows", NumGlobalRows);
166 NewMap =
new Epetra_Map(NumGlobalRows, 0, Comm);
167 HDF5.
Read(
"matrix", *NewMap, *NewMap, NewMatrix);
172 int NewNumGlobalNonzeros;
173 HDF5.
Read(
"matrix",
"NumGlobalNonzeros", NewNumGlobalNonzeros);
178 HDF5.
Read(
"x", NewX);
179 HDF5.
Read(
"b", NewB);
182 int new_latitude, new_longitude;
183 std::vector<int> new_iarray(3);
184 std::vector<double> new_darray(3);
185 HDF5.
Read(
"my parameters",
"latitude", new_latitude);
186 HDF5.
Read(
"my parameters",
"longitude", new_longitude);
187 HDF5.
Read(
"my parameters",
"int array", H5T_NATIVE_INT, 3, &new_iarray[0]);
188 HDF5.
Read(
"my parameters",
"double array", H5T_NATIVE_DOUBLE, 3, &new_darray[0]);
191 std::string PackageName;
192 HDF5.
Read(
"matrix",
"package name", PackageName);
195 HDF5.
Read(
"List", newList);
196 if (Comm.
MyPID() == 0)
198 std::cout <<
"New list as read from file is:" << std::endl;
199 std::cout <<
"bool type = " << newList.
get(
"bool type",
false) << std::endl;
200 std::cout <<
"int type = " << newList.
get(
"int type", -1) << std::endl;
201 std::cout <<
"double type = " << newList.
get(
"double type", -1.0) << std::endl;
202 std::cout <<
"std::string type = " << newList.
get(
"std::string type",
"not-set") << std::endl;
203 std::cout << std::endl;
205 std::cout <<
"Checking some read and written data..." << std::endl;
206 for (
int i = 0; i < 3; ++i) {
207 std::cout <<
"iarray[" << i <<
"] = " << iarray[i] <<
" should be " << new_iarray[i] << std::endl;
208 if(iarray[i] != new_iarray[i]) {
209 std::cout <<
"Test failed." << std::endl;
214 for (
int i = 0; i < 3; ++i) {
215 std::cout <<
"darray[" << i <<
"] = " << darray[i] <<
" should be " << new_darray[i] << std::endl;
216 if(darray[i] != new_darray[i]) {
217 std::cout <<
"Test failed." << std::endl;
222 std::cout << std::endl;
223 std::cout <<
"Try to print out the content of myfile.h5 using the command" << std::endl;
224 std::cout <<
" h5dump myfile.h5" << std::endl;
233 if (NewMap )
delete NewMap;
234 if (NewMatrix)
delete NewMatrix;
235 if (NewX )
delete NewX;
236 if (NewB )
delete NewB;
245 std::cerr <<
"Caught generic std::exception" << std::endl;
253 return(EXIT_SUCCESS);
void Write(const std::string &GroupName, const std::string &DataSetName, int data)
Write an integer in group GroupName using the given DataSetName.
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
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.
int FillComplete(bool OptimizeDataStorage=true)
int main(int argc, char **argv)
int NumMyElements() const
int NumGlobalNonzeros() const
class HDF5: A class for storing Epetra objects in parallel binary files
void Close()
Close the file.
void Create(const std::string FileName)
Create a new file.
std::string toString(const int &x)