Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 0bb85290 authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

Update in API in order to remove memory leaks (changes added to FChebInterpolator too.)

parent 0b6ed9f6
......@@ -465,7 +465,7 @@ void scalfmm_execute_fmm(scalfmm_handle Handle);
* The last param cellDestroyer is meaningless in case the user uses
* one of the provided kernel. (i.e. Chebyshev, Lagrange)
*/
void Scalfmm_dealloc_handle(scalfmm_handle handle, Callback_free_cell cellDestroyer);
void scalfmm_dealloc_handle(scalfmm_handle handle, Callback_free_cell cellDestroyer);
#endif
......@@ -24,9 +24,10 @@
#include "FScalFMMEngine.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "Kernels/P2P/FP2PLeafInterface.hpp"
//#include "Kernels/P2P/FP2PLeafInterface.hpp"
#include "Arranger/FOctreeArranger.hpp"
#include "Arranger/FArrangerPeriodic.hpp"
#include "Arranger/FBasicParticleContainerIndexedMover.hpp"
#include "Core/FFmmAlgorithmThread.hpp"
#include "Core/FFmmAlgorithm.hpp"
......@@ -45,12 +46,14 @@ class FInterEngine : public FScalFMMEngine{
private:
//Typedef on the octree class, in order to clarify following code
typedef FOctree<InterCell,ContainerClass,LeafClass> OctreeClass;
typedef FP2PLeafInterface<OctreeClass> LeafInterface;
//typedef FP2PLeafInterface<OctreeClass> LeafInterface;
//Typedef on Octree Arranger, in order to clarify following code
typedef FOctreeArranger<OctreeClass,ContainerClass,LeafInterface> ArrangerClass;
typedef FArrangerPeriodic<OctreeClass,ContainerClass,LeafInterface> ArrangerClassPeriodic;
typedef FBasicParticleContainerIndexedMover<OctreeClass, ContainerClass> MoverClass;
typedef FOctreeArranger<OctreeClass, ContainerClass, MoverClass> ArrangerClass;
typedef FArrangerPeriodic<OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
//Pointer to the kernel to be executed
InterKernel * kernel;
MatrixKernelClass * matrix;
......@@ -78,8 +81,12 @@ public:
//TODO free kernel too
~FInterEngine(){
free(octree);
free(kernel);
delete matrix;
delete octree;
delete kernel;
if(arranger){
delete arranger;
}
}
//Inserting array of position
......@@ -528,7 +535,6 @@ public:
void execute_fmm(){
//typedef FOctree<InterCell,ContainerClass,LeafClass> OctreeClass;
switch(Algorithm){
case 0:
{
......@@ -557,7 +563,9 @@ public:
}
}
void intern_dealloc_handle(Callback_free_cell unUsed){
//this->~FInterEngine();
}
};
......
......@@ -51,11 +51,16 @@ protected:
scalfmm_kernel_type kernelType;
scalfmm_algorithm Algorithm;
FVector<bool> progress;
FVector<bool>* progress;
int nbPart;
public:
FScalFMMEngine() : Algorithm(multi_thread), progress(), nbPart(0){
FScalFMMEngine() : Algorithm(multi_thread), progress(nullptr), nbPart(0){
progress = new FVector<bool>();
}
virtual ~FScalFMMEngine() {
delete progress;
}
//First function displayed there are common function for every
......@@ -208,6 +213,10 @@ public:
FAssertLF(0,"No kernel set, cannot execute anything, exiting ...\n");
}
virtual void intern_dealloc_handle(Callback_free_cell userDeallocator){
FAssertLF(0,"No kernel set, cannot execute anything, exiting ...\n");
}
};
......@@ -378,6 +387,10 @@ extern "C" void scalfmm_execute_fmm(scalfmm_handle Handle){
((ScalFmmCoreHandle * ) Handle)->engine->execute_fmm();
}
extern "C" void scalfmm_user_kernel_config(scalfmm_handle Handle, Scalfmm_Kernel_Descriptor userKernel, void * userDatas){
((ScalFmmCoreHandle * ) Handle)->engine->user_kernel_config(userKernel,userDatas);
}
extern "C" void scalfmm_init_cell(scalfmm_handle Handle, Callback_init_cell user_cell_initializer){
((ScalFmmCoreHandle * ) Handle)->engine->init_cell(user_cell_initializer);
}
......@@ -386,5 +399,8 @@ extern "C" void scalfmm_free_cell(scalfmm_handle Handle, Callback_free_cell user
((ScalFmmCoreHandle * ) Handle)->engine->free_cell(user_cell_deallocator);
}
// extern "C" void scalfmm_intern_dealloc_handle(scalfmm_handle Handle,Callback_free_cell userDeallocator){
// ((ScalFmmCoreHandle * ) Handle)->engine->intern_dealloc_handle(userDeallocator);
// }
#endif
#ifndef CALL_HPP
#define CALL_HPP
/** It should be compiled with C export */
extern "C" {
#include "CScalfmmApi.h"
......@@ -15,7 +11,7 @@ extern "C" scalfmm_handle scalfmm_init(int TreeHeight,double BoxWidth,double* Bo
switch(KernelType){
case 0:
//handle->engine = new FUserKernelEngine(...);
handle->engine = new FUserKernelEngine(TreeHeight, BoxWidth, BoxCenter, KernelType);
std::cout<< "User Kernel type unsupported yet" << std::endl;
break;
......@@ -48,5 +44,8 @@ extern "C" scalfmm_handle scalfmm_init(int TreeHeight,double BoxWidth,double* Bo
return handle;
}
#endif
extern "C" void scalfmm_dealloc_handle(scalfmm_handle handle, Callback_free_cell userDeallocator){
((ScalFmmCoreHandle *) handle)->engine->intern_dealloc_handle(userDeallocator);
delete ((ScalFmmCoreHandle *) handle)->engine ;
delete (ScalFmmCoreHandle *) handle;
}
......@@ -153,10 +153,11 @@ private:
typedef FSimpleLeaf<ContainerClass> LeafClass;
typedef FOctree<CoreCell,ContainerClass,LeafClass> OctreeClass;
typedef CoreKernel<CoreCell,ContainerClass> CoreKernelClass;
typedef FP2PLeafInterface<OctreeClass> LeafInterface;
//For arranger classes
typedef FOctreeArranger<OctreeClass,ContainerClass,LeafInterface> ArrangerClass;
typedef FArrangerPeriodic<OctreeClass,ContainerClass,LeafInterface> ArrangerClassPeriodic;
typedef FBasicParticleContainerIndexedMover<OctreeClass, ContainerClass> MoverClass;
typedef FOctreeArranger<OctreeClass, ContainerClass, MoverClass> ArrangerClass;
typedef FArrangerPeriodic<OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
//Attributes
......@@ -171,13 +172,24 @@ public:
kernelType = KernelType;
//Kernel is not set now because the user must provide a
//Scalfmm_Kernel_descriptor
//kernel = new CoreKernelClass();
}
~FUserKernelEngine(){
delete octree;
if(arranger){
delete arranger;
}
if(kernel){
delete kernel;
}
}
void user_kernel_config( Scalfmm_Kernel_Descriptor userKernel, void * userDatas){
if(!kernel){
kernel = new CoreKernelClass(userKernel,userDatas);
}
}
void tree_insert_particles( int NbPositions, double * arrayX, double * arrayY, double * arrayZ){
......@@ -226,11 +238,11 @@ public:
}
void execute_fmm(){
//FAssertLF(kernel,"No kernel set, please use scalfmm_user_kernel_config before calling the execute routine ... Exiting \n");
FAssertLF(kernel,"No kernel set, please use scalfmm_user_kernel_config before calling the execute routine ... Exiting \n");
switch(Algorithm){
case 0:
{
typedef FFmmAlgorithm<OctreeClass,CoreCell,ContainerClass,CoreKernelClass,LeafInterface> AlgoClassSeq;
typedef FFmmAlgorithm<OctreeClass,CoreCell,ContainerClass,CoreKernelClass,LeafClass> AlgoClassSeq;
AlgoClassSeq algoSeq(octree,kernel);
algoSeq.execute();
break;
......@@ -255,7 +267,10 @@ public:
}
}
void intern_dealloc_handle(Callback_free_cell userDeallocator){
free_cell(userDeallocator);
this->~FUserKernelEngine();
}
};
......
......@@ -23,7 +23,7 @@ int main(int argc, char ** av){
scalfmm_kernel_type myChoice = chebyshev;
//Octree configuration
int TreeHeight = 5;
int TreeHeight = 7;
double boxWidth = 2.0;
double boxCenter[3] = {0.0,0.0,0.0};
......@@ -56,7 +56,7 @@ int main(int argc, char ** av){
//Computation Part
int nb_iteration = 100;
int nb_iteration = 10;//atoi(av[1]);
int curr_iteration = 0;
//Array to store the output
......@@ -112,13 +112,16 @@ int main(int argc, char ** av){
curr_iteration++;
}
//End of Computation, useer get the position after a hundreds of iterations
//Free memory
free(positionsXYZ);
free(array_of_charge);
free(array_of_forces);
free(array_of_pot);
free(array_of_displacement);
//End of Computation, useer get the position after some iterations
scalfmm_dealloc_handle(handle,NULL);
return 0;
}
......@@ -236,10 +236,10 @@ int main(int argc, char ** argv){
scalfmm_handle handle = scalfmm_init(treeHeight, boxWidth, boxCenter,user_defined_kernel);
// Insert particles
printf("Inserting particles...\n");
Scalfmm_insert_array_of_particles(handle, nbParticles, particleIndexes, particleXYZ);
scalfmm_tree_insert_particles_xyz(handle, nbParticles, particleXYZ);
// Init cell
printf("Initizalizing the cells:\n");
Scalfmm_init_cell(handle, my_Callback_init_cell);
scalfmm_init_cell(handle, my_Callback_init_cell);
// Init our callback struct
struct User_Scalfmm_Kernel_Descriptor kernel;
......@@ -255,9 +255,11 @@ int main(int argc, char ** argv){
struct MyData my_data;
memset(&my_data, 0, sizeof(struct MyData));
my_data.insertedPositions = particleXYZ;
//Set my datas before calling fmm (this will set as well the kernel)
scalfmm_user_kernel_config(handle,kernel,&my_data);
// Execute the FMM
Scalfmm_execute_kernel(handle, kernel, &my_data);
scalfmm_execute_fmm(handle/*, kernel, &my_data*/);
// Print the results store in our callback
printf("There was %d P2M\n", my_data.countP2M);
......@@ -268,8 +270,10 @@ int main(int argc, char ** argv){
printf("There was %d P2PInner\n", my_data.countP2PInner);
printf("There was %d P2P\n", my_data.countP2P);
//Dealloc the cells
scalfmm_free_cell(handle,my_Callback_free_cell);
// Dealloc the handle
Scalfmm_dealloc_handle(handle,my_Callback_free_cell);
scalfmm_dealloc_handle(handle,my_Callback_free_cell);
return 0;
}
......@@ -420,11 +420,16 @@ public:
*/
~FChebInterpolator()
{
for (unsigned int l=0; l<static_cast<unsigned int>(TreeHeight); ++l)
for (unsigned int child=0; child<8; ++child)
if(ChildParentInterpolator[l][child] != nullptr)
for (unsigned int l=0; l<static_cast<unsigned int>(TreeHeight); ++l){
for (unsigned int child=0; child<8; ++child){
if(ChildParentInterpolator[l][child] != nullptr){
delete [] ChildParentInterpolator[l][child];
}
}
delete[] ChildParentInterpolator[l];
}
delete[] ChildParentInterpolator;
}
/**
......
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