Commit 4c731155 authored by Jerry Clarke's avatar Jerry Clarke
Browse files

Remove some debugging

Add AllowAllocate method to XdmfArray
Add SetShapeFromSelection to XdmfArray
Change XdmfDataItem so that it only allocated the space it actually needs
Leave Array unchanged in ValuesHDF if possible
parent 9945e0cb
......@@ -206,6 +206,7 @@ Tag << "_" << XDMF_64BIT_CAST GlobalTimeCntr << "_XdmfArray" << ends;
XdmfArray::XdmfArray() {
XdmfDebug("XdmfArray Constructor");
this->AllowAllocate = 1;
this->DataPointer = NULL;
this->HeavyDataSetName = NULL;
this->DataIsMine = 1;
......@@ -283,9 +284,13 @@ return( RetVal );
*/
XdmfInt32 XdmfArray::Allocate( void ){
XdmfDebug("Allocating " <<
XdmfDebug("Request Allocating " <<
XDMF_64BIT_CAST (this->GetNumberOfElements() * this->GetElementSize()) <<
" Bytes");
if(!this->AllowAllocate){
XdmfDebug("AllowAllocate is Off");
return(XDMF_SUCCESS);
}
if( this->DataIsMine ) {
XdmfDebug("Data " << XDMF_64BIT_CAST this->DataPointer << " is Mine");
if( this->DataPointer ) {
......@@ -317,12 +322,54 @@ XdmfInt32 XdmfArray::Reform( XdmfInt32 rank, XdmfInt64 *Dimensions ) {
return( XDMF_SUCCESS );
}
XdmfInt32 XdmfArray::ReformFromSelection( XdmfDataDesc *DataDesc) {
XdmfDebug("Reform from Selection");
if(DataDesc->GetSelectionType() == XDMF_SELECTALL){
return(this->Reform(DataDesc));
}
if( DataDesc->GetSelectionType() == XDMF_HYPERSLAB ){
XdmfInt32 Rank;
XdmfInt64 Start[ XDMF_MAX_DIMENSION ];
XdmfInt64 Stride[ XDMF_MAX_DIMENSION ];
XdmfInt64 Count[ XDMF_MAX_DIMENSION ];
// Select the HyperSlab from HDF5
XdmfDebug("Reform from Hyperslab");
Rank = DataDesc->GetHyperSlab( Start, Stride, Count );
this->Reform(Rank, Count);
this->SelectAll();
} else {
XdmfInt64 NumberOfCoordinates;
XdmfInt64 *Coordinates;
// Select Parametric Coordinates from HDF5
XdmfDebug("Reform from Coordinates");
NumberOfCoordinates = DataDesc->GetSelectionSize();
XdmfDataDesc::SetNumberOfElements(NumberOfCoordinates);
this->SelectAll();
delete Coordinates;
}
return( XDMF_SUCCESS );
}
XdmfInt32 XdmfArray::SetShapeFromSelection( XdmfDataDesc *DataDesc) {
this->ReformFromSelection(DataDesc);
if(this->Allocate() != XDMF_SUCCESS){
return(XDMF_FAIL);
}
return( XDMF_SUCCESS );
}
XdmfInt32 XdmfArray::SetShape( XdmfInt32 rank, XdmfInt64 *Dimensions ) {
XdmfDebug("Setting Shape and Allocating Memory");
XdmfDataDesc::SetShape( rank, Dimensions );
this->Allocate();
if(this->Allocate() != XDMF_SUCCESS){
return(XDMF_FAIL);
}
return( XDMF_SUCCESS );
}
......@@ -330,7 +377,9 @@ XdmfInt32
XdmfArray::CopyShape( hid_t dataSpace ){
XdmfDebug("Setting Shape and Allocating Memory");
XdmfDataDesc::CopyShape( dataSpace );
this->Allocate();
if(this->Allocate() != XDMF_SUCCESS){
return(XDMF_FAIL);
}
return( XDMF_SUCCESS );
}
......@@ -338,7 +387,9 @@ XdmfInt32
XdmfArray::CopyShape( XdmfDataDesc *DataDesc ){
XdmfDebug("Setting Shape and Allocating Memory");
XdmfDataDesc::CopyShape( DataDesc );
this->Allocate();
if(this->Allocate() != XDMF_SUCCESS){
return(XDMF_FAIL);
}
return( XDMF_SUCCESS );
}
......@@ -353,8 +404,9 @@ XdmfInt32 XdmfArray::SetShapeFromString( XdmfConstString Dimensions ) {
XdmfDebug("Setting Shape and Allocating Memory");
XdmfDataDesc::SetShapeFromString( Dimensions );
this->Allocate();
if(this->Allocate() != XDMF_SUCCESS){
return(XDMF_FAIL);
}
return( XDMF_SUCCESS );
}
......
......@@ -64,23 +64,30 @@ public:
XdmfLength GetCoreLength( ) { return ( this->GetElementSize() * this->GetNumberOfElements() ) ; } ;
XdmfInt32 Allocate( void );
//! Allow for automatic allocation of data buffer
XdmfSetValueMacro(AllowAllocate, XdmfBoolean);
XdmfGetValueMacro(AllowAllocate, XdmfBoolean);
//! Overloaded SetShape to Allocate space
XdmfInt32 SetShape( XdmfInt32 Rank, XdmfInt64 *Dimensions );
XdmfInt32 SetShapeFromString( XdmfConstString Dimensions );
XdmfInt32 SetShapeFromSelection( XdmfDataDesc *DataDesc);
XdmfInt32 SetNumberOfElements( XdmfInt64 Length ) {
return( this->SetShape( 1, &Length ) );
};
//! Reshape without changing number of elements
//! Reshape without changing (allocating) number of elements
XdmfInt32 ReformFromString( XdmfConstString Dimensions );
XdmfInt32 ReformFromSelection( XdmfDataDesc *DataDesc);
XdmfInt32 CopyShape( XdmfDataDesc *DataDesc );
#ifndef SWIG
XdmfInt32 Reform( XdmfInt32 Rank, XdmfInt64 *Dimensions );
XdmfInt32 Reform( XdmfDataDesc *DataDesc );
XdmfInt32 CopyShape( hid_t DataSpace );
#endif
XdmfInt32 CopyShape( XdmfDataDesc *DataDesc );
//! Get the undelying data for fast access \b CAUTION !!
XdmfPointer GetDataPointer( XdmfInt64 Index = 0 );
......@@ -411,6 +418,7 @@ public:
protected:
XdmfPointer DataPointer;
XdmfBoolean AllowAllocate;
XdmfBoolean DataIsMine;
char TagName[XDMF_ARRAY_TAG_LENGTH];
......
......@@ -476,13 +476,15 @@ XdmfInt32 XdmfDataItem::Update(){
return(this->UpdateFunction());
}
if(this->Array->CopyType(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
if(this->Array->CopyShape(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
// if(this->Array->CopyShape(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
// if(this->Array->CopySelection(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
if(this->CheckValues(this->Format) != XDMF_SUCCESS){
XdmfErrorMessage("Error Accessing Internal XdmfValues");
return(XDMF_FAIL);
}
if(this->Values->GetDataDesc()->CopySelection(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
XdmfDebug("Resize Array");
if(this->Array->SetShapeFromSelection(this->DataDesc) != XDMF_SUCCESS) return(XDMF_FAIL);
switch (this->Format) {
case XDMF_FORMAT_HDF :
this->Values->SetDebug(this->GetDebug());
......@@ -491,6 +493,7 @@ XdmfInt32 XdmfDataItem::Update(){
#ifndef XDMF_NO_MPI
this->Values->SetDsmBuffer(this->DsmBuffer);
#endif
XdmfDebug("Reading Data");
if(!((XdmfValuesHDF *)this->Values)->Read(this->Array)){
XdmfErrorMessage("Reading Values Failed");
return(XDMF_FAIL);
......
......@@ -89,8 +89,12 @@ XdmfValuesHDF::Read(XdmfArray *anArray){
// Select the HyperSlab from HDF5
Rank = this->DataDesc->GetHyperSlab( Start, Stride, Count );
H5.SelectHyperSlab( Start, Stride, Count );
RetArray->SetShape(Rank, Count);
RetArray->SelectAll();
if(RetArray->GetSelectionSize() < H5.GetSelectionSize()){
XdmfErrorMessage("Return Array No Large Enough to Hold Selected Data");
RetArray->SetShapeFromSelection(&H5);
}
// RetArray->SetShape(Rank, Count);
// RetArray->SelectAll();
} else {
XdmfInt64 NumberOfCoordinates;
XdmfInt64 *Coordinates;
......@@ -104,7 +108,7 @@ XdmfValuesHDF::Read(XdmfArray *anArray){
delete Coordinates;
}
}
XdmfDebug("Reading " << H5.GetSelectionSize() << " into Array of " << RetArray->GetSelectionSize() );
if( H5.Read(RetArray) == NULL ){
XdmfErrorMessage("Can't Read Dataset " << DataSetName);
if(!anArray) delete RetArray;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment