From: apo Date: Mon, 4 Dec 2006 06:49:10 +0000 (+0000) Subject: To implement more accurate memory size calculation X-Git-Tag: WP1_2_3_05-12-2006_cache_system~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98f45e2cf662fc14d84ea0b47d44c130e3ae2144;p=modules%2Fvisu.git To implement more accurate memory size calculation --- diff --git a/src/CONVERTOR/VISUConvertor.cxx b/src/CONVERTOR/VISUConvertor.cxx index 60ce6567..b5814d6a 100644 --- a/src/CONVERTOR/VISUConvertor.cxx +++ b/src/CONVERTOR/VISUConvertor.cxx @@ -91,8 +91,8 @@ void parseFile(const char* theFileName) if(anEntity != VISU::NODE_ENTITY){ VISU::PGaussPtsIDMapper aGaussMesh = aCon->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp); - VISU::TVTKOutput* aDataSet = aGaussMesh->GetVTKOutput(); /* + VISU::TVTKOutput* aDataSet = aGaussMesh->GetVTKOutput(); int aNbCells = aDataSet->GetNumberOfCells(); for(int anCellId = 0; anCellId < aNbCells; anCellId++){ VISU::TGaussPointID anObjID = aGaussMesh->GetObjID(anCellId); @@ -102,8 +102,8 @@ void parseFile(const char* theFileName) }else{ VISU::PIDMapper anIDMapper = aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); - VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); /* + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); int aNbCells = aDataSet->GetNumberOfCells(); for(int anCellId = 0; anCellId < aNbCells; anCellId++){ int anObjID = anIDMapper->GetElemObjID(anCellId); @@ -132,9 +132,9 @@ void parseFile(const char* theFileName) for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; VISU::PIDMapper anIDMapper = aCon->GetMeshOnEntity(aMeshName,anEntity); - VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); { /* + VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); int aNbCells, anCellId, anObjID, aVTKID; aNbCells = aDataSet->GetNumberOfCells(); for(anCellId = 0; anCellId < aNbCells; anCellId++){ diff --git a/src/CONVERTOR/VISU_Convertor.hxx b/src/CONVERTOR/VISU_Convertor.hxx index 286a81a1..2a819f89 100644 --- a/src/CONVERTOR/VISU_Convertor.hxx +++ b/src/CONVERTOR/VISU_Convertor.hxx @@ -365,13 +365,21 @@ public: const std::string& theFieldName, int theStampsNum) = 0; - //! Get amount of memory to build mesh for corresponding MED TIMESTAMP + //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on mesh virtual size_t - GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) = 0; + GetTimeStampOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; + + //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on Gauss Points + virtual + size_t + GetTimeStampOnGaussPtsSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) = 0; //! Get amount of memory to build all MED TIMESTAMPS for corresponding MED FIELD virtual diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 067ec8cb..4bfe9a5b 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -67,6 +67,37 @@ static int MYDEBUGWITHFILES = 0; namespace VISU { + //--------------------------------------------------------------- + /*! Computes number of points by the given number of cells + * in assumption of regular hexahedral mesh structure + */ + size_t + GetNumberofPoints(size_t theNbCells) + { + return size_t(pow(pow(theNbCells, 1.0/3.0) + 1.0, 3.0)); + } + + //--------------------------------------------------------------- + /*! Computes size dataset the given number of mesh macro metrics + * in assumption of regular hexahedral mesh structure + */ + size_t + GetDataSetSize(size_t theNbOfPoints, + size_t theNbOfCells, + size_t theCellsSize, + bool theComputeLinks) + { + size_t aPointsSize = 3*theNbOfPoints*sizeof(VISU::TCoord); + size_t aConnectivityAndTypesSize = theCellsSize*sizeof(vtkIdType); + size_t aLocationsSize = theNbOfCells*sizeof(int); + vtkFloatingPointType aNbCellsPerPoint = theCellsSize / theNbOfCells - 1; + size_t aLinksSize = theNbOfPoints * (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short)); + if(!theComputeLinks) + aLinksSize = 0; + size_t aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize; + return aResult; + } + //--------------------------------------------------------------- TIsVTKDone::TIsVTKDone(): myIsVTKDone(false), @@ -103,6 +134,35 @@ namespace VISU return GetSource().GetPointer(); } + unsigned long int + TSource + ::GetMemorySize() + { + if(TVTKOutput* anOutput = GetVTKOutput()){ + anOutput->Update(); + return GetVTKOutput()->GetActualMemorySize() * 1024; + } + if(myIsDone){ + size_t aNbPoints = GetNumberofPoints(myNbCells); + return GetDataSetSize(aNbPoints, myNbCells, myCellsSize, false); + } + throw std::runtime_error("TSource::GetMemorySize - myIsDone == false !!!"); + return 0; + } + + //--------------------------------------------------------------- + unsigned long int + TMemoryCheckIDMapper + ::GetMemorySize() + { + if(myIsVTKDone){ + GetVTKOutput()->Update(); + return GetVTKOutput()->GetActualMemorySize() * 1024; + }else + throw std::runtime_error("TMemoryCheckIDMapper::GetMemorySize - myIsVTKDone == false !!!"); + return 0; + } + //--------------------------------------------------------------- TAppendFilter::TAppendFilter() @@ -128,7 +188,6 @@ namespace VISU return GetFilter()->GetOutput(); } - //--------------------------------------------------------------- TMergeFilter::TMergeFilter() {} @@ -152,7 +211,6 @@ namespace VISU return GetFilter()->GetUnstructuredGridOutput(); } - //--------------------------------------------------------------- TPointCoords ::TPointCoords(): @@ -186,6 +244,15 @@ namespace VISU return TCoordSlice(myCoord,std::slice(theNodeId*myDim,myDim,1)); } + unsigned long int + TPointCoords + ::GetMemorySize() + { + size_t aSize = sizeof(TCoord) * myCoord.size(); + aSize += myPoints->GetActualMemorySize() * 1024; + return aSize; + } + //--------------------------------------------------------------- void @@ -271,6 +338,15 @@ namespace VISU return theID; } + unsigned long int + TSubProfileImpl + ::GetMemorySize() + { + size_t aSize = TSource::GetMemorySize(); + aSize += sizeof(vtkIdType) * mySubMeshID.size(); + return aSize; + } + //--------------------------------------------------------------- bool @@ -369,6 +445,18 @@ namespace VISU return anAppendFilter->GetOutput(); } + unsigned long int + TProfileImpl + ::GetMemorySize() + { + size_t aSize = TAppendFilter::GetMemorySize(); + aSize += myNamedPointCoords->GetMemorySize(); + aSize += myElemObj2VTKID.size() * 2 * sizeof(vtkIdType); + for(size_t anId = 0; anId < mySubProfileArr.size(); anId++) + aSize += mySubProfileArr[anId]->GetMemorySize(); + return aSize; + } + std::string TProfileImpl ::GetNodeName(vtkIdType theObjID) const @@ -415,6 +503,15 @@ namespace VISU return myFilter->GetUnstructuredGridOutput(); } + unsigned long int + TIDMapperFilter + ::GetMemorySize() + { + size_t aSize = myIDMapper->GetMemorySize(); + aSize += mySource.GetMemorySize(); + return aSize; + } + vtkIdType TIDMapperFilter ::GetNodeObjID(vtkIdType theID) const @@ -484,6 +581,15 @@ namespace VISU return TGaussPointID(aCellID,aLocalPntID); } + unsigned long int + TGaussSubMeshImpl + ::GetMemorySize() + { + size_t aSize = TSource::GetMemorySize(); + aSize += myPointCoords.GetMemorySize(); + return aSize; + } + //--------------------------------------------------------------- bool operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight) @@ -530,6 +636,17 @@ namespace VISU return mySource.GetVTKOutput(); } + unsigned long int + TGaussMeshImpl + ::GetMemorySize() + { + size_t aSize = TAppendFilter::GetMemorySize(); + aSize += mySource.GetMemorySize(); + for(size_t anId = 0; anId < myGaussSubMeshArr.size(); anId++) + aSize += myGaussSubMeshArr[anId]->GetMemorySize(); + return aSize; + } + TNamedIDMapper* TGaussMeshImpl:: GetParent() @@ -569,6 +686,18 @@ namespace VISU return ""; } + unsigned long int + TSubMeshImpl + ::GetMemorySize() + { + size_t aSize = TSource::GetMemorySize(); + for(size_t anId = 0; anId < myCell2Connect.size(); anId++){ + const TConnect& aConnect = myCell2Connect[anId]; + aSize += aConnect.size() * sizeof(vtkIdType); + } + return aSize; + } + //--------------------------------------------------------------- vtkIdType TMeshOnEntityImpl @@ -628,6 +757,20 @@ namespace VISU return aSubMesh->GetElemName(anInputID); } + unsigned long int + TMeshOnEntityImpl + ::GetMemorySize() + { + size_t aSize = TAppendFilter::GetMemorySize(); + aSize += myNamedPointCoords->GetMemorySize(); + aSize += myElemObj2VTKID.size() * 2 * sizeof(vtkIdType); + for(size_t anId = 0; anId < mySubMeshArr.size(); anId++){ + const PSubMeshImpl& aSubMesh = mySubMeshArr[anId]; + aSize += aSubMesh->GetMemorySize(); + } + return aSize; + } + //--------------------------------------------------------------- vtkIdType TFamilyImpl @@ -671,6 +814,24 @@ namespace VISU return TSource::GetVTKOutput(); } + unsigned long int + TFamilyImpl + ::GetMemorySize() + { + size_t aSize = TSource::GetMemorySize(); + aSize += myNamedPointCoords->GetMemorySize(); + aSize += myElemObj2VTKID.size() * 2 * sizeof(vtkIdType); + aSize += myMeshID.size() * sizeof(vtkIdType); + TGeom2SubMeshID::const_iterator anIter = myGeom2SubMeshID.begin(); + TGeom2SubMeshID::const_iterator anIterEnd = myGeom2SubMeshID.end(); + for(; anIter != anIterEnd; anIter++){ + const TSubMeshID& aSubMeshID = anIter->second; + aSize += aSubMeshID.size() * sizeof(vtkIdType); + aSize += sizeof(EGeometry); + } + return aSize; + } + //--------------------------------------------------------------- TNbASizeCells @@ -726,6 +887,21 @@ namespace VISU return myNamedPointCoords->GetVTKID(theID); } + unsigned long int + TGroupImpl + ::GetMemorySize() + { + size_t aSize = TAppendFilter::GetMemorySize(); + aSize += myNamedPointCoords->GetMemorySize(); + aSize += myElemObj2VTKID.size() * 2 * sizeof(vtkIdType); + for(size_t anId = 0; anId < myFamilyArr.size(); anId++){ + const PFamilyImpl& aFamily = myFamilyArr[anId]; + aSize += aFamily->GetMemorySize(); + } + return aSize; + } + + //--------------------------------------------------------------- TFieldImpl @@ -828,6 +1004,15 @@ namespace VISU return aValueSliceArr; } + unsigned long int + TMeshValue + ::GetMemorySize() const + { + size_t aSize = sizeof(TMeshValue); + aSize += myValue.size() * sizeof(vtkFloatingPointType); + return aSize; + } + //--------------------------------------------------------------- TValForTimeImpl @@ -865,6 +1050,22 @@ namespace VISU return anIter->second; } + unsigned long int + TValForTimeImpl + ::GetMemorySize() + { + size_t aSize = sizeof(TValForTimeImpl); + TGeom2Value::const_iterator anIter = myGeom2Value.begin(); + TGeom2Value::const_iterator anIterEnd = myGeom2Value.end(); + for(; anIter != anIterEnd; anIter++){ + const TMeshValue& aMeshValue = anIter->second; + aSize += aMeshValue.GetMemorySize(); + aSize += sizeof(EGeometry); + } + return aSize; + } + + //--------------------------------------------------------------- vtkIdType @@ -2397,7 +2598,7 @@ VISU_Convertor_impl size_t aLinksSize = aMesh->myNbPoints * (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); aLinksSize = 0; - vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + size_t aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; MSG(MYDEBUG,"GetMeshOnEntitySize "<< "- aResult = "<myNbPoints * (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); aLinksSize = 0; - vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + size_t aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; MSG(MYDEBUG,"GetFamilyOnEntitySize "<< "- aResult = "<myNbPoints * (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short)); aLinksSize = 0; - vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize; + size_t aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize; if(MYDEBUG){ MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aPointsSize = "<(aFindTimeStamp); PFieldImpl aField = boost::get<3>(aFindTimeStamp); - size_t aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity); + size_t aMeshSize = GetMeshOnEntitySize(theMeshName, aVTKMeshOnEntity->myEntity); size_t aTimeStampSize = size_t(aField->myDataSize*sizeof(vtkFloatingPointType) * ERR_SIZE_CALC); size_t aResult = aMeshSize + aTimeStampSize; @@ -2624,6 +2825,70 @@ VISU_Convertor_impl } +size_t +VISU_Convertor_impl +::GetTimeStampOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) +{ + size_t aSize = 0; + + //Cheching possibility do the query + TFindTimeStamp aFindTimeStamp = FindTimeStamp(theMeshName, + theEntity, + theFieldName, + theStampsNum); + + PValForTimeImpl aValForTime = boost::get<4>(aFindTimeStamp); + PIDMapperFilter anIDMapperFilter = aValForTime->myIDMapperFilter; + if(anIDMapperFilter->myIsVTKDone){ + VISU::PIDMapper anIDMapper = GetTimeStampOnMesh(theMeshName, + theEntity, + theFieldName, + theStampsNum); + anIDMapper->GetVTKOutput(); + aSize += anIDMapper->GetMemorySize(); + }else + aSize += GetTimeStampSize(theMeshName, theEntity, theFieldName, theStampsNum); + + cout<<"VISU_Convertor_impl::GetTimeStampOnMeshSize - "<myIsVTKDone)<(aFindTimeStamp); + PGaussPtsIDFilter aGaussPtsIDFilter = aValForTime->myGaussPtsIDFilter; + if(aGaussPtsIDFilter->myIsVTKDone){ + VISU::PGaussPtsIDMapper aGaussPtsIDMapper = GetTimeStampOnGaussPts(theMeshName, + theEntity, + theFieldName, + theStampsNum); + aGaussPtsIDMapper->GetVTKOutput(); + aSize += aGaussPtsIDMapper->GetMemorySize(); + }else + aSize += GetTimeStampSize(theMeshName, theEntity, theFieldName, theStampsNum); + + cout<<"VISU_Convertor_impl::GetTimeStampOnGaussPtsSize - "<myIsVTKDone)< PPointCoords; @@ -232,7 +252,7 @@ namespace VISU protected: typedef TVector TPointsDim; TPointsDim myPointsDim; //!< Keeps name of each dimension - TVectorID myVectorID; //!< Keeps object¶ numeration + TVectorID myVectorID; //!< Keeps object¶ numeration TObj2VTKID myObj2VTKID; //!< Keeps mapping from object number to VTK one public: @@ -302,6 +322,11 @@ namespace VISU vtkIdType GetElemObjID(int theVtkI) const; + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize(); + //! Keeps status of the structure /*! In some cases MED file does not use MED PROFILES, but at VISU creates corresponding data strucutre @@ -362,6 +387,11 @@ namespace VISU TVTKOutput* GetVTKOutput(); + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize(); + //! Reimplement the TNamedIDMapper::GetNodeName virtual std::string @@ -377,7 +407,6 @@ namespace VISU PNamedPointCoords myNamedPointCoords; //!< Keeps reference on the same TNamedPointCoords as TMesh TMeshOnEntityImpl* myMeshOnEntity; // PProfileImpl; @@ -424,6 +453,11 @@ namespace VISU virtual TVTKOutput* GetVTKOutput(); + + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize(); }; typedef SharedPtr PIDMapperFilter; @@ -460,6 +494,11 @@ namespace VISU GetObjID(vtkIdType theID, vtkIdType theStartID) const; + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize(); + PGaussImpl myGauss; // PValForTimeImpl; } @@ -864,13 +938,21 @@ public: const std::string& theFieldName, int theStampsNum); - //! Implemention of the VISU_Convertor::GetTimeStampSize + //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on mesh virtual - size_t - GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum); + size_t + GetTimeStampOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum); + + //! Get amount of memory to build vtkDataSet for corresponding MED TIMESTAMP on Gauss Points + virtual + size_t + GetTimeStampOnGaussPtsSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum); //! Implemention of the VISU_Convertor::GetTimeStampOnGaussPts virtual @@ -958,6 +1040,14 @@ protected: const VISU::TEntity& theEntity); protected: + //! Implemention of the VISU_Convertor::GetTimeStampSize + virtual + size_t + GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum); + //! To fill intermeiate representation of TMeshOnEntity from a MED source virtual int diff --git a/src/CONVERTOR/VISU_IDMapper.hxx b/src/CONVERTOR/VISU_IDMapper.hxx index a488a210..9614bc82 100644 --- a/src/CONVERTOR/VISU_IDMapper.hxx +++ b/src/CONVERTOR/VISU_IDMapper.hxx @@ -100,6 +100,11 @@ namespace VISU virtual TVTKOutput* GetVTKOutput() = 0; + + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize() = 0; }; typedef SharedPtr PIDMapper; diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index be9dbf29..b7e5202e 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -418,8 +418,9 @@ unsigned long int VISU_Actor ::GetMemorySize() { + static vtkFloatingPointType ERR_SIZE_CALC = 1.00; vtkDataSet* aDataSet = GetMapper()->GetInput(); - unsigned long int aSize = aDataSet->GetActualMemorySize() * 1024; + unsigned long int aSize = size_t(aDataSet->GetActualMemorySize() * 1024 * ERR_SIZE_CALC); aDataSet = myGeomFilter->GetOutput(); aSize += aDataSet->GetActualMemorySize() * 1024; diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index b1b2042f..2341f209 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -67,10 +67,10 @@ VISU::GaussPoints_i size_t aResult = VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theTimeStampNumber,false); if(theIsMemoryCheck && aResult){ VISU::Result_i::TInput* anInput = theResult->GetInput(); - size_t aSize = anInput->GetTimeStampSize(theMeshName, - (VISU::TEntity)theEntity, - theFieldName, - theTimeStampNumber); + size_t aSize = anInput->GetTimeStampOnGaussPtsSize(theMeshName, + (VISU::TEntity)theEntity, + theFieldName, + theTimeStampNumber); aSize *= INCMEMORY; aResult = VISU_PipeLine::CheckAvailableMemory(aSize); if(MYDEBUG) @@ -258,6 +258,25 @@ VISU::GaussPoints_i } } +//---------------------------------------------------------------------------- +CORBA::Float +VISU::GaussPoints_i +::GetMemorySize() +{ + CORBA::Float aMemorySize = TSuperClass::GetMemorySize(); + + // To calculate memory used by VISU Converter + VISU::Result_i::TInput* anInput = GetCResult()->GetInput(); + CORBA::Float aSize = anInput->GetTimeStampOnGaussPtsSize(GetCMeshName(), + GetTEntity(), + GetCFieldName(), + GetTimeStampNumber()); + // Convert to mega bytes + aMemorySize += aSize / (1024.0 * 1024.0); + cout<<"GaussPoints_i::GetMemorySize - "<