Commit f579a60e authored by berenger-bramas's avatar berenger-bramas
Browse files

Added FReal in FGlobal.hpp that can be double or real and change all the simulation type.

Added restrict to some kernels prototypes (did not increase performance yet)

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@22 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 6dbb127e
......@@ -20,17 +20,16 @@ class FList {
Node* next; //< Next node
};
Node* root; //< Root node, NULL if size is 0
int size; //< Elements in the list
Node* root; //< Root node, NULL if size is 0
int size; //< Elements in the list
/**
* Copy a list into current object
* The current list has to be empty when this function is called
*/
void copy(const FList& other){
const Node* otherRoot = other.root;
Node ** myRoot = &this->root;
const Node* FRestrict otherRoot = other.root;
Node * FRestrict * myRoot = &this->root;
while(otherRoot){
(*myRoot) = new Node;
(*myRoot)->target = otherRoot->target;
......@@ -59,9 +58,11 @@ public:
* @return the current list as a reference
*/
FList& operator=(const FList& other){
if(this != &other){
clear();
copy(other);
return *this;
}
return *this;
}
/**
......@@ -78,7 +79,7 @@ public:
*/
void clear(){
while(this->root){
Node* next(this->root->next);
Node*const FRestrict next = this->root->next;
delete this->root;
this->root = next;
}
......@@ -90,7 +91,7 @@ public:
* @param inObject the object to insert
*/
void pushFront(Object& inObject){
Node* newNode = new Node;
Node* newNode = new Node;
newNode->target = inObject;
newNode->next = this->root;
......
......@@ -30,16 +30,16 @@
*/
template< class ParticuleClass, class CellClass, int OctreeHeight, int SubtreeHeight = 3>
class FOctree {
const int height; //< tree height
const int leafIndex; //< index of leaf int array
FReal boxWidthAtLevel[OctreeHeight]; //< to store the width of each boxs at all levels
FSubOctree< ParticuleClass, CellClass > root; //< root suboctree
const FReal boxWidth; //< the space system width
const F3DPosition boxCenter; //< the space system center
const F3DPosition boxCorner; //< the space system corner (used to compute morton index)
const F3DPosition boxCenter; //< the space system center
const F3DPosition boxCorner; //< the space system corner (used to compute morton index)
FReal boxWidthAtLevel[OctreeHeight]; //< to store the width of each boxs at all levels
const FReal boxWidth; //< the space system width
FSubOctree< ParticuleClass, CellClass > root; //< root suboctree
const int height; //< tree height
const int leafIndex; //< index of leaf int array
/** Forbiden copy operator */
FOctree& operator=(const FOctree&) {
......@@ -109,7 +109,7 @@ public:
* ask node to insert this particule
* @param inParticule the particule to insert (must inherite from FAbstractParticule)
*/
void insert(ParticuleClass* const inParticule){
void insert(ParticuleClass* const inParticule){
const MortonIndex particuleIndex = getLeafMortonFromPosition( inParticule->getPosition() );
root.insert( particuleIndex, inParticule, this->height, this->boxWidthAtLevel);
}
......@@ -158,8 +158,8 @@ public:
class Iterator : protected FAssertable {
SubOctreeTypes current; //< Current suboctree
int currentLocalLevel; //< Current level in the current suboctree
long currentLocalIndex; //< Current index (array position) in the current_suboctree.cells[ currentLocalLevel ]
int currentLocalLevel; //< Current level in the current suboctree
/**
* To know what is the left limit on the current level on the current subtree
......
......@@ -37,18 +37,19 @@
template< class ParticuleClass, class CellClass >
class FAbstractSubOctree : protected FAssertable{
protected:
const int subOctreeHeight; //< Height of this suboctree
const int subOctreePosition; //< Level of the current suboctree in the global tree (0 if node)
long leftLeafIndex; //< The leaf at the left position (this is the array index to start when iterate)
long rightLeafIndex; //< The leaf at the right position (this is the last array index when iterate)
CellClass*** cells; //< Potential cells, cells are allocated only if needed
FAbstractSubOctree* const parent; //< Parent suboctree (null for root)
const long indexInParent; //< This is the index of the current octree in the parent's array
long leftLeafIndex; //< The leaf at the left position (this is the array index to start when iterate)
long rightLeafIndex; //< The leaf at the right position (this is the last array index when iterate)
const int subOctreeHeight; //< Height of this suboctree
const int subOctreePosition; //< Level of the current suboctree in the global tree (0 if node)
/**
* This function compute the morton index for the last level of this suboctree.
* suppose we have an index like : 000.010.111.001.101.110
......@@ -248,6 +249,7 @@ class FSubOctreeWithLeafs : public FAbstractSubOctree<ParticuleClass,CellClass>
private:
FList<ParticuleClass*>** leafs; //< Leafs array
public:
/**
* Constructor
......
......@@ -2,6 +2,7 @@
#define FABSTRACTKERNELS_HPP
// /!\ Please, you must read the license at the bottom of this page
#include "../Utils/FGlobal.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -41,7 +42,7 @@ public:
* the child array has a size of 8 elements (address if exists or 0 otherwise).
* You must test if a pointer is 0 to know if an element exists inside this array
*/
virtual void M2M(CellClass* const pole, const CellClass*const* const child, const int inLevel) = 0;
virtual void M2M(CellClass* const FRestrict pole, const CellClass*const FRestrict *const FRestrict child, const int inLevel) = 0;
/**
* M2L
......@@ -51,7 +52,7 @@ public:
* @param size the number of neighbors
* @param inLevel the current level of the computation
*/
virtual void M2L(CellClass* const local, const CellClass*const* const distantNeighbors, const int size, const int inLevel) = 0;
virtual void M2L(CellClass* const FRestrict local, const CellClass*const FRestrict *const FRestrict distantNeighbors, const int size, const int inLevel) = 0;
/**
* L2L
......@@ -62,7 +63,7 @@ public:
* the child array has a size of 8 elements (address if exists or 0 otherwise).
* You must test if a pointer is 0 to know if an element exists inside this array
*/
virtual void L2L(const CellClass* const local, CellClass** const child, const int inLevel) = 0;
virtual void L2L(const CellClass* const FRestrict local, CellClass* FRestrict * const FRestrict child, const int inLevel) = 0;
/**
* L2P
......@@ -79,7 +80,7 @@ public:
* @param directNeighborsParticules the particules from direct neighbors (this is an array of list)
* @param size the number of direct neighbors (the size of the array directNeighborsParticules)
*/
virtual void P2P(FList<ParticuleClass*>* const particules, const FList<ParticuleClass*>*const* const directNeighborsParticules, const int size) = 0;
virtual void P2P(FList<ParticuleClass*>* const FRestrict particules, const FList<ParticuleClass*>*const FRestrict *const FRestrict directNeighborsParticules, const int size) = 0;
};
......
......@@ -31,17 +31,17 @@ public:
}
/** Print the morton index */
virtual void M2M(CellClass* const pole, const CellClass*const* const child, const int inLevel) {
virtual void M2M(CellClass* const FRestrict pole, const CellClass*const FRestrict *const FRestrict child, const int inLevel) {
//FDEBUG( FDebug::Controller << "M2M : " << pole->getMortonIndex() << "\n" );
}
/** Print the morton index */
virtual void M2L(CellClass* const pole, const CellClass*const* const distantNeighbors, const int size, const int inLevel) {
virtual void M2L(CellClass* const FRestrict pole, const CellClass*const FRestrict *const FRestrict distantNeighbors, const int size, const int inLevel) {
//FDEBUG( FDebug::Controller << "M2L : " << pole->getMortonIndex() << " (" << size << ")\n" );
}
/** Print the morton index */
virtual void L2L(const CellClass* const local, CellClass** const child, const int inLevel) {
virtual void L2L(const CellClass* const FRestrict local, CellClass* FRestrict *const FRestrict child, const int inLevel) {
//FDEBUG( FDebug::Controller << "L2L : " << local->getMortonIndex() << "\n" );
}
......@@ -51,7 +51,7 @@ public:
}
/** Print the number of particules */
virtual void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) {
virtual void P2P(FList<ParticuleClass*>* const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) {
//FDEBUG( FDebug::Controller << "P2P : " << currentBox->getSize() << " (" << size << ")\n" );
}
};
......
......@@ -30,9 +30,8 @@ class FFMMAlgorithmThreaded : protected FAssertable{
static const int NbThreads = 4; //< Number of threads (currently a static number)
Octree* const tree; //< The octree to work on
KernelClass<ParticuleClass, CellClass>* kernels[NbThreads]; //< The kernels (one by thread)
Octree* const tree; //< The octree to work on
FDEBUG_TIME(FTic counter); //< In case of debug count the time
......
......@@ -30,7 +30,7 @@ public:
pole->setDataUp(particules->getSize());
}
// During upward
void M2M(CellClass* const pole, const CellClass*const* const child, const int inLevel) {
void M2M(CellClass* const FRestrict pole, const CellClass *const FRestrict *const FRestrict child, const int inLevel) {
// A parent represents the sum of the child
for(int idx = 0 ; idx < 8 ; ++idx){
if(child[idx]){
......@@ -39,14 +39,14 @@ public:
}
}
// Before Downward
void M2L(CellClass* const pole, const CellClass*const* const distantNeighbors, const int size, const int inLevel) {
void M2L(CellClass* const FRestrict pole, const CellClass*const FRestrict *const distantNeighbors, const int size, const int inLevel) {
// The pole is impacted by what represent other poles
for(int idx = 0 ; idx < size ; ++idx){
pole->setDataDown(pole->getDataDown() + distantNeighbors[idx]->getDataUp());
}
}
// During Downward
void L2L(const CellClass* const local, CellClass** const child, const int inLevel) {
void L2L(const CellClass*const FRestrict local, CellClass* FRestrict *const FRestrict child, const int inLevel) {
// Each child is impacted by the father
for(int idx = 0 ; idx < 8 ; ++idx){
if(child[idx]){
......@@ -55,7 +55,7 @@ public:
}
}
// After Downward
void L2P(const CellClass* const local, FList<ParticuleClass*>* const particules){
void L2P(const CellClass* const local, FList<ParticuleClass*>*const particules){
// The particules is impacted by the parent cell
typename FList<ParticuleClass*>::BasicIterator iter(*particules);
while( iter.isValide() ){
......@@ -64,7 +64,7 @@ public:
}
}
// After Downward
void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) {
void P2P(FList<ParticuleClass*>*const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) {
// Each particules targeted is impacted by the particules sources
long inc = currentBox->getSize() - 1;
for(int idx = 0 ; idx < size ; ++idx){
......
......@@ -229,7 +229,7 @@ protected:
//////////////////////////////////////////////////////////////////
// position_2_r_cos_th_sin_th_ph
void positionToSphere(const F3DPosition& inVector, Spherical* const outSphere ){
void positionToSphere(const F3DPosition& inVector, Spherical* const FRestrict outSphere ){
const FReal x2y2 = (inVector.getX() * inVector.getX()) + (inVector.getY() * inVector.getY());
outSphere->r = FMath::Sqrt( x2y2 + (inVector.getZ() * inVector.getZ()));
......@@ -709,7 +709,7 @@ public:
*
* Warning: if j-n < |k-l| we do nothing.
*/
void M2M(CellClass* const inPole, const CellClass*const* const inChild, const int inLevel) {
void M2M(CellClass* const FRestrict inPole, const CellClass *const FRestrict *const FRestrict inChild, const int inLevel) {
// We do NOT have: for(l=n-j+k; l<=j-n+k ;++l){} <=> for(l=-n; l<=n ;++l){if (j-n >= abs(k-l)){}}
// But we have: for(k=MAX(0,n-j+l); k<=j-n+l; ++k){} <=> for(k=0; k<=j; ++k){if (j-n >= abs(k-l)){}}
......@@ -829,7 +829,7 @@ public:
*Remark: here we have always j+n >= |-k-l|
*
*/
void M2L(CellClass* const pole, const CellClass*const* const distantNeighbors, const int size, const int inLevel) {
void M2L(CellClass* const FRestrict pole, const CellClass*const FRestrict *const FRestrict distantNeighbors, const int size, const int inLevel) {
FTreeCoordinate coordCenter;
coordCenter.setPositionFromMorton(pole->getMortonIndex(),inLevel);
......@@ -961,7 +961,7 @@ public:
*
*Warning: if |l-k| > n-j, we do nothing.
*/
void L2L(const CellClass* const pole, CellClass** const child, const int inLevel) {
void L2L(const CellClass* const FRestrict pole, CellClass* FRestrict *const FRestrict child, const int inLevel) {
for(int idxChild = 0 ; idxChild < 8 ; ++idxChild){
// if no child at this position
......@@ -1054,7 +1054,7 @@ public:
virtual void L2P(const CellClass* const local, FList<ParticuleClass*>* const particules) = 0;
virtual void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) = 0;
virtual void P2P(FList<ParticuleClass*>* const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) = 0;
};
......
......@@ -35,7 +35,7 @@ class FFmbKernelsForces : public FAbstractFmbKernels<ParticuleClass,CellClass> {
/** bodies_L2P
* expansion_L2P_add_to_force_vector
*/
void L2P(const CellClass* const local, FList<ParticuleClass*>* const particules){
void L2P(const CellClass* const local, FList<ParticuleClass*> *const particules){
typename FList<ParticuleClass*>::BasicIterator iterTarget(*particules);
while( iterTarget.isValide() ){
//printf("Morton %lld\n",local->getMortonIndex());
......@@ -226,7 +226,7 @@ class FFmbKernelsForces : public FAbstractFmbKernels<ParticuleClass,CellClass> {
* )
*
*/
void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) {
void P2P(FList<ParticuleClass*>* const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) {
typename FList<ParticuleClass*>::BasicIterator iterTarget(*currentBox);
while( iterTarget.isValide() ){
for(int idxDirectNeighbors = 0 ; idxDirectNeighbors < size ; ++idxDirectNeighbors){
......
......@@ -89,7 +89,7 @@ public:
* )
*
*/
void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) {
void P2P(FList<ParticuleClass*>* const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) {
typename FList<ParticuleClass*>::BasicIterator iterTarget(*currentBox);
while( iterTarget.isValide() ){
for(int idxDirectNeighbors = 0 ; idxDirectNeighbors < size ; ++idxDirectNeighbors){
......
......@@ -287,7 +287,7 @@ public:
* )
*
*/
void P2P(FList<ParticuleClass*>* const currentBox, const FList<ParticuleClass*>*const* directNeighbors, const int size) {
void P2P(FList<ParticuleClass*>* const FRestrict currentBox, const FList<ParticuleClass*>* FRestrict const* FRestrict directNeighbors, const int size) {
typename FList<ParticuleClass*>::BasicIterator iterTarget(*currentBox);
while( iterTarget.isValide() ){
......
......@@ -82,7 +82,7 @@ public:
return *this;
}
/** Inc real and imaginary by doubles
/** Inc real and imaginary by values
* @param inIncReal to inc the real
* @param inIncImag to inc the imag
*/
......
......@@ -22,7 +22,17 @@
// Types
///////////////////////////////////////////////////////
typedef double FReal;
typedef float FReal;
///////////////////////////////////////////////////////
// Restrict
///////////////////////////////////////////////////////
#ifdef WINDOWS
#define FRestrict __restrict
#else
#define FRestrict __restrict__
#endif
#endif //FGLOBAL_HPP
......@@ -29,8 +29,8 @@
*/
class FTic {
private:
FReal start; //< start time (tic)
FReal end; //< stop time (tac)
double start; //< start time (tic)
double end; //< stop time (tac)
public:
/** Constructor */
......@@ -49,7 +49,7 @@ public:
/** Return end - start
* @return the time elapsed between tic & tac in second */
FReal elapsed() const{
double elapsed() const{
return this->end - this->start;
}
......@@ -58,9 +58,9 @@ public:
* GetTickCount on windows
* gettimeofday on linux
*/
static FReal GetTime(){
static double GetTime(){
#ifdef WINDOWS
return static_cast<FReal>(GetTickCount())/1000.0;
return static_cast<double>(GetTickCount())/1000.0;
#else
timeval t;
gettimeofday(&t, NULL);
......
......@@ -27,7 +27,7 @@
#include "../Sources/Files/FFMALoader.hpp"
// Compile by : g++ testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -O2 -o testFmbAlgorithm.exe
// g++ testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -lgomp -fopenmp -O2 -o testFmbAlgorithm.exe
// With openmp : g++ testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -lgomp -fopenmp -O2 -o testFmbAlgorithm.exe
/** This program show an example of use of
* the fmm basic algo
......@@ -99,8 +99,8 @@ int main(int , char ** ){
//FFmbKernelsPotentialForces FFmbKernelsForces FFmbKernelsPotential
FFmbKernelsPotentialForces<FmbParticule, FmbCell> kernels(NbLevels,loader.getBoxWidth());
//FFMMAlgorithm FFMMAlgorithmThreaded FFMMAlgorithmThreadedInterval
FFMMAlgorithm<FFmbKernelsPotentialForces, FmbParticule, FmbCell, NbLevels, SizeSubLevels> algo(&tree,&kernels);
//FFMMAlgorithm FFMMAlgorithmThreaded
FFMMAlgorithmThreaded<FFmbKernelsPotentialForces, FmbParticule, FmbCell, NbLevels, SizeSubLevels> algo(&tree,&kernels);
algo.execute();
counter.tac();
......
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