Commit 0a717332 authored by berenger-bramas's avatar berenger-bramas

Memory profiler is now working, an example is on the testMemStats.cpp file.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@273 2616d619-271b-44dc-8df4-d4a8f33a7222
parent ed4964b4
#include "FMemStats.h"
#include "ScalFmmConfig.h"
FMemStats FMemStats::controler;
#include <cstdio>
#ifdef SCALFMM_USE_MEM_STATS
// Regular scalar new
void* operator new(std::size_t n) throw(std::bad_alloc)
......@@ -56,7 +57,7 @@ FMemStats FMemStats::controler;
void operator delete(void* p) throw(){
if(p){
FMemStats::controler.deallocate( *(reinterpret_cast<size_t*>(static_cast<unsigned char*>(p) - 8)) );
free(reinterpret_cast<unsigned char*>(p) - 8);
free(static_cast<unsigned char*>(p) - 8);
}
}
......
......@@ -63,6 +63,18 @@ public:
std::size_t getCurrentAllocated() const{
return currentAllocated;
}
float getMaxAllocatedMB() const{
return float(getMaxAllocated()) / 1024 / 1024;
}
float getTotalAllocatedMB() const{
return float(getTotalAllocated()) / 1024 / 1024;
}
float getCurrentAllocatedMB() const{
return float(getCurrentAllocated()) / 1024 / 1024;
}
};
......
......@@ -32,77 +32,73 @@
// Simply create particles and try the kernels
int main(int argc, char ** argv){
typedef FTestParticle ParticleClass;
typedef FTestCell CellClass;
typedef FVector<ParticleClass> ContainerClass;
{
typedef FTestParticle ParticleClass;
typedef FTestCell CellClass;
typedef FVector<ParticleClass> ContainerClass;
typedef FSimpleLeaf<ParticleClass, ContainerClass > LeafClass;
typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass > OctreeClass;
typedef FTestKernels<ParticleClass, CellClass, ContainerClass > KernelClass;
typedef FSimpleLeaf<ParticleClass, ContainerClass > LeafClass;
typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass > OctreeClass;
typedef FTestKernels<ParticleClass, CellClass, ContainerClass > KernelClass;
typedef FFmmAlgorithm<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
///////////////////////What we do/////////////////////////////
std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
//////////////////////////////////////////////////////////////
typedef FFmmAlgorithm<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
///////////////////////What we do/////////////////////////////
std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
//////////////////////////////////////////////////////////////
const int NbLevels = FParameters::getValue(argc,argv,"-h", 9);
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
const long NbPart = FParameters::getValue(argc,argv,"-nb", 2000000);
const FReal FRandMax = FReal(RAND_MAX);
const int NbLevels = FParameters::getValue(argc,argv,"-h", 9);
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
const long NbPart = FParameters::getValue(argc,argv,"-nb", 2000000);
const FReal FRandMax = FReal(RAND_MAX);
FTic counter;
FTic counter;
srand ( 1 ); // volontary set seed to constant
srand ( 1 ); // volontary set seed to constant
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
OctreeClass tree(NbLevels, SizeSubLevels, 1.0, F3DPosition(0.5,0.5,0.5));
OctreeClass tree(NbLevels, SizeSubLevels, 1.0, F3DPosition(0.5,0.5,0.5));
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
std::cout << "Creating & Inserting " << NbPart << " particles ..." << std::endl;
std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
counter.tic();
std::cout << "Creating & Inserting " << NbPart << " particles ..." << std::endl;
std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
counter.tic();
{
FTestParticle particleToFill;
for(int idxPart = 0 ; idxPart < NbPart ; ++idxPart){
particleToFill.setPosition(FReal(rand())/FRandMax,FReal(rand())/FRandMax,FReal(rand())/FRandMax);
tree.insert(particleToFill);
{
FTestParticle particleToFill;
for(int idxPart = 0 ; idxPart < NbPart ; ++idxPart){
particleToFill.setPosition(FReal(rand())/FRandMax,FReal(rand())/FRandMax,FReal(rand())/FRandMax);
tree.insert(particleToFill);
}
}
}
counter.tac();
std::cout << "Done " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
counter.tac();
std::cout << "Done " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
std::cout << "Working on particles ..." << std::endl;
counter.tic();
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// FTestKernels FBasicKernels
KernelClass kernels;
FmmClass algo(&tree,&kernels);
algo.execute();
std::cout << "Working on particles ..." << std::endl;
counter.tic();
counter.tac();
std::cout << "Done " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;
// FTestKernels FBasicKernels
KernelClass kernels;
FmmClass algo(&tree,&kernels);
algo.execute();
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
ValidateFMMAlgo<OctreeClass, ParticleClass, CellClass, ContainerClass, LeafClass>(&tree);
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
counter.tac();
std::cout << "Done " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
}
std::cout << "Memory used at the end " << FMemStats::controler.getCurrentAllocated() << " Bytes\n";
std::cout << "Max memory used " << FMemStats::controler.getMaxAllocated() << " Bytes\n";
std::cout << "Total memory used " << FMemStats::controler.getTotalAllocated() << " Bytes\n";
std::cout << "Memory used at the end " << FMemStats::controler.getCurrentAllocated() << " Bytes (" << FMemStats::controler.getCurrentAllocatedMB() << "MB)\n";
std::cout << "Max memory used " << FMemStats::controler.getMaxAllocated() << " Bytes (" << FMemStats::controler.getMaxAllocatedMB() << "MB)\n";
std::cout << "Total memory used " << FMemStats::controler.getTotalAllocated() << " Bytes (" << FMemStats::controler.getTotalAllocatedMB() << "MB)\n";
return 0;
}
......
Markdown is supported
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