45 #ifdef HAVE_EPETRAEXT_HDF5 
   47 #include "Epetra_MpiComm.h" 
   50 #include "Epetra_SerialComm.h" 
   52 #include "Teuchos_ParameterList.hpp" 
   53 #include "Epetra_BlockMap.h" 
   54 #include "Epetra_DistObject.h" 
   60 #define CHECK_HID(hid_t) \ 
   62     throw(EpetraExt::Exception(__FILE__, __LINE__, \ 
   63                     "hid_t is negative")); } 
   65 #define CHECK_STATUS(status) \ 
   67     throw(EpetraExt::Exception(__FILE__, __LINE__, \ 
   68                     "function H5Giterater returned a negative value")); } 
   81   std::vector<std::string> IntLabels, DoubleLabels;
 
   82   std::vector<int> IntLabelsData;
 
   83   std::vector<double> DoubleLabelsData;
 
   85   obj.
GetLabels(IntLabels, IntLabelsData, DoubleLabels, DoubleLabelsData);
 
   89   for (
unsigned int i = 0; i < IntLabels.size(); ++i)
 
   90     Write(GroupName, IntLabels[i], IntLabelsData[i]);
 
   92   for (
unsigned int i = 0; i < DoubleLabels.size(); ++i)
 
   93     Write(GroupName, DoubleLabels[i], DoubleLabelsData[i]);
 
   99   std::vector<int> IntSize(NumMyElements);
 
  100   std::vector<int> DoubleSize(NumMyElements);
 
  102   int TotalIntSize = 0, TotalDoubleSize = 0;
 
  104   std::vector<int> IntData;
 
  105   std::vector<double> DoubleData;
 
  107   for (
int i = 0; i < NumMyElements; ++i)
 
  111     TotalIntSize += IntSize[i];
 
  112     TotalDoubleSize += DoubleSize[i];
 
  115   IntData.resize(TotalIntSize);
 
  116   DoubleData.resize(TotalDoubleSize);
 
  125   for (
int i = 0; i < NumMyElements; ++i)
 
  127     obj.
Pack(i, &IntData[IntCount], &DoubleData[DoubleCount]);
 
  128     IntCount += IntSize[i];
 
  129     DoubleCount += DoubleSize[i];
 
  135   Write(GroupName, 
"__type__", obj.
Type());
 
  136   Write(GroupName, 
"NumGlobalElements", NumGlobalElements);
 
  142     Write(GroupName, 
"int ptr", NumMyElements, 
 
  143           NumGlobalElements, H5T_NATIVE_INT, &IntSize[0]);
 
  144     Write(GroupName, 
"int data", NumMyElements, 
 
  145           NumGlobalElements, H5T_NATIVE_INT, &IntData[0]);
 
  150     Write(GroupName, 
"double ptr", NumMyElements, 
 
  151           NumGlobalElements, H5T_NATIVE_INT, &DoubleSize[0]);
 
  152     Write(GroupName, 
"double data", NumMyElements, 
 
  153           NumGlobalElements, H5T_NATIVE_DOUBLE, &DoubleData[0]);
 
  163   std::vector<std::string> IntLabels, DoubleLabels;
 
  166   std::vector<int> IntLabelsData(IntLabels.size());
 
  167   std::vector<double> DoubleLabelsData(DoubleLabels.size());
 
  169   for (
unsigned int i = 0; i < IntLabels.size(); ++i)
 
  170     Read(GroupName, IntLabels[i], IntLabelsData[i]);
 
  172   for (
unsigned int i = 0; i < DoubleLabels.size(); ++i)
 
  173     Read(GroupName, DoubleLabels[i], DoubleLabelsData[i]);
 
  175   std::vector<int> IntSize(NumMyElements);
 
  176   std::vector<int> DoubleSize(NumMyElements);
 
  178   int TotalIntSize = 0, TotalDoubleSize = 0;
 
  179   int GrandTotalIntSize = 0, GrandTotalDoubleSize = 0;
 
  184     Read(GroupName, 
"int ptr", NumMyElements, 
 
  185          NumGlobalElements, H5T_NATIVE_INT, &IntSize[0]);
 
  186     for (
int i = 0; i < NumMyElements; ++i)
 
  187       TotalIntSize += IntSize[i];
 
  188     Comm().SumAll(&TotalIntSize, &GrandTotalIntSize, 1);
 
  193     Read(GroupName, 
"double ptr", NumMyElements, 
 
  194          NumGlobalElements, H5T_NATIVE_INT, &DoubleSize[0]);
 
  195     for (
int i = 0; i < NumMyElements; ++i)
 
  197       TotalDoubleSize += DoubleSize[i];
 
  199     Comm().SumAll(&TotalDoubleSize, &GrandTotalDoubleSize, 1);
 
  202   std::vector<int> IntData(TotalIntSize + 1);
 
  203   std::vector<double> DoubleData(TotalDoubleSize + 1);
 
  207     Read(GroupName, 
"int data", TotalIntSize, 
 
  208          GrandTotalIntSize, H5T_NATIVE_INT, &IntData[0]);
 
  210     Read(GroupName, 
"double data", TotalDoubleSize, 
 
  211          GrandTotalDoubleSize, H5T_NATIVE_DOUBLE, &DoubleData[0]);
 
  216   obj.
SetLabels(IntLabelsData, DoubleLabelsData);
 
  218   int IntCount = 0, DoubleCount = 0;
 
  219   for (
int i = 0; i < NumMyElements; ++i)
 
  221     obj.
UnPack(i, IntSize[i], &(IntData[IntCount]),
 
  222                DoubleSize[i], &(DoubleData[DoubleCount]));
 
  223     IntCount += IntSize[i];
 
  224     DoubleCount += DoubleSize[i];
 
  233                                            int& NumGlobalElements)
 
  235   if (!IsContained(GroupName))
 
  237                     "requested group " + GroupName + 
" not found"));
 
  239   Read(GroupName, 
"__type__", Type);
 
  241   Read(GroupName, 
"NumGlobalElements", NumGlobalElements);
 
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. 
 
virtual int GetLabels(std::vector< std::string > &IntLabels, std::vector< std::string > &DoubleLabels) const =0
Packs all global information. 
 
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. 
 
void Read(const std::string &GroupName, const std::string &DataSetName, int &data)
Read an integer from group /GroupName/DataSetName. 
 
virtual int NumMyElements() const =0
Returns the local number of elements. 
 
virtual int Finalize()=0
Performs any finalization procedure after unpacking. 
 
virtual int UnPack(const int EID, int IntSize, int *IntData, int DoubleSize, double *DoubleData)=0
Unpacks all data for local element EID in the specified arrays. 
 
virtual bool HasDouble() const =0
 
virtual int IntSize(const int EID) const =0
Returns the size of integer data for local element EID. 
 
virtual int DoubleSize(const int EID) const =0
Returns the size of double data for local element EID. 
 
virtual int Initialize()=0
Performs any initialization procedure before unpacking. 
 
virtual int SetLabels(const std::vector< int > &IntLabelsData, const std::vector< double > &DoubleLabelsData)=0
Sets global information. 
 
virtual int NumGlobalElements() const =0
Returns the global number of elements. 
 
virtual int Pack(const int EID, int *IntData, double *DoubleData) const =0
Packs all data for local element EID in the specified arrays. 
 
virtual std::string Type() const =0
Returns the identifier of the distributed object. 
 
virtual bool HasInt() const =0