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