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 #if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS)
46 #ifdef __GNUC__
47 #warning "The EpetraExt package is deprecated"
48 #endif
49 #endif
50 
51 #include "EpetraExt_ConfigDefs.h"
52 #ifdef HAVE_EPETRAEXT_HDF5
53 
54 #include <string>
55 #include "hdf5.h"
56 class Epetra_Map;
57 class Epetra_BlockMap;
58 class Epetra_Comm;
59 class Epetra_IntVector;
60 class Epetra_MultiVector;
61 class Epetra_CrsGraph;
62 class Epetra_RowMatrix;
63 class Epetra_CrsMatrix;
64 class Epetra_VbrMatrix;
65 namespace Teuchos {
66  class ParameterList;
67 }
68 namespace EpetraExt {
69  class Handle;
70  template<class T>
71  class DistArray;
72 }
73 
74 namespace EpetraExt
75 {
332 class HDF5
333 {
334  public:
335  // @{ \name Constructor and destructor.
336 
338  HDF5(const Epetra_Comm& Comm);
339 
341  ~HDF5()
342  {
343  if (IsOpen())
344  Close();
345  }
346 
347  // @}
348  // @{ \name Basic operations
349 
351  void Create(const std::string FileName);
352 
354  void Open(const std::string FileName, int AccessType = H5F_ACC_RDWR);
355 
357  void Close()
358  {
359  H5Fclose(file_id_);
360  IsOpen_ = false;
361  }
362 
364  void Flush()
365  {
366  H5Fflush(file_id_, H5F_SCOPE_GLOBAL);
367  }
368 
370  bool IsOpen() const
371  {
372  return(IsOpen_);
373  }
374 
376  void CreateGroup(const std::string& GroupName)
377  {
378  hid_t group_id = H5Gcreate(file_id_, GroupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
379  H5Gclose(group_id);
380  }
381 
383  bool IsContained(std::string Name, std::string GroupName = "");
384 
385  // @}
386  // @{ \name basic non-distributed data types
387 
389  void Write(const std::string& GroupName, const std::string& DataSetName, int data);
390 
392  void Read(const std::string& GroupName, const std::string& DataSetName, int& data);
393 
395  void Write(const std::string& GroupName, const std::string& DataSetName, double data);
396 
398  void Read(const std::string& GroupName, const std::string& DataSetName, double& data);
399 
401  void Write(const std::string& GroupName, const std::string& DataSetName, const std::string& data);
402 
404  void Read(const std::string& GroupName, const std::string& DataSetName, std::string& data);
405 
407  void Read(const std::string& GroupName, const std::string& DataSetName,
408  const hid_t type, const int Length, void* data);
409 
411  void Write(const std::string& GroupName, const std::string& DataSetName,
412  const hid_t type, const int Length,
413  const void* data);
414 
416  void WriteComment(const std::string& GroupName, std::string Comment)
417  {
418  H5Gset_comment(file_id_, GroupName.c_str(), Comment.c_str());
419  }
420 
422  void ReadComment(const std::string& GroupName, std::string& Comment)
423  {
424  char comment[128];
425  H5Gget_comment(file_id_, GroupName.c_str(), 128, comment);
426  Comment = comment;
427  }
428 
429  // @}
430  // @{ \name Distributed arrays
431 
433  void Write(const std::string& GroupName, const std::string& DataSetName, int MySize, int GlobalSize, hid_t type, const void* data);
434 
436  void Read(const std::string& GroupName, const std::string& DataSetName,
437  int MySize, int GlobalSize,
438  const hid_t type, void* data);
439 
440  // @}
441  // @{ \name Epetra_Map/Epetra_BlockMap
442 
444  void Write(const std::string& GroupName, const Epetra_Map& Map);
445 
447  void Read(const std::string& GroupName, Epetra_Map*& Map);
448 
450  void ReadMapProperties(const std::string& GroupName,
451  int& NumGlobalElements,
452  int& IndexBase,
453  int& NumProc);
454 
456  void Read(const std::string& GroupName, Epetra_BlockMap*& Map);
457 
459  void Write(const std::string& GroupName, const Epetra_BlockMap& Map);
460 
462  void ReadBlockMapProperties(const std::string& GroupName,
463  int& NumGlobalElements,
464  int& NumGlobalPoints,
465  int& IndexBase,
466  int& NumProc);
467 
468  // @}
469  // @{ \name Epetra_CrsGraph
470 
472  void Read(const std::string& GroupName, Epetra_CrsGraph*& Graph);
473 
475  void Read(const std::string& GroupName, const Epetra_Map& DomainMap,
476  const Epetra_Map& RangeMap, Epetra_CrsGraph*& Graph);
477 
479  void Write(const std::string& GroupName, const Epetra_CrsGraph& Graph);
480 
482  void ReadCrsGraphProperties(const std::string& GroupName,
483  int& NumGlobalRows,
484  int& NumGlobalCols,
485  int& NumGlobalNonzeros,
486  int& NumGlobalDiagonals,
487  int& MaxNumIndices);
488 
489  // @}
490  // @{ \name Epetra_IntVector
491 
493  void Write(const std::string& GroupName, const Epetra_IntVector& x);
494 
496  void Read(const std::string& GroupName, Epetra_IntVector*& X);
497 
499  void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_IntVector*& X);
500 
502  void ReadIntVectorProperties(const std::string& GroupName, int& GlobalLength);
503 
504  // @}
505  // @{ \name Epetra_MultiVector
506 
510  void Write(const std::string& GroupName, const Epetra_MultiVector& x, bool writeTranspose = false);
511 
516  void Read(const std::string& GroupName, Epetra_MultiVector*& X,
517  bool writeTranspose = false, const int& indexBase = 0);
518 
522  void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_MultiVector*& X,
523  bool writeTranspose = false);
524 
526  void ReadMultiVectorProperties(const std::string& GroupName,
527  int& GlobalLength,
528  int& NumVectors);
529 
530  // @}
531  // @{ \name Epetra_RowMatrix/Epetra_CrsMatrix
532 
534  void Write(const std::string& GroupName, const Epetra_RowMatrix& Matrix);
535 
537  void Read(const std::string& GroupName, Epetra_CrsMatrix*& A);
538 
540  void Read(const std::string& GroupName,
541  const Epetra_Map& DomainMap,
542  const Epetra_Map& RangeMap,
543  Epetra_CrsMatrix*& A);
544 
546  void ReadCrsMatrixProperties(const std::string& GroupName,
547  int& NumGlobalRows,
548  int& NumGlobalCols,
549  int& NumNonzeros,
550  int& NumGlobalDiagonals,
551  int& MaxNumEntries,
552  double& NormOne,
553  double& NormInf);
554 
555  // @}
556  // @{ \name Teuchos::ParameterList
557 
559  void Write(const std::string& GroupName, const Teuchos::ParameterList& List);
560 
562  void Read(const std::string& GroupName, Teuchos::ParameterList& List);
563 
564  // @}
565  // @{ \name EpetraExt::DistArray<int>
566 
568  void Write(const std::string& GroupName, const DistArray<int>& array);
569 
571  void Read(const std::string& GroupName, DistArray<int>*& array);
572 
574  void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<int>*& array);
575 
577  void ReadIntDistArrayProperties(const std::string& GroupName,
578  int& GlobalLength,
579  int& RowSize);
580 
581  // @}
582  // @{ \name EpetraExt::DistArray<double>
583 
585  void Write(const std::string& GroupName, const DistArray<double>& array);
586 
588  void Read(const std::string& GroupName, DistArray<double>*& array);
589 
591  void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<double>*& array);
592 
594  void ReadDoubleDistArrayProperties(const std::string& GroupName,
595  int& GlobalLength,
596  int& RowSize);
597  // @}
598  // @}
599  // @{ \name Generic distributed object
600 
602  void Write(const std::string& GroupName, const Handle& List);
603 
605  void Read(const std::string& GroupName, Handle& List);
606 
608  void ReadHandleProperties(const std::string& GroupName,
609  std::string& Type,
610  int& NumGlobalElements);
611 
612  // @}
613  private:
614  // @{ \name Private Data
615 
617  const Epetra_Comm& Comm() const
618  {
619  return(Comm_);
620  }
621 
625  std::string FileName_;
627  bool IsOpen_;
628 
630  hid_t file_id_;
631  hid_t plist_id_;
632  herr_t status;
633 
634  // @}
635 };
636 }
637 #endif
638 #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.