Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 6489e64e authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille
Browse files

remove compilation errors due to changes in FTreeBuilder

parent ba195b06
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
// ==== CMAKE =====
// @FUSE_BLAS
// ================
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include "ScalFmmConfig.h"
#include "Files/FFmaGenericLoader.hpp"
#include "Kernels/Chebyshev/FChebCell.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "Kernels/Chebyshev/FChebSymKernel.hpp"
#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
#include "Utils/FParameters.hpp"
#include "Containers/FOctree.hpp"
#ifdef _OPENMP
#include "Core/FFmmAlgorithmThread.hpp"
#else
#include "Core/FFmmAlgorithm.hpp"
#endif
#include "Utils/FTemplate.hpp"
/**
* This program runs the FMM Algorithm with the Chebyshev kernel and compares the results with a direct computation.
*/
/// \file ChebyshevInterpolationFMM.cpp
//!
//! \brief This program runs the FMM Algorithm with the interpolation kernel based on Chebyshev interpolation (1/r kernel)
//! \authors B. Bramas, O. Coulaud
//!
//! This code is a short example to use the Chebyshev Interpolation approach for the 1/r kernel
//!
//!@Algorithm
//! <b> General arguments:</b>
//! \param -help(-h) to see the parameters available in this driver
//! \param -depth The depth of the octree
//! \param -subdepth Specifies the size of the sub octree
//! \param -t The number of threads
//!
//! \param -f name Name of the particles file with extension (.fma or .bfma). The data in file have to be in our FMA format
//!
//
void usage() {
std::cout << "Driver for Chebyshev interpolation kernel (1/r kernel)" << std::endl;
std::cout << "Options "<< std::endl
<< " -help to see the parameters " << std::endl
<< " -depth the depth of the octree "<< std::endl
<< " -subdepth specifies the size of the sub octree " << std::endl
<< " -f name name specifies the name of the particle distribution" << std::endl
<< " -t n specifies the number of threads used in the computations" << std::endl;
}
// Simply create particles and try the kernels
struct TempMainStruct{
template <const unsigned int ORDER>
static void Run(int argc, char* argv[])
{
const std::string defaultFile(/*SCALFMMDataPath+*/"../Data/test20k.fma" );
const std::string filename = FParameters::getStr(argc,argv,"-f", defaultFile.c_str());
const unsigned int TreeHeight = FParameters::getValue(argc, argv, "-depth", 5);
const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, "-subdepth", 2);
const unsigned int NbThreads = FParameters::getValue(argc, argv, "-t", 1);
if(FParameters::existParameter(argc, argv, "-h")||FParameters::existParameter(argc, argv, "-help")){
usage() ;
exit(EXIT_SUCCESS);
}
#ifdef _OPENMP
omp_set_num_threads(NbThreads);
std::cout << "\n>> Using " << omp_get_max_threads() << " threads.\n" << std::endl;
#else
std::cout << "\n>> Sequential version.\n" << std::endl;
#endif
//
std::cout << "Parameters "<< std::endl
<< " Octree Depth "<< TreeHeight <<std::endl
<< " SubOctree depth " << SubTreeHeight <<std::endl
<< " Input file name: " <<filename <<std::endl
<< " Thread number: " << NbThreads <<std::endl
<<std::endl;
//
// init timer
FTic time;
// open particle file
////////////////////////////////////////////////////////////////////
//
FFmaGenericLoader loader(filename);
//
FSize nbParticles = loader.getNumberOfParticles() ;
FmaRWParticle<8,8>* const particles = new FmaRWParticle<8,8>[nbParticles];
loader.fillParticle(particles,nbParticles);
FReal energyD = 0.0 ;
/////////////////////////////////////////////////////////////////////////////////////////////////
// Compute direct energy
/////////////////////////////////////////////////////////////////////////////////////////////////
for(int idx = 0 ; idx < nbParticles ; ++idx){
energyD += particles[idx].getPotential()*particles[idx].getPhysicalValue() ;
}
//
////////////////////////////////////////////////////////////////////
// begin Chebyshev kernel
// accuracy
//const unsigned int ORDER = 7;
// typedefs
typedef FP2PParticleContainerIndexed<> ContainerClass;
typedef FSimpleLeaf< ContainerClass > LeafClass;
typedef FChebCell<ORDER> CellClass;
typedef FOctree<CellClass,ContainerClass,LeafClass> OctreeClass;
//
typedef FInterpMatrixKernelR MatrixKernelClass;
typedef FChebSymKernel<CellClass,ContainerClass,MatrixKernelClass,ORDER> KernelClass;
//
#ifdef _OPENMP
typedef FFmmAlgorithmThread<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
#else
typedef FFmmAlgorithm<OctreeClass,CellClass,ContainerClass,KernelClass,LeafClass> FmmClass;
#endif
// init oct-tree
OctreeClass tree(TreeHeight, SubTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());
{ // -----------------------------------------------------
std::cout << "Creating & Inserting " << loader.getNumberOfParticles()
<< " particles ..." << std::endl;
std::cout << "\tHeight : " << TreeHeight << " \t sub-height : " << SubTreeHeight << std::endl;
time.tic();
//
FPoint position;
FReal physicalValue = 0.0;
//
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
//
// Read particle per particle from file
//
// put particle in octree
tree.insert(particles[idxPart].getPosition() , idxPart, particles[idxPart].getPhysicalValue() );
}
time.tac();
std::cout << "Done " << "(@Creating and Inserting Particles = "
<< time.elapsed() << " s) ." << std::endl;
} // -----------------------------------------------------
{ // -----------------------------------------------------
std::cout << "\nChebyshev FMM (ORDER="<< ORDER << ") ... " << std::endl;
const MatrixKernelClass matrixClass;
time.tic();
//
KernelClass kernels(TreeHeight, loader.getBoxWidth(), loader.getCenterOfBox(),&matrixClass);
//
FmmClass algorithm(&tree, &kernels);
//
algorithm.execute(); // Here the call of the FMM algorithm
//
time.tac();
std::cout << "Done " << "(@Algorithm = " << time.elapsed() << " s) ." << std::endl;
}
// -----------------------------------------------------
//
// Some output
//
//
{ // -----------------------------------------------------
FReal energy =0.0;
//
// Loop over all leaves
//
std::cout <<std::endl<<" &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& "<<std::endl;
std::cout << std::scientific;
std::cout.precision(10) ;
/////////////////////////////////////////////////////////////////////////////////////////////////
// Compare
/////////////////////////////////////////////////////////////////////////////////////////////////
printf("Compute Diff...");
FMath::FAccurater potentialDiff;
FMath::FAccurater fx, fy, fz, f;
{ // Check that each particle has been summed with all other
tree.forEachLeaf([&](LeafClass* leaf){
const FReal*const potentials = leaf->getTargets()->getPotentials();
const FReal*const physicalValues = leaf->getTargets()->getPhysicalValues();
const FReal*const forcesX = leaf->getTargets()->getForcesX();
const FReal*const forcesY = leaf->getTargets()->getForcesY();
const FReal*const forcesZ = leaf->getTargets()->getForcesZ();
const int nbParticlesInLeaf = leaf->getTargets()->getNbParticles();
const FVector<int>& indexes = leaf->getTargets()->getIndexes();
for(int idxPart = 0 ; idxPart < nbParticlesInLeaf ; ++idxPart){
const int indexPartOrig = indexes[idxPart];
potentialDiff.add(particles[indexPartOrig].getPotential(),potentials[idxPart]);
fx.add(particles[indexPartOrig].getForces()[0],forcesX[idxPart]);
fy.add(particles[indexPartOrig].getForces()[1],forcesY[idxPart]);
fz.add(particles[indexPartOrig].getForces()[2],forcesZ[idxPart]);
f.add(particles[indexPartOrig].getForces()[0],forcesX[idxPart]);
f.add(particles[indexPartOrig].getForces()[1],forcesY[idxPart]);
f.add(particles[indexPartOrig].getForces()[2],forcesZ[idxPart]);
energy += potentials[idxPart]*physicalValues[idxPart];
}
});
}
std::cout << energy << " " << energyD << std::endl;
delete[] particles;
f.setNbElements(nbParticles);
std::cout << "FChebSymKernel Energy " << FMath::Abs(energy-energyD) << " Relative "<< FMath::Abs(energy-energyD) / FMath::Abs(energyD) <<std::endl;
std::cout << "FChebSymKernel Potential " << potentialDiff << std::endl;
std::cout << "FChebSymKernel Fx " << fx << std::endl;
std::cout << "FChebSymKernel Fy " << fy << std::endl;
std::cout << "FChebSymKernel Fz " << fz << std::endl;
std::cout << "FChebSymKernel F " << f << std::endl;
}
// -----------------------------------------------------
//return 0;
}
};
int main(int argc, char** argv){
const unsigned int order = FParameters::getValue(argc, argv, "-order", 5);
std::cout << "Order given by user is : " << order << "\n";
FRunIf::Run<unsigned int, 2, 13, 1, TempMainStruct>(order, argc, argv);
return 0;
}
......@@ -214,13 +214,21 @@ int main(int argc, char** argv){
paraSort.tac();
std::cout << "Time needed for FMpiTreeBuilder part : "<< paraSort.elapsed() << " secondes !" << std::endl;
ContainerClass parts;
parts.reserve(finalParticles.getSize());
//Convert ouput of DistributeArrayToContainer to a ContainerClass
for(int idxPart = 0; idxPart < finalParticles.getSize(); ++idxPart){
parts.push(finalParticles[idxPart].getPosition(),finalParticles[idxPart].getPhysicalValue());
}
FTic treeBuilder;
treeBuilder.tic();
FTreeBuilder<FmaRWParticle<4,4>,OctreeClass,LeafClass>::BuildTreeFromArray(finalParticles,finalParticles.getSize(),&tree,true);
FTreeBuilder<OctreeClass,LeafClass>::BuildTreeFromArray(&tree,parts,true);
treeBuilder.tac();
std::cout << "Time needed for TreeBuilder : "<< treeBuilder.elapsed() << " secondes !" << std::endl;
#define CHECK_TREE
//Check the datas
#ifdef CHECK_TREE
......
......@@ -4,13 +4,13 @@
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
......@@ -41,6 +41,7 @@
#include "../../Src/Files/FMpiFmaGenericLoader.hpp"
#include "../../Src/Files/FMpiTreeBuilder.hpp"
#include "../../Src/Files/FTreeBuilder.hpp"
#include "../../Src/BalanceTree/FLeafBalance.hpp"
......@@ -50,10 +51,10 @@
// Simply create particles and try the kernels
int main(int argc, char ** argv){
FHelpDescribeAndExit(argc, argv,
"Test Spherical HArmonic kernel with blas.",
FParameterDefinitions::InputFile, FParameterDefinitions::OctreeHeight,
FParameterDefinitions::OctreeSubHeight, FParameterDefinitions::SHDevelopment,
FParameterDefinitions::NbThreads);
"Test Spherical HArmonic kernel with blas.",
FParameterDefinitions::InputFile, FParameterDefinitions::OctreeHeight,
FParameterDefinitions::OctreeSubHeight, FParameterDefinitions::SHDevelopment,
FParameterDefinitions::NbThreads);
typedef FSphericalCell CellClass;
typedef FP2PParticleContainer<> ContainerClass;
......@@ -92,8 +93,8 @@ int main(int argc, char ** argv){
}
CellClass::Init(DevP,true);
OctreeClass tree(NbLevels, SizeSubLevels,loader.getBoxWidth(),loader.getCenterOfBox());
// -----------------------------------------------------
......@@ -127,22 +128,32 @@ int main(int argc, char ** argv){
FVector<TestParticle> finalParticles;
FLeafBalance balancer;
// FMpiTreeBuilder< TestParticle >::ArrayToTree(app.global(), particles, loader.getNumberOfParticles(),
// tree.getBoxCenter(),
// tree.getBoxWidth(),
// tree.getHeight(), &finalParticles,&balancer);
FMpiTreeBuilder< TestParticle >::DistributeArrayToContainer(app.global(),particles,
// tree.getBoxCenter(),
// tree.getBoxWidth(),
// tree.getHeight(), &finalParticles,&balancer);
FMpiTreeBuilder< TestParticle >::DistributeArrayToContainer(app.global(),particles,
loader.getMyNumberOfParticles(),
tree.getBoxCenter(),
tree.getBoxWidth(),tree.getHeight(),
&finalParticles, &balancer);
for(int idx = 0 ; idx < finalParticles.getSize(); ++idx){
tree.insert(finalParticles[idx].position,finalParticles[idx].physicalValue);
ContainerClass parts;
parts.reserve(finalParticles.getSize());
//Convert ouput of DistributeArrayToContainer to a ContainerClass
for(int idxPart = 0; idxPart < finalParticles.getSize(); ++idxPart){
parts.push(finalParticles[idxPart].getPosition(),finalParticles[idxPart].physicalValue);
}
delete[] particles;
FTreeBuilder<OctreeClass,LeafClass>::BuildTreeFromArray(&tree,parts,true);
// for(int idx = 0 ; idx < finalParticles.getSize(); ++idx){
// tree.insert(finalParticles[idx].position,finalParticles[idx].physicalValue);
// }
delete[] particles;
counter.tac();
std::cout << "Done " << "(" << counter.elapsed() << "s)." << std::endl;
......@@ -213,4 +224,3 @@ int main(int argc, char ** argv){
}
return 0;
}
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstdio>
#include "ScalFmmConfig.h"
#include "Files/FFmaGenericLoader.hpp"
#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
#include "../../Src/Kernels/P2P/FP2PParticleContainer.hpp"
#include "../../Src/Kernels/Rotation/FRotationKernel.hpp"
#include "../../Src/Kernels/Rotation/FRotationCell.hpp"
#include "../Src/BalanceTree/FLeafBalance.hpp"
#include "../Src/Files/FTreeBuilder.hpp"
#include "../Src/Containers/FTreeCoordinate.hpp"
#include "Utils/FTic.hpp"
#include "Utils/FQuickSort.hpp"
#include "Utils/FParameters.hpp"
#include "../../Src/Utils/FParameterNames.hpp"
#include "Containers/FOctree.hpp"
#ifdef _OPENMP
#include "Core/FFmmAlgorithmThread.hpp"
#else
#include "Core/FFmmAlgorithm.hpp"
#endif
#include "Utils/FTemplate.hpp"
/** This method has been tacken from the octree
* it computes a tree coordinate (x or y or z) from real position
*/
static int getTreeCoordinate(const FReal inRelativePosition, const FReal boxWidthAtLeafLevel) {
const FReal indexFReal = inRelativePosition / boxWidthAtLeafLevel;
const int index = int(FMath::dfloor(indexFReal));
if( index && FMath::LookEqual(inRelativePosition, boxWidthAtLeafLevel * FReal(index) ) ){
return index - 1;
}
return index;
}
/**
* This program build a tree and insert the parts inside.
* Time needed for the insert is outputed
*
*/
int main(int argc, char** argv){
struct TestParticle{
MortonIndex index;
FSize indexInFile;
FPoint position;
FReal physicalValue;
const FPoint& getPosition()const{
return position;
}
TestParticle& operator=(const TestParticle& other){
index=other.index;
indexInFile=other.indexInFile;
position=other.position;
physicalValue=other.physicalValue;
return *this;
}
bool operator<=(const TestParticle& rhs)const{
if(rhs.index < this->index){return false;}
else{
if(rhs.index > this->index){return true;}
else{
if(rhs.indexInFile == this->indexInFile){
return true;
}
else {
return rhs.indexInFile> this->indexInFile ;
}
}
}
}
};
static const int P = 9;
typedef FRotationCell<P> CellClass;
typedef FP2PParticleContainer<> ContainerClass;
typedef FSimpleLeaf< ContainerClass > LeafClass;
typedef FOctree< CellClass, ContainerClass , LeafClass > OctreeClass;
//typedef FRotationKernel< CellClass, ContainerClass , P> KernelClass;
//typedef FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClassThread;
const int NbLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
const int SizeSubLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
const char* const filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
const unsigned int NbThreads = FParameters::getValue(argc, argv, FParameterDefinitions::NbThreads.options, omp_get_max_threads());
omp_set_num_threads(NbThreads);
std::cout << "Using " << omp_get_max_threads() <<" threads" << std::endl;
std::cout << "Opening : " << filename << "\n";
FFmaGenericLoader loaderRef(filename);
if(!loaderRef.isOpen()){
std::cout << "LoaderRef Error, " << filename << " is missing\n";
return 1;
}
FTic regInsert;
// -----------------------------------------------------
{
OctreeClass treeRef(NbLevels, SizeSubLevels, loaderRef.getBoxWidth(), loaderRef.getCenterOfBox());
std::cout << "Creating & Inserting " << loaderRef.getNumberOfParticles() << " particles ..." << std::endl;
std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
regInsert.tic();
for(int idxPart = 0 ; idxPart < loaderRef.getNumberOfParticles() ; ++idxPart){
FPoint particlePosition;
FReal physicalValue;
loaderRef.fillParticle(&particlePosition,&physicalValue);
treeRef.insert(particlePosition, physicalValue );
}
regInsert.tac();
std::cout << "Time needed for regular insert : " << regInsert.elapsed() << " secondes" << std::endl;
}
//Second solution, parts must be sorted for that
FFmaGenericLoader loader(filename);
if(!loader.isOpen()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
}
//Get the needed informations
FReal boxWidth = loader.getBoxWidth();
FReal boxWidthAtLeafLevel = boxWidth/FReal(1 << (NbLevels - 1));
FPoint centerOfBox = loader.getCenterOfBox();
FPoint boxCorner = centerOfBox - boxWidth/2;
FSize nbOfParticles = loader.getNumberOfParticles();
//Temporary TreeCoordinate
FTreeCoordinate host;
TestParticle * arrayOfParts = new TestParticle[nbOfParticles];
memset(arrayOfParts,0,sizeof(TestParticle)*nbOfParticles);
for(int idxPart = 0 ; idxPart < nbOfParticles ; ++idxPart){
loader.fillParticle(&arrayOfParts[idxPart].position,&arrayOfParts[idxPart].physicalValue);
//Build temporary TreeCoordinate
host.setX( getTreeCoordinate( arrayOfParts[idxPart].getPosition().getX() - boxCorner.getX(), boxWidthAtLeafLevel ));
host.setY( getTreeCoordinate( arrayOfParts[idxPart].getPosition().getY() - boxCorner.getY(), boxWidthAtLeafLevel ));
host.setZ( getTreeCoordinate( arrayOfParts[idxPart].getPosition().getZ() - boxCorner.getZ(), boxWidthAtLeafLevel ));
//Set Morton index from Tree Coordinate
arrayOfParts[idxPart].index = host.getMortonIndex(NbLevels - 1);
arrayOfParts[idxPart].indexInFile = idxPart;
}
//std::sort(arrayOfParts,&arrayOfParts[nbOfParticles-1]);
FQuickSort<TestParticle,MortonIndex>::QsOmp(arrayOfParts,nbOfParticles);
OctreeClass tree(NbLevels, SizeSubLevels, loaderRef.getBoxWidth(), loaderRef.getCenterOfBox());
//copy into a Container class
ContainerClass parts;
parts.reserve(nbOfParticles);
for(FSize idxPart = 0;idxPart<nbOfParticles;++idxPart){
parts.push(arrayOfParts[idxPart].getPosition(),arrayOfParts[idxPart].physicalValue);
}
FTreeBuilder<OctreeClass,LeafClass>::BuildTreeFromArray(&tree,parts,false);
return 0;
}
......@@ -215,13 +215,13 @@ class TestMpiTreeBuilder : public FUTesterMpi< class TestMpiTreeBuilder> {
int * toSend = new int[outputSize];
int * displ = nullptr;
int * recvParts = nullptr;
int * myPart = nullptr;
//Prepare the indexInFile to send
for(int idPart=0 ; idPart<outputSize ; ++idPart){
toSend[idPart] = int(outputArray[idPart].particle.indexInFile);
}
if(app.global().processId() == 0){
//There, we build the array of displacement
displ = new int[app.global().processCount()];
......@@ -234,7 +234,7 @@ class TestMpiTreeBuilder : public FUTesterMpi< class TestMpiTreeBuilder> {