From 1acbddc59b3717be2865f99fcba9d9fb912194bf Mon Sep 17 00:00:00 2001
From: piacibel <cyrille.piacibello@inria.fr>
Date: Tue, 31 Mar 2015 10:04:40 +0200
Subject: [PATCH] Changes relatives to template over FReal type

---
 Addons/CKernelApi/Src/FInterEngine.hpp        | 10 +--
 Addons/CKernelApi/Src/FScalfmmApiInit.cpp     | 62 +++++++++----------
 Addons/CKernelApi/Src/FUserKernelEngine.hpp   |  8 +--
 .../Tests/testUserDefinedKernelApi.c          | 11 ++--
 4 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/Addons/CKernelApi/Src/FInterEngine.hpp b/Addons/CKernelApi/Src/FInterEngine.hpp
index 2a427a859..98493c060 100644
--- a/Addons/CKernelApi/Src/FInterEngine.hpp
+++ b/Addons/CKernelApi/Src/FInterEngine.hpp
@@ -38,21 +38,21 @@
  * @class FInterEngine implements API for Interpolations kernels, its
  * templates can be ChebCell/ChebKernel or UnifCell/UnifKernel
  */
-template<class InterCell,class InterKernel,
+template<class FReal, class InterCell,class InterKernel,
          class ContainerClass = FP2PParticleContainerIndexed<FReal>,
          class LeafClass = FSimpleLeaf<FReal, FP2PParticleContainerIndexed<FReal> >,
-         class MatrixKernelClass = FInterpMatrixKernelR>
+         class MatrixKernelClass = FInterpMatrixKernelR<FReal> >
 class FInterEngine : public FScalFMMEngine{
 private:
     //Typedef on the octree class, in order to clarify following code
-    typedef FOctree<InterCell,ContainerClass,LeafClass> OctreeClass;
+    typedef FOctree<FReal,InterCell,ContainerClass,LeafClass> OctreeClass;
     //typedef FP2PLeafInterface<OctreeClass>            LeafInterface;
 
 
     //Typedef on Octree Arranger, in order to clarify following code
-    typedef FBasicParticleContainerIndexedMover<OctreeClass, ContainerClass> MoverClass;
+    typedef FBasicParticleContainerIndexedMover<FReal,OctreeClass, ContainerClass> MoverClass;
     typedef FOctreeArranger<FReal,OctreeClass, ContainerClass, MoverClass> ArrangerClass;
-    typedef FArrangerPeriodic<OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
+    typedef FArrangerPeriodic<FReal,OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
 
     //Pointer to the kernel to be executed
     InterKernel * kernel;
diff --git a/Addons/CKernelApi/Src/FScalfmmApiInit.cpp b/Addons/CKernelApi/Src/FScalfmmApiInit.cpp
index 194cc688a..5e73bc059 100644
--- a/Addons/CKernelApi/Src/FScalfmmApiInit.cpp
+++ b/Addons/CKernelApi/Src/FScalfmmApiInit.cpp
@@ -8,21 +8,21 @@ extern "C" {
 
 extern "C" scalfmm_handle scalfmm_init(/*int TreeHeight,double BoxWidth,double* BoxCenter, */scalfmm_kernel_type KernelType){
     ScalFmmCoreHandle * handle = new ScalFmmCoreHandle();
-
+    typedef double FReal;
     switch(KernelType){
     case 0:
-        handle->engine = new FUserKernelEngine(/*TreeHeight, BoxWidth, BoxCenter, */KernelType);
+        handle->engine = new FUserKernelEngine<FReal>(/*TreeHeight, BoxWidth, BoxCenter, */KernelType);
         break;
 
     case 1:
         //TODO typedefs
         typedef FP2PParticleContainerIndexed<FReal>                                 ContainerClass;
-        typedef FChebCell<7>                                                         ChebCell;
+        typedef FChebCell<FReal,7>                                                         ChebCell;
 
         typedef FInterpMatrixKernelR<FReal>                                        MatrixKernelClass;
-        typedef FChebSymKernel<ChebCell,ContainerClass,MatrixKernelClass,7>        ChebKernel;
+        typedef FChebSymKernel<FReal,ChebCell,ContainerClass,MatrixKernelClass,7>        ChebKernel;
 
-        handle->engine = new FInterEngine<ChebCell,ChebKernel>(/*TreeHeight,BoxWidth,BoxCenter, */KernelType);
+        handle->engine = new FInterEngine<FReal,ChebCell,ChebKernel>(/*TreeHeight,BoxWidth,BoxCenter, */KernelType);
         break;
     // case 2:
     //     //TODO typedefs
@@ -66,14 +66,14 @@ extern "C" {
 
 typedef struct FChebCell_struct{
     //Store what's needed
-    FChebCell<7> * cell;
+    FChebCell<double,7> * cell;
 }ChebCellStruct;
 
 
 //How to create/destroy cells
 extern "C" ChebCellStruct * ChebCellStruct_create(long long int inIndex,int * position){
     ChebCellStruct * newCell = new ChebCellStruct();
-    newCell->cell = new FChebCell<7>();
+    newCell->cell = new FChebCell<double,7>();
     newCell->cell->setMortonIndex(inIndex);
     newCell->cell->setCoordinate(position[0],position[1],position[2]);
     return newCell;
@@ -90,8 +90,8 @@ extern "C" void ChebCellStruct_free(ChebCellStruct * inCell){
 
 typedef struct FChebKernel_struct{
     //Be ready full duplication go there !!!
-    FChebSymKernel<FChebCell<7>,FP2PParticleContainerIndexed<FReal>,FInterpMatrixKernelR,7> ** kernel;
-    FInterpMatrixKernelR<FReal> * matrix;
+    FChebSymKernel<double,FChebCell<double,7>,FP2PParticleContainerIndexed<double>,FInterpMatrixKernelR<double>,7> ** kernel;
+    FInterpMatrixKernelR<double> * matrix;
 } ChebKernelStruct;
 
 //Kernel functions
@@ -99,14 +99,14 @@ extern "C" ChebKernelStruct * ChebKernelStruct_create(int inTreeHeight,
                                                       double inBoxWidth,
                                                       double* inBoxCenter){
     //typedef to lighten the writing
-    typedef FChebSymKernel<FChebCell<7>, FP2PParticleContainerIndexed<FReal>, FInterpMatrixKernelR,7> KernelClass;
+    typedef FChebSymKernel<double,FChebCell<double,7>, FP2PParticleContainerIndexed<double>, FInterpMatrixKernelR<double>,7> KernelClass;
     ChebKernelStruct * newKernel = new ChebKernelStruct();
-    newKernel->matrix= new FInterpMatrixKernelR();
+    newKernel->matrix= new FInterpMatrixKernelR<double>();
     int nb_threads = omp_get_max_threads();
     newKernel->kernel = new KernelClass*[nb_threads];
     newKernel->kernel[0]=new KernelClass(inTreeHeight,
                                          inBoxWidth,
-                                         FPoint<FReal>(inBoxCenter[0], inBoxCenter[1], inBoxCenter[2]),
+                                         FPoint<double>(inBoxCenter[0], inBoxCenter[1], inBoxCenter[2]),
                                          newKernel->matrix);
 
     for(int idThreads=1 ; idThreads<nb_threads ; ++idThreads){
@@ -128,11 +128,11 @@ extern "C" void ChebKernelStruct_free(void *inKernel){
 
 extern "C" void ChebKernel_P2M(void * leafCell, int nbParticles, const int *particleIndexes, void * inKernel){
     //make temporary array of parts
-    FP2PParticleContainerIndexed<FReal>* tempContainer = new FP2PParticleContainerIndexed<FReal>();
+    FP2PParticleContainerIndexed<double>* tempContainer = new FP2PParticleContainerIndexed<double>();
     tempContainer->reserve(nbParticles);
-    FPoint<FReal> pos;
+    FPoint<double> pos;
     for(int i=0 ; i<nbParticles ; ++i){
-        pos = FPoint<FReal>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
+        pos = FPoint<double>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
                      reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+1],
                      reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+2]);
         double Phi = reinterpret_cast<UserData *>(inKernel)->myPhyValues[particleIndexes[i]];
@@ -141,7 +141,7 @@ extern "C" void ChebKernel_P2M(void * leafCell, int nbParticles, const int *part
     }
     //get the real cell struct
     ChebCellStruct * realCellStruct = reinterpret_cast<ChebCellStruct *>(leafCell);
-    FChebCell<7> * realCell = realCellStruct->cell;
+    FChebCell<double,7> * realCell = realCellStruct->cell;
 
     //Identify thread number
     int id_thread = omp_get_thread_num();
@@ -159,8 +159,8 @@ extern "C" void  ChebKernel_M2M(int level, void* parentCell, int childPosition,
     ChebCellStruct * parentCellStruct = reinterpret_cast<ChebCellStruct *>(parentCell);
     ChebCellStruct * childCellStruct = reinterpret_cast<ChebCellStruct *>(childCell);
     //get real cheb cell
-    FChebCell<7>* parentChebCell = parentCellStruct->cell;
-    FChebCell<7>* childChebCell = childCellStruct->cell;
+    FChebCell<double,7>* parentChebCell = parentCellStruct->cell;
+    FChebCell<double,7>* childChebCell = childCellStruct->cell;
 
     //Identify thread number
     int id_thread = omp_get_thread_num();
@@ -176,10 +176,10 @@ extern "C" void ChebKernel_M2L(int level, void* targetCell,  void* sourceCell[34
     //Get our structures
     ChebCellStruct * targetCellStruct = reinterpret_cast<ChebCellStruct *>(targetCell);
     //get real cheb cell
-    FChebCell<7>* const targetChebCell = targetCellStruct->cell;
+    FChebCell<double,7>* const targetChebCell = targetCellStruct->cell;
 
     //copy to an array of FChebCell
-    const FChebCell<7>* arrayOfChebCell[343];
+    const FChebCell<double,7>* arrayOfChebCell[343];
     for(int i=0; i<343 ; ++i){
         if(sourceCell[i] != nullptr){
             arrayOfChebCell[i] = reinterpret_cast<ChebCellStruct*>(sourceCell[i])->cell;
@@ -202,8 +202,8 @@ extern "C" void ChebKernel_L2L(int level, void* parentCell, int childPosition, v
     ChebCellStruct * parentCellStruct = reinterpret_cast<ChebCellStruct *>(parentCell);
     ChebCellStruct * childCellStruct = reinterpret_cast<ChebCellStruct *>(childCell);
     //get real cheb cell
-    FChebCell<7>* parentChebCell = parentCellStruct->cell;
-    FChebCell<7>* childChebCell = childCellStruct->cell;
+    FChebCell<double,7>* parentChebCell = parentCellStruct->cell;
+    FChebCell<double,7>* childChebCell = childCellStruct->cell;
 
     //Identify thread number
     int id_thread = omp_get_thread_num();
@@ -217,11 +217,11 @@ extern "C" void ChebKernel_L2L(int level, void* parentCell, int childPosition, v
 
 extern "C" void ChebKernel_L2P(void* leafCell, int nbParticles, const int* particleIndexes, void* inKernel){
     //Create temporary FSimpleLeaf
-    FP2PParticleContainerIndexed<FReal>* tempContainer = new FP2PParticleContainerIndexed<FReal>();
+    FP2PParticleContainerIndexed<double>* tempContainer = new FP2PParticleContainerIndexed<double>();
     tempContainer->reserve(nbParticles);
-    FPoint<FReal> pos;
+    FPoint<double> pos;
     for(int i=0 ; i<nbParticles ; ++i){
-    pos = FPoint<FReal>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
+    pos = FPoint<double>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
         reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+1],
         reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+2]);
     double Phi = reinterpret_cast<UserData *>(inKernel)->myPhyValues[particleIndexes[i]];
@@ -230,7 +230,7 @@ extern "C" void ChebKernel_L2P(void* leafCell, int nbParticles, const int* parti
     //Get our structures
     ChebCellStruct * leafCellStruct = reinterpret_cast<ChebCellStruct *>(leafCell);
     //get real cheb cell
-    FChebCell<7>* leafChebCell = leafCellStruct->cell;
+    FChebCell<double,7>* leafChebCell = leafCellStruct->cell;
 
     //Identify thread number
     int id_thread = omp_get_thread_num();
@@ -258,10 +258,10 @@ extern "C" void ChebKernel_L2P(void* leafCell, int nbParticles, const int* parti
                     const int * sourceParticleIndexes[27],int sourceNbPart[27],void* inKernel){
 
     //Create temporary FSimpleLeaf for target
-    FP2PParticleContainerIndexed<FReal>* tempContTarget = new FP2PParticleContainerIndexed<FReal>();
+    FP2PParticleContainerIndexed<double>* tempContTarget = new FP2PParticleContainerIndexed<double>();
     tempContTarget->reserve(nbParticles);
     for(int i=0 ; i<nbParticles ; ++i){
-        FPoint<FReal> pos = FPoint<FReal>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
+        FPoint<double> pos = FPoint<double>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3  ],
                             reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+1],
                             reinterpret_cast<UserData *>(inKernel)->insertedPositions[particleIndexes[i]*3+2]);
         double Phi = reinterpret_cast<UserData *>(inKernel)->myPhyValues[particleIndexes[i]];
@@ -269,18 +269,18 @@ extern "C" void ChebKernel_L2P(void* leafCell, int nbParticles, const int* parti
     }
 
     //Create 27 FSimpleLeaf for 27 sources
-    FP2PParticleContainerIndexed<FReal>* tempContSources[27];
+    FP2PParticleContainerIndexed<double>* tempContSources[27];
     for(int idSource=0; idSource<27 ; ++idSource){
         if(sourceNbPart[idSource] != 0){
             //Create container
-            tempContSources[idSource] = new FP2PParticleContainerIndexed<FReal>();
+            tempContSources[idSource] = new FP2PParticleContainerIndexed<double>();
             //Allocate memory
             tempContSources[idSource]->reserve(sourceNbPart[idSource]);
             //Store a ptr to the indices of that source leaf
             const int * indSource = sourceParticleIndexes[idSource];
             //Then, for each part in this source
             for(int i=0 ; i<sourceNbPart[idSource] ; ++i){
-                FPoint<FReal> pos = FPoint<FReal>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[indSource[i]*3  ],
+                FPoint<double> pos = FPoint<double>(reinterpret_cast<UserData *>(inKernel)->insertedPositions[indSource[i]*3  ],
                                     reinterpret_cast<UserData *>(inKernel)->insertedPositions[indSource[i]*3+1],
                                     reinterpret_cast<UserData *>(inKernel)->insertedPositions[indSource[i]*3+2]);
                 double Phi = reinterpret_cast<UserData *>(inKernel)->myPhyValues[indSource[i]];
diff --git a/Addons/CKernelApi/Src/FUserKernelEngine.hpp b/Addons/CKernelApi/Src/FUserKernelEngine.hpp
index 9b88ce6d1..585aafa53 100644
--- a/Addons/CKernelApi/Src/FUserKernelEngine.hpp
+++ b/Addons/CKernelApi/Src/FUserKernelEngine.hpp
@@ -197,7 +197,7 @@ public:
 
 };
 
-
+template<class FReal>
 class FUserKernelEngine : public FScalFMMEngine{
 
 private:
@@ -205,13 +205,13 @@ private:
     //Typedefs :
     typedef FP2PParticleContainerIndexed<FReal>           ContainerClass;
     typedef FSimpleLeaf<FReal, ContainerClass>                   LeafClass;
-    typedef FOctree<CoreCell,ContainerClass,LeafClass>  OctreeClass;
+    typedef FOctree<FReal,CoreCell,ContainerClass,LeafClass>  OctreeClass;
     typedef CoreKernel<CoreCell,ContainerClass>     CoreKernelClass;
 
     //For arranger classes
-    typedef FBasicParticleContainerIndexedMover<OctreeClass, ContainerClass> MoverClass;
+    typedef FBasicParticleContainerIndexedMover<FReal, OctreeClass, ContainerClass> MoverClass;
     typedef FOctreeArranger<FReal,OctreeClass, ContainerClass, MoverClass> ArrangerClass;
-    typedef FArrangerPeriodic<OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
+    typedef FArrangerPeriodic<FReal,OctreeClass, ContainerClass, MoverClass> ArrangerClassPeriodic;
 
 
     //Attributes
diff --git a/Addons/CKernelApi/Tests/testUserDefinedKernelApi.c b/Addons/CKernelApi/Tests/testUserDefinedKernelApi.c
index 1fd1d94cc..6287d2fcf 100644
--- a/Addons/CKernelApi/Tests/testUserDefinedKernelApi.c
+++ b/Addons/CKernelApi/Tests/testUserDefinedKernelApi.c
@@ -112,7 +112,7 @@ void my_Callback_M2M(int level, void* cellData, int childPosition, void* childDa
     struct MyCellDescriptor* my_child = (struct MyCellDescriptor*) childData;
 
     int childFullPosition[3];
-    Scalfmm_utils_parentChildPosition(childPosition, childFullPosition);
+    scalfmm_utils_parentChildPosition(childPosition, childFullPosition);
 
     VerbosePrint("Doing a M2M at level %d, between cells %lld and %lld (position %d/%d/%d)\n",
            level, my_cell->mortonIndex, my_child->mortonIndex,
@@ -128,7 +128,7 @@ void my_Callback_M2L(int level, void* cellData, int srcPosition, void* srcData,
     struct MyCellDescriptor* my_src_cell = (struct MyCellDescriptor*) srcData;
 
     int interactionFullPosition[3];
-    Scalfmm_utils_interactionPosition(srcPosition, interactionFullPosition);
+    scalfmm_utils_interactionPosition(srcPosition, interactionFullPosition);
 
     VerbosePrint("Doing a M2L at level %d, between cells %lld and %lld (position %d/%d/%d)\n",
            level, my_cell->mortonIndex, my_src_cell->mortonIndex,
@@ -144,7 +144,7 @@ void my_Callback_L2L(int level, void* cellData, int childPosition, void* childDa
     struct MyCellDescriptor* my_child = (struct MyCellDescriptor*) childData;
 
     int childFullPosition[3];
-    Scalfmm_utils_parentChildPosition(childPosition, childFullPosition);
+    scalfmm_utils_parentChildPosition(childPosition, childFullPosition);
 
     VerbosePrint("Doing a L2L at level %d, between cells %lld and %lld (position %d/%d/%d)\n",
            level, my_cell->mortonIndex, my_child->mortonIndex,
@@ -246,6 +246,7 @@ int main(int argc, char ** argv){
     // Insert particles
     printf("Inserting particles...\n");
     scalfmm_tree_insert_particles_xyz(handle, nbParticles, particleXYZ);
+    printf("Particles Inserted ...\n");
 
     // Init our callback struct
     struct User_Scalfmm_Kernel_Descriptor kernel;
@@ -263,7 +264,7 @@ int main(int argc, char ** argv){
     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);
-
+    printf("Kernel set ... \n");
     //loop to multiples runs of the fmm
     int nb_ite = 1;
     int curr_ite = 0;
@@ -272,8 +273,10 @@ int main(int argc, char ** argv){
     memset(new_positions,0,3*nbParticles*sizeof(double));
 
     while(curr_ite < nb_ite){
+        printf("Start FMM number %d/%d ... \n", curr_ite,nb_ite);
         // Execute the FMM
         scalfmm_execute_fmm(handle/*, kernel, &my_data*/);
+        printf("FMM finished ... \n");
         scalfmm_get_positions_xyz(handle,nbParticles,new_positions);
         //Computation on those positions
         //Here it's a random
-- 
GitLab