From 4ff2da857d57b53eb4b7251fa1d459d14895ce1d Mon Sep 17 00:00:00 2001
From: bramas <berenger.bramas@inria.fr>
Date: Sun, 27 Apr 2014 14:05:53 +0200
Subject: [PATCH] debug blocked tree and seq algorithm

---
 Src/GroupTree/FGroupOfParticles.hpp  |  2 +-
 Src/GroupTree/FGroupSeqAlgorithm.hpp | 26 ++++++++++++++++++++------
 Tests/Kernels/testBlockedTree.cpp    |  4 ++--
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/Src/GroupTree/FGroupOfParticles.hpp b/Src/GroupTree/FGroupOfParticles.hpp
index 2cbb97f48..facf85055 100644
--- a/Src/GroupTree/FGroupOfParticles.hpp
+++ b/Src/GroupTree/FGroupOfParticles.hpp
@@ -52,7 +52,7 @@ protected:
     size_t attributeOffset;
 
     //< This value is for not used leaves
-    static const MortonIndex LeafIsEmptyFlag = -1;
+    static const int LeafIsEmptyFlag = -1;
 
 public:
     /**
diff --git a/Src/GroupTree/FGroupSeqAlgorithm.hpp b/Src/GroupTree/FGroupSeqAlgorithm.hpp
index 57afc061f..2a4efd642 100644
--- a/Src/GroupTree/FGroupSeqAlgorithm.hpp
+++ b/Src/GroupTree/FGroupSeqAlgorithm.hpp
@@ -5,6 +5,8 @@
 #include "../Core/FCoreCommon.hpp"
 #include "../Utils/FQuickSort.hpp"
 #include "../Containers/FTreeCoordinate.hpp"
+#include "../Utils/FLog.hpp"
+#include "../Utils/FTic.hpp"
 
 #include <list>
 #include <vector>
@@ -38,6 +40,8 @@ public:
     }
 
     void execute(const unsigned operationsToProceed = FFmmNearAndFarFields){
+        FLOG( FLog::Controller << "\tStart FGroupSeqAlgorithm\n" );
+
         if(operationsToProceed & FFmmP2M) bottomPass();
 
         if(operationsToProceed & FFmmM2M) upwardPass();
@@ -51,6 +55,7 @@ public:
 
 protected:
     void bottomPass(){
+        FLOG( FTic timer; );
         typename std::list<ParticleGroupClass*>::iterator iterParticles = tree->leavesBegin();
         const typename std::list<ParticleGroupClass*>::iterator endParticles = tree->leavesEnd();
 
@@ -77,9 +82,11 @@ protected:
         }
 
         FAssertLF(iterParticles == endParticles && iterCells == endCells);
+        FLOG( FLog::Controller << "\t\t bottomPass in " << timer.tacAndElapsed() << "s\n" );
     }
 
     void upwardPass(){
+        FLOG( FTic timer; );
         for(int idxLevel = tree->getHeight()-2 ; idxLevel >= 2 ; --idxLevel){
             typename std::list<CellContainerClass*>::iterator iterCells = tree->cellsBegin(idxLevel);
             const typename std::list<CellContainerClass*>::iterator endCells = tree->cellsEnd(idxLevel);
@@ -117,9 +124,11 @@ protected:
 
             FAssertLF(iterCells == endCells && (iterChildCells == endChildCells || (++iterChildCells) == endChildCells));
         }
+        FLOG( FLog::Controller << "\t\t upwardPass in " << timer.tacAndElapsed() << "s\n" );
     }
 
     void transferPass(){
+        FLOG( FTic timer; );
         for(int idxLevel = tree->getHeight()-1 ; idxLevel >= 2 ; --idxLevel){
             typename std::list<CellContainerClass*>::iterator iterCells = tree->cellsBegin(idxLevel);
             const typename std::list<CellContainerClass*>::iterator endCells = tree->cellsEnd(idxLevel);
@@ -151,7 +160,7 @@ protected:
                                         counterExistingCell += 1;
                                     }
                                 }
-                                else if(interactionsPosition[idxInter] < 343/2){
+                                else if(interactionsIndexes[idxInter] < mindex){
                                     OutOfBlockInteraction property;
                                     property.insideIndex = mindex;
                                     property.outIndex    = interactionsIndexes[idxInter];
@@ -179,7 +188,7 @@ protected:
                         currentOutInteraction += 1;
                     }
 
-                    int lastOutInteraction = currentOutInteraction + 1;
+                    int lastOutInteraction = currentOutInteraction;
                     while(lastOutInteraction < int(outsideInteractions.size()) && outsideInteractions[lastOutInteraction].outIndex < blockEndIdx){
                         lastOutInteraction += 1;
                     }
@@ -211,9 +220,11 @@ protected:
             }
 
         }
+        FLOG( FLog::Controller << "\t\t transferPass in " << timer.tacAndElapsed() << "s\n" );
     }
 
     void downardPass(){
+        FLOG( FTic timer; );
         for(int idxLevel = 2 ; idxLevel <= tree->getHeight()-2 ; ++idxLevel){
             typename std::list<CellContainerClass*>::iterator iterCells = tree->cellsBegin(idxLevel);
             const typename std::list<CellContainerClass*>::iterator endCells = tree->cellsEnd(idxLevel);
@@ -251,9 +262,11 @@ protected:
 
             FAssertLF(iterCells == endCells && (iterChildCells == endChildCells || (++iterChildCells) == endChildCells));
         }
+        FLOG( FLog::Controller << "\t\t downardPass in " << timer.tacAndElapsed() << "s\n" );
     }
 
     void directPass(){
+        FLOG( FTic timer; );
         {
             typename std::list<ParticleGroupClass*>::iterator iterParticles = tree->leavesBegin();
             const typename std::list<ParticleGroupClass*>::iterator endParticles = tree->leavesEnd();
@@ -303,7 +316,7 @@ protected:
 
                             ParticleContainerClass interactionsObjects[27];
                             ParticleContainerClass* interactions[27];
-                            memset(interactions, 0, 27*sizeof(CellClass*));
+                            memset(interactions, 0, 27*sizeof(ParticleContainerClass*));
                             int counterExistingCell = 0;
 
                             for(int idxInter = 0 ; idxInter < counter ; ++idxInter){
@@ -314,7 +327,7 @@ protected:
                                         counterExistingCell += 1;
                                     }
                                 }
-                                else if(interactionsPosition[idxInter] < 27/2){
+                                else if(interactionsIndexes[idxInter] < mindex){
                                     OutOfBlockInteraction property;
                                     property.insideIndex = mindex;
                                     property.outIndex    = interactionsIndexes[idxInter];
@@ -342,7 +355,7 @@ protected:
                         currentOutInteraction += 1;
                     }
 
-                    int lastOutInteraction = currentOutInteraction + 1;
+                    int lastOutInteraction = currentOutInteraction;
                     while(lastOutInteraction < int(outsideInteractions.size()) && outsideInteractions[lastOutInteraction].outIndex < blockEndIdx){
                         lastOutInteraction += 1;
                     }
@@ -354,7 +367,7 @@ protected:
                                 ParticleContainerClass particles = (*iterParticles)->template getLeaf<ParticleContainerClass>(outsideInteractions[outInterIdx].insideIndex);
                                 FAssertLF(particles.isAttachedToSomething());
                                 ParticleContainerClass* interactions[27];
-                                memset(interactions, 0, 27*sizeof(CellClass*));
+                                memset(interactions, 0, 27*sizeof(ParticleContainerClass*));
                                 interactions[outsideInteractions[outInterIdx].outPosition] = &interParticles;
                                 const int counter = 1;
                                 kernels->P2PRemote( FTreeCoordinate(outsideInteractions[outInterIdx].insideIndex, tree->getHeight()-1), &particles, &particles , interactions, counter);
@@ -373,6 +386,7 @@ protected:
                 ++iterParticles;
             }
         }
+        FLOG( FLog::Controller << "\t\t directPass in " << timer.tacAndElapsed() << "s\n" );
     }
 
     int getOppositeNeighIndex(const int index) const {
diff --git a/Tests/Kernels/testBlockedTree.cpp b/Tests/Kernels/testBlockedTree.cpp
index 7e51a6c82..5cb625622 100644
--- a/Tests/Kernels/testBlockedTree.cpp
+++ b/Tests/Kernels/testBlockedTree.cpp
@@ -27,13 +27,13 @@
 #include "../../Src/GroupTree/FP2PGroupParticleContainer.hpp"
 
 int main(int argc, char* argv[]){
-    static const int P = 9;
+    static const int P = 3;
     typedef FRotationCell<P>               CellClass;
     typedef FP2PParticleContainer<>          ContainerClass;
 
     typedef FSimpleLeaf< ContainerClass >                     LeafClass;
     typedef FOctree< CellClass, ContainerClass , LeafClass >  OctreeClass;
-    typedef FGroupTree< CellClass, FP2PGroupParticleContainer<>, 4, FReal>  GroupOctreeClass;
+    typedef FGroupTree< CellClass, FP2PGroupParticleContainer<>, 5, FReal>  GroupOctreeClass;
 
     FTic counter;
     const int NbLevels      = FParameters::getValue(argc,argv,"-h", 5);
-- 
GitLab