EpetraExt Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_HDF5.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 
42 #ifndef EPETRAEXT_HDF5_H
43 #define EPETRAEXT_HDF5_H
44 
45 #include "EpetraExt_ConfigDefs.h"
46 #ifdef HAVE_EPETRAEXT_HDF5
47 
48 #include <string>
49 #include "hdf5.h"
50 class Epetra_Map;
51 class Epetra_BlockMap;
52 class Epetra_Comm;
53 class Epetra_IntVector;
54 class Epetra_MultiVector;
55 class Epetra_CrsGraph;
56 class Epetra_RowMatrix;
57 class Epetra_CrsMatrix;
58 class Epetra_VbrMatrix;
59 namespace Teuchos {
60  class ParameterList;
61 }
62 namespace EpetraExt {
63  class Handle;
64  template<class T>
65  class DistArray;
66 }
67 
68 namespace EpetraExt
69 {
326 class HDF5
327 {
328  public:
329  // @{ \name Constructor and destructor.
330 
332  HDF5(const Epetra_Comm& Comm);
333 
335  ~HDF5()
336  {
337  if (IsOpen())
338  Close();
339  }
340 
341  // @}
342  // @{ \name Basic operations
343 
345  void Create(const std::string FileName);
346 
348  void Open(const std::string FileName, int AccessType = H5F_ACC_RDWR);
349 
351  void Close()
352  {
353  H5Fclose(file_id_);
354  IsOpen_ = false;
355  }
356 
358  void Flush()
359  {
360  H5Fflush(file_id_, H5F_SCOPE_GLOBAL);
361  }
362 
364  bool IsOpen() const
365  {
366  return(IsOpen_);
367  }
368 
370  void CreateGroup(const std::string& GroupName)
371  {
372  hid_t group_id = H5Gcreate(file_id_, GroupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
373  H5Gclose(group_id);
374  }
375 
377  bool IsContained(std::string Name, std::string GroupName = "");
378 
379  // @}
380  // @{ \name basic non-distributed data types
381 
383  void Write(const std::string& GroupName, const std::string& DataSetName, int data);
384 
386  void Read(const std::string& GroupName, const std::string& DataSetName, int& data);
387 
389  void Write(const std::string& GroupName, const std::string& DataSetName, double data);
390 
392  void Read(const std::string& GroupName, const std::string& DataSetName, double& data);
393 
395  void Write(const std::string& GroupName, const std::string& DataSetName, const std::string& data);
396 
398  void Read(const std::string& GroupName, const std::string& DataSetName, std::string& data);
399 
401  void Read(const std::string& GroupName, const std::string& DataSetName,
402  const hid_t type, const int Length, void* data);
403 
405  void Write(const std::string& GroupName, const std::string& DataSetName,
406  const hid_t type, const int Length,
407  const void* data);
408 
410  void WriteComment(const std::string& GroupName, std::string Comment)
411  {
412  H5Gset_comment(file_id_, GroupName.c_str(), Comment.c_str());
413  }
414 
416  void ReadComment(const std::string& GroupName, std::string& Comment)
417  {
418  char comment[128];
419  H5Gget_comment(file_id_, GroupName.c_str(), 128, comment);
420  Comment = comment;
421  }
422 
423  // @}
424  // @{ \name Distributed arrays
425 
427  void Write(const std::string& GroupName, const std::string& DataSetName, int MySize, int GlobalSize, hid_t type, const void* data);
428 
430  void Read(const std::string& GroupName, const std::string& DataSetName,
431  int MySize, int GlobalSize,
432  const hid_t type, void* data);
433 
434  // @}
435  // @{ \name Epetra_Map/Epetra_BlockMap
436 
438  void Write(const std::string& GroupName, const Epetra_Map& Map);
439 
441  void Read(const std::string& GroupName, Epetra_Map*& Map);
442 
444  void ReadMapProperties(const std::string& GroupName,
445  int& NumGlobalElements,
446  int& IndexBase,
447  int& NumProc);
448 
450  void Read(const std::string& GroupName, Epetra_BlockMap*& Map);
451 
453  void Write(const std::string& GroupName, const Epetra_BlockMap& Map);
454 
456  void ReadBlockMapProperties(const std::string& GroupName,
457  int& NumGlobalElements,
458  int& NumGlobalPoints,
459  int& IndexBase,
460  int& NumProc);
461 
462  // @}
463  // @{ \name Epetra_CrsGraph
464 
466  void Read(const std::string& GroupName, Epetra_CrsGraph*& Graph);
467 
469  void Read(const std::string& GroupName, const Epetra_Map& DomainMap,
470  const Epetra_Map& RangeMap, Epetra_CrsGraph*& Graph);
471 
473  void Write(const std::string& GroupName, const Epetra_CrsGraph& Graph);
474 
476  void ReadCrsGraphProperties(const std::string& GroupName,
477  int& NumGlobalRows,
478  int& NumGlobalCols,
479  int& NumGlobalNonzeros,
480  int& NumGlobalDiagonals,
481  int& MaxNumIndices);
482 
483  // @}
484  // @{ \name Epetra_IntVector
485 
487  void Write(const std::string& GroupName, const Epetra_IntVector& x);
488 
490  void Read(const std::string& GroupName, Epetra_IntVector*& X);
491 
493  void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_IntVector*& X);
494 
496  void ReadIntVectorProperties(const std::string& GroupName, int& GlobalLength);
497 
498  // @}
499  // @{ \name Epetra_MultiVector
500 
504  void Write(const std::string& GroupName, const Epetra_MultiVector& x, bool writeTranspose = false);
505 
510  void Read(const std::string& GroupName, Epetra_MultiVector*& X,
511  bool writeTranspose = false, const int& indexBase = 0);
512 
516  void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_MultiVector*& X,
517  bool writeTranspose = false);
518 
520  void ReadMultiVectorProperties(const std::string& GroupName,
521  int& GlobalLength,
522  int& NumVectors);
523 
524  // @}
525  // @{ \name Epetra_RowMatrix/Epetra_CrsMatrix
526 
528  void Write(const std::string& GroupName, const Epetra_RowMatrix& Matrix);
529 
531  void Read(const std::string& GroupName, Epetra_CrsMatrix*& A);
532 
534  void Read(const std::string& GroupName,
535  const Epetra_Map& DomainMap,
536  const Epetra_Map& RangeMap,
537  Epetra_CrsMatrix*& A);
538 
540  void ReadCrsMatrixProperties(const std::string& GroupName,
541  int& NumGlobalRows,
542  int& NumGlobalCols,
543  int& NumNonzeros,
544  int& NumGlobalDiagonals,
545  int& MaxNumEntries,
546  double& NormOne,
547  double& NormInf);
548 
549  // @}
550  // @{ \name Teuchos::ParameterList
551 
553  void Write(const std::string& GroupName, const Teuchos::ParameterList& List);
554 
556  void Read(const std::string& GroupName, Teuchos::ParameterList& List);
557 
558  // @}
559  // @{ \name EpetraExt::DistArray<int>
560 
562  void Write(const std::string& GroupName, const DistArray<int>& array);
563 
565  void Read(const std::string& GroupName, DistArray<int>*& array);
566 
568  void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<int>*& array);
569 
571  void ReadIntDistArrayProperties(const std::string& GroupName,
572  int& GlobalLength,
573  int& RowSize);
574 
575  // @}
576  // @{ \name EpetraExt::DistArray<double>
577 
579  void Write(const std::string& GroupName, const DistArray<double>& array);
580 
582  void Read(const std::string& GroupName, DistArray<double>*& array);
583 
585  void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<double>*& array);
586 
588  void ReadDoubleDistArrayProperties(const std::string& GroupName,
589  int& GlobalLength,
590  int& RowSize);
591  // @}
592  // @}
593  // @{ \name Generic distributed object
594 
596  void Write(const std::string& GroupName, const Handle& List);
597 
599  void Read(const std::string& GroupName, Handle& List);
600 
602  void ReadHandleProperties(const std::string& GroupName,
603  std::string& Type,
604  int& NumGlobalElements);
605 
606  // @}
607  private:
608  // @{ \name Private Data
609 
611  const Epetra_Comm& Comm() const
612  {
613  return(Comm_);
614  }
615 
619  std::string FileName_;
621  bool IsOpen_;
622 
624  hid_t file_id_;
625  hid_t plist_id_;
626  herr_t status;
627 
628  // @}
629 };
630 }
631 #endif
632 #endif /* EPETRAEXT_HDF5_H */
void ReadDoubleDistArrayProperties(const std::string &GroupName, int &GlobalLength, int &RowSize)
Read the global number of elements and type for a generic handle object.
void Write(const std::string &GroupName, const std::string &DataSetName, int data)
Write an integer in group GroupName using the given DataSetName.
void ReadHandleProperties(const std::string &GroupName, std::string &Type, int &NumGlobalElements)
Read the global number of elements and type for a generic handle object.
void ReadComment(const std::string &GroupName, std::string &Comment)
Read the string associated with group GroupName.
void ReadMapProperties(const std::string &GroupName, int &NumGlobalElements, int &IndexBase, int &NumProc)
Read basic properties of specified Epetra_Map.
void CreateGroup(const std::string &GroupName)
Create group GroupName.
bool IsContained(std::string Name, std::string GroupName="")
Return true if Name is contained in the database.
bool IsOpen() const
Return true if a file has already been opened using Open()/Create()
void Read(const std::string &GroupName, const std::string &DataSetName, int &data)
Read an integer from group /GroupName/DataSetName.
void WriteComment(const std::string &GroupName, std::string Comment)
Associate string Comment with group GroupName.
const Epetra_Comm & Comm() const
Returns a reference to this object&#39;s communicator.
~HDF5()
Destructor.
const Epetra_Comm & Comm_
This object&#39;s communicator.
void ReadBlockMapProperties(const std::string &GroupName, int &NumGlobalElements, int &NumGlobalPoints, int &IndexBase, int &NumProc)
Read basic properties of specified Epetra_BlockMap.
void Flush()
Flush the content to the file.
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.
std::string FileName_
FileName currently open.
bool IsOpen_
If true, a file is currently open.
void Open(const std::string FileName, int AccessType=H5F_ACC_RDWR)
Open specified file with given access type.
class HDF5: A class for storing Epetra objects in parallel binary files
HDF5(const Epetra_Comm &Comm)
Constructor.
hid_t file_id_
file ID for HDF5.
void Close()
Close the file.
void Create(const std::string FileName)
Create a new file.
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.
void ReadMultiVectorProperties(const std::string &GroupName, int &GlobalLength, int &NumVectors)
Read basic properties of specified Epetra_MultiVector.
DistArray&lt;T&gt;: A class to store row-oriented multivectors of type T.