Commit 3a7f8b0b authored by COULAUD Olivier's avatar COULAUD Olivier
parents 387a66e4 8fff82f4
......@@ -23,7 +23,7 @@
#include "../../Src/Components/FBasicKernels.hpp"
#ifdef SCALFMM_USE_MPI
#ifdef ScalFMM_USE_MPI
#include "../../Src/Utils/FMpi.hpp"
#endif
......@@ -283,7 +283,7 @@ struct ScalFmmCoreHandle {
int treeHeight; // hombre de niveaux de l'arbre (int)
FReal boxWidth; // taille de la boîte racine (FReal)
FReal boxCenter[3]; // position du centre de la boîte racine (FReal[3])
#ifdef SCALFMM_USE_MPI
#ifdef ScalFMM_USE_MPI
MPI_Comm mpiCom; // communicateur MPI (MPI_Comm)
#endif
int nbThreads; // nombre de threads (int)
......@@ -319,7 +319,7 @@ int FmmCore_isParameterUsed(void */*fmmCore*/, int *name, int *flag){
case FMMCORE_ROOT_BOX_WIDTH :
case FMMCORE_ROOT_BOX_CENTER :
case FMMCORE_TREE_HEIGHT :
#ifdef SCALFMM_USE_MPI
#ifdef ScalFMM_USE_MPI
case FMMCORE_MPI_COMMUNICATOR:
#endif
case FMMCORE_THREADS_NUMBER:
......@@ -358,7 +358,7 @@ int FmmCore_setParameter(void *fmmCore, int *name, void*value){
case FMMCORE_ROOT_BOX_CENTER :
memcpy(corehandle->config.boxCenter, value, sizeof(FReal)*3);
break;
#ifdef SCALFMM_USE_MPI
#ifdef ScalFMM_USE_MPI
case FMMCORE_MPI_COMMUNICATOR:
corehandle->config.mpiCom = *(MPI_Comm*)value;
break;
......@@ -403,7 +403,7 @@ int FmmCore_getParameter(void *fmmCore, int *name, void*value){
case FMMCORE_ROOT_BOX_CENTER :
memcpy(value,corehandle->config.boxCenter, sizeof(FReal)*3);
break;
#ifdef SCALFMM_USE_MPI
#ifdef ScalFMM_USE_MPI
case FMMCORE_MPI_COMMUNICATOR:
*(MPI_Comm*)value = corehandle->config.mpiCom;
break;
......
......@@ -29,7 +29,7 @@
*/
/**
* @brief This class is an arranger, it move the particles that need to be hosted in a different leaf.
* @brief This class is an arranger, it moves the particles that need to be hosted in a different leaf.
*
* For example, if a simulation has been executed and the position
* of the particles have been changed, then it may be better
......
......@@ -24,21 +24,34 @@
* This proposes an interface to save and restore a class.
*
* To make your container are usable in the mpi fmm, they must provide this interface.
* This class is mainly called by the Sendable classes in order to store the attributes.
*/
class FAbstractSerializable {
protected:
/**
* Should save all the native data into the buffer
*/
template <class BufferWriterClass>
void save(BufferWriterClass&) const{
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement save");
}
/**
* Should restore all the native data from the buffer
* Warning! It should be done in the same order! and with the same size!
*/
template <class BufferReaderClass>
void restore(BufferReaderClass&){
static_assert(sizeof(BufferReaderClass) == 0 , "Your class should implement restore");
}
static int GetSize(){
return 0;
}
/**
* @brief GetSize returns the size of the current block (in order to prepare the buffer)
* @return
*/
static int GetSize(){
return 0;
}
};
......
......@@ -16,6 +16,9 @@
#ifndef FPARTICLETYPE_HPP
#define FPARTICLETYPE_HPP
/**
* @brief The FParticleType enum is to make a difference between Target and Source (Tsm)
*/
enum FParticleType {
FParticleTypeSource = 0,
FParticleTypeTarget = 1
......
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// 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".
// ===================================================================================
#ifndef FABSTRACTBUFFER_HPP
#define FABSTRACTBUFFER_HPP
/**
* @brief The FAbstractBufferReader class defines what is an abstract buffer reader.
* The buffer used by the mpi algorithm for example should defines this methods.
*/
class FAbstractBufferReader {
public:
virtual ~FAbstractBufferReader(){
}
virtual char* data() = 0;
virtual const char* data() const = 0;
virtual int getSize() const = 0;
virtual void seek(const int inIndex) = 0;
virtual int tell() const = 0;
virtual char* data() = 0;
virtual const char* data() const = 0;
virtual int getSize() const = 0;
virtual void seek(const int inIndex) = 0;
virtual int tell() const = 0;
template <class ClassType>
ClassType getValue(){
......@@ -33,16 +52,19 @@ public:
};
/**
* @brief The FAbstractBufferWriter class defines what is an abstract buffer writer.
* The buffer used by the mpi algorithm for example should defines this methods.
*/
class FAbstractBufferWriter {
public:
virtual ~FAbstractBufferWriter(){
}
virtual char* data() = 0;
virtual char* data() = 0;
virtual const char* data() const = 0;
virtual int getSize() const = 0;
virtual void reset() = 0;
virtual int getSize() const = 0;
virtual void reset() = 0;
template <class ClassType>
void write(const ClassType& object){
......
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// 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".
// ===================================================================================
#ifndef FBLOCKALLOCATOR_HPP
#define FBLOCKALLOCATOR_HPP
......
......@@ -19,7 +19,7 @@
#include <memory>
#include "../Utils/FMpi.hpp"
#include "FAbstractBuffer.hpp"
#include "../Utils/FAssert.hpp"
/** @author Cyrille Piacibello
* This class provide the same features as FBufferWriter using MPI_Pack system
......@@ -40,8 +40,9 @@ public :
comm(inComm),
arrayCapacity(inCapacity),
array(new char[inCapacity]),
currentIndex(0)
{}
currentIndex(0){
FAssertLF(array, "Cannot allocate array");
}
/** Destructor
*/
......@@ -70,13 +71,8 @@ public :
/** Move the read index to a position */
void seek(const int inIndex){
if(inIndex > arrayCapacity){
printf("FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough");
exit(0);
}
else{
currentIndex = inIndex;
}
FAssertLF(inIndex < arrayCapacity, "FMpiBufferReader :: Aborting :: Can't move index because buffer isn't long enough");
currentIndex = inIndex;
}
/** Get the read position */
......
......@@ -19,6 +19,7 @@
#include <memory>
#include "../Utils/FMpi.hpp"
#include "FAbstractBuffer.hpp"
#include "../Utils/FAssert.hpp"
/** @author Cyrille Piacibello
* This class provide the same features as FBufferWriter using MPI_Pack system
......@@ -35,10 +36,7 @@ class FMpiBufferWriter : public FAbstractBufferWriter {
/** Test and exit if not enought space */
void assertRemainingSpace(const size_t requestedSpace) const {
if(int(currentIndex + requestedSpace) > arrayCapacity){
printf("Error FMpiBufferWriter has not enough space\n");
exit(0);
}
FAssertLF(int(currentIndex + requestedSpace) <= arrayCapacity, "Error FMpiBufferWriter has not enough space");
}
public:
......@@ -93,10 +91,7 @@ public:
/** Write back, position + sizeof(object) has to be < size */
template <class ClassType>
void writeAt(const int position, const ClassType& object){
if(position + (int) sizeof(ClassType) > currentIndex){
printf("Not enought space\n");
exit(0);
}
FAssertLF(int(position + sizeof(ClassType)) <= currentIndex)
int noConstPosition = position;
MPI_Pack(const_cast<ClassType*>(&object), 1, FMpi::GetType(object), array.get(), arrayCapacity, &noConstPosition, mpiComm);
}
......
......@@ -94,8 +94,10 @@ class FOctree : public FNoCopyable {
* @return the box num at the leaf level that contains inRelativePosition
*/
int getTreeCoordinate(const FReal inRelativePosition) const {
FAssertLF( (inRelativePosition >= 0 && inRelativePosition < this->boxWidth), "inRelativePosition : ",inRelativePosition );
FAssertLF( inRelativePosition >= 0 && inRelativePosition < this->boxWidth, "Particle out of box" );
FAssertLF( (inRelativePosition >= 0 && inRelativePosition <= this->boxWidth), "inRelativePosition : ",inRelativePosition );
if(inRelativePosition == this->boxWidth){
return FMath::pow2(height-1)-1;
}
const FReal indexFReal = inRelativePosition / this->boxWidthAtLevel[this->leafIndex];
return static_cast<int>(indexFReal);
}
......
This diff is collapsed.
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// 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".
// ===================================================================================
#ifndef FFMABINLOADERRESULT_HPP
#define FFMABINLOADERRESULT_HPP
#include "./FFmaBinLoader.hpp"
/**
* @author Cyrille Piacibello (cyrille.piacibello@inria.fr)
* @class FFmaBinLoaderResult
*
* Please read the license
*
* @brief The aim of this class is to load particles and forces from a
* file, to compare with results from any Fmm Kernel.
*/
class FFmaBinLoaderResult : public FFmaBinLoader {
protected:
typedef FFmaBinLoader Parent;
size_t removeWarning;
public:
FFmaBinLoaderResult(const char * filename):
Parent::FFmaBinLoader(filename)
{
}
void fillParticle(FPoint*const inParticlePosition, FReal*const physicalValue, FReal* forceX, FReal* forceY, FReal* forceZ, FReal * const potential){
FReal x,y,z,data,fx,fy,fz,pot;
//Same datas as particle files
removeWarning += fread(&x, sizeof(FReal), 1, file);
removeWarning += fread(&y, sizeof(FReal), 1, file);
removeWarning += fread(&z, sizeof(FReal), 1, file);
removeWarning += fread(&data, sizeof(FReal), 1, file);
//results datas
removeWarning += fread(&fx, sizeof(FReal), 1, file);
removeWarning += fread(&fy, sizeof(FReal), 1, file);
removeWarning += fread(&fz, sizeof(FReal), 1, file);
removeWarning += fread(&pot, sizeof(FReal), 1, file);
//return
inParticlePosition->setPosition(x,y,z);
(*physicalValue) = data;
*forceX = fx;
*forceY = fy;
*forceZ = fz;
*potential = pot;
}
};
#endif //FFMABINLOADERRESULT_HPP
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// 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".
// ===================================================================================
#ifndef FALIGNEDMEMORY_HPP
#define FALIGNEDMEMORY_HPP
/**
* This should be used to allocate and deallocate aligned memory.
*/
namespace FAlignedMemory {
/**
* @brief Allocate16BAligned
* @param inSize in Bytes
* @return the address of the allocated block of size inSize
*/
inline void* Allocate16BAligned(const size_t inSize){
unsigned char* memoryBlock = new unsigned char[inSize + 15 + 16];
{
......@@ -12,20 +35,24 @@ inline void* Allocate16BAligned(const size_t inSize){
return reinterpret_cast<void*>( (reinterpret_cast<long long int>(memoryBlock) + 16 + 15) & ~0xFLL);
}
/**
* Allocate an array of inNbElements elements of type ObjectType.
* The objects are not initialized!
*/
template <class ObjectType>
inline ObjectType* AllocateType16BAligned(const int inNbElements){
return reinterpret_cast<ObjectType*>(Allocate16BAligned(sizeof(ObjectType) * inNbElements));
}
/** delete a block allocated with allocate16BAligned
*/
/**
* Delete a block allocated with allocate16BAligned
*/
inline void Dealloc16BAligned(const void*const memoryBlock){
if( memoryBlock ){
const unsigned char*const* storeRealAddress = reinterpret_cast<const unsigned char*const *>(reinterpret_cast<const unsigned char*>(memoryBlock) - 16);
delete[] reinterpret_cast<const unsigned char*>(*storeRealAddress);
}
}
}
......
......@@ -63,7 +63,7 @@ public:
}
};
#ifdef SCALFMM_USE_ASSERT
#ifdef ScalFMM_USE_ASSERT
//////////////////////////////////////////////////////////////
// Sp error activated
......
......@@ -24,5 +24,5 @@ FLog FLog::Controller;
#endif // SCALFMM_USE_DEBUG
#endif // ScalFMM_USE_DEBUG
......@@ -179,7 +179,7 @@ public:
};
#endif //SCALFMM_USE_DEBUG
#endif //ScalFMM_USE_DEBUG
#endif //FDEBUG_HPP
......
......@@ -19,7 +19,7 @@ FMemStats FMemStats::controler;
#include <cstdio>
#ifdef SCALFMM_USE_MEM_STATS
#ifdef ScalFMM_USE_MEM_STATS
// Regular scalar new
void* operator new(std::size_t n) throw(std::bad_alloc)
{
......
......@@ -27,7 +27,7 @@
* and give simple stats like max, total used, current used
*/
#ifdef SCALFMM_USE_MEM_STATS
#ifdef ScalFMM_USE_MEM_STATS
#include <new>
#include <stdexcept>
#warning You are using meme stats
......@@ -67,7 +67,7 @@ private:
currentAllocated -= size;
}
#ifdef SCALFMM_USE_MEM_STATS
#ifdef ScalFMM_USE_MEM_STATS
friend void* operator new(std::size_t n) throw(std::bad_alloc);
friend void* operator new(size_t n, std::nothrow_t const&) throw();
friend void* operator new[](size_t n) throw(std::bad_alloc);
......@@ -114,7 +114,7 @@ public:
/** To know if mem stat has been enabled */
bool isUsed() const {
#ifdef SCALFMM_USE_MEM_STATS
#ifdef ScalFMM_USE_MEM_STATS
return true;
#else
return false;
......
......@@ -14,12 +14,12 @@
// "http://www.gnu.org/licenses".
// ===================================================================================
#include "FTrace.hpp"
#ifdef SCALFMM_USE_TRACE
#ifdef ScalFMM_USE_TRACE
#if !defined (SCALFMM_USE_ITAC) && !defined (SCALFMM_USE_EZTRACE)
#if !defined (ScalFMM_USE_ITAC) && !defined (ScalFMM_USE_EZTRACE)
int FTrace::Deep = 0;
FTic FTrace::TimeSinceBegining;
#endif
#endif // SCALFMM_USE_TRACE
#endif // ScalFMM_USE_TRACE
......@@ -34,7 +34,7 @@
* </code>
*/
#ifndef SCALFMM_USE_TRACE
#ifndef ScalFMM_USE_TRACE
#define FTRACE( X )
......@@ -56,7 +56,7 @@
#define FTRACE( X ) X
#ifdef SCALFMM_USE_ITAC
#ifdef ScalFMM_USE_ITAC
#include <VT.h>
......@@ -85,7 +85,7 @@
};
#else
#ifdef SCALFMM_USE_EZTRACE
#ifdef ScalFMM_USE_EZTRACE
#include <eztrace.h>
......@@ -219,11 +219,11 @@
friend class FFunction;
};
#endif //SCALFMM_USE_EZTRACE
#endif //ScalFMM_USE_EZTRACE
#endif //SCALFMM_USE_ITAC
#endif //ScalFMM_USE_ITAC
#endif //SCALFMM_USE_TRACE
#endif //ScalFMM_USE_TRACE
#endif //FTRACE_HPP
......
......@@ -17,7 +17,7 @@
/**
* In this file we show how to use the debug module.
* Warning, in FGlobal.hpp (included in FLog.hpp) SCALFMM_USE_DEBUG might be undefined.
* Warning, in FGlobal.hpp (included in FLog.hpp) ScalFMM_USE_DEBUG might be undefined.
*/
int main(void){
......
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// 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".
// ===================================================================================
/**
*@author Cyrille Piacibello
*
* This exec will be used to store the result of direct computation in
* Binary Files. Then, a kernel (Chebyshev) is called on the same file, and
* results are compared.
*
* Format of result file :
* Each data is a FReal : posX,posY,posZ,physicalValue,forceX,forceY,forceZ,potential
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "ScalFmmConfig.h"
#include "../../Src/Utils/FTic.hpp"
#include "../../Src/Utils/FParameters.hpp"
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
#include "../../Src/Kernels/P2P/FP2P.hpp"
#include "../../Src/Kernels/P2P/FP2PParticleContainerIndexed.hpp"
#include "../../Src/Files/FFmaBinLoader.hpp"
#include "../../Src/Files/FFmaBinLoaderResult.hpp"
#include "../../Src/Utils/FTic.hpp"
#include "../../Src/Kernels/Chebyshev/FChebCell.hpp"
#include "../../Src/Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "../../Src/Kernels/Chebyshev/FChebKernel.hpp"
#include "../../Src/Kernels/Chebyshev/FChebSymKernel.hpp"
#include "../../Src/Core/FFmmAlgorithm.hpp"
int main(int argc, char* argv[])
{
// get info from commandline
const char* const defaultFilename = (sizeof(FReal) == sizeof(float))?
"../Data/test20k.bin.fma.single":
"../Data/test20k.bin.fma.double";
const char* const filename = FParameters::getStr(argc,argv,"-f", defaultFilename);
const char* const fileresult = FParameters::getStr(argc,argv,"-fr","../Data/test20k.bin.fma.double.result");;
//For Fmm Computation
const unsigned int TreeHeight = FParameters::getValue(argc, argv, "-h", 5);
const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, "-sh", 2);
FTic time;
struct TestParticle{
FPoint position;
FReal forces[3];
FReal physicalValue;
FReal potential;
};
printf("Input is %s, \n Results will be stored in %s \n",filename,fileresult);
{
//First Part
//Direct Computation and Storage of result
//open particle file
FFmaBinLoader loader(filename);
if(!loader.isOpen()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
}
time.tic();
TestParticle* const particles = new TestParticle[loader.getNumberOfParticles()];
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
FPoint position;
FReal physicalValue = 0.0;
loader.fillParticle(&position,&physicalValue);
// get copy
particles[idxPart].position = position;
particles[idxPart].physicalValue = physicalValue;
particles[idxPart].potential = 0.0;
particles[idxPart].forces[0] = 0.0;
particles[idxPart].forces[1] = 0.0;
particles[idxPart].forces[2] = 0.0;
}
time.tac();
printf("Elapsed Time for Loading %lld particles from File: \t %f\n",loader.getNumberOfParticles(),time.elapsed());
//Direct Computation
time.tic();
for(int idxTarget = 0 ; idxTarget < loader.getNumberOfParticles() ; ++idxTarget){
for(int idxOther = idxTarget + 1 ; idxOther < loader.getNumberOfParticles() ; ++idxOther){
FP2P::MutualParticles(particles[idxTarget].position.getX(), particles[idxTarget].position.getY(),
particles[idxTarget].position.getZ(),particles[idxTarget].physicalValue,
&particles[idxTarget].forces[0],&particles[idxTarget].forces[1],
&particles[idxTarget].forces[2],&particles[idxTarget].potential,
particles[idxOther].position.getX(), particles[idxOther].position.getY(),
particles[idxOther].position.getZ(),particles[idxOther].physicalValue,
&particles[idxOther].forces[0],&particles[idxOther].forces[1],
&particles[idxOther].forces[2],&particles[idxOther].potential);
}
}
time.tac();
printf("Elapsed Time for Direct Computation: \t %f\n",time.elapsed());
//Write results in output file
FILE * fd = fopen(fileresult,"w");
//Size of elements to be written
int realSize = sizeof(FReal);
FSize nbPart = loader.getNumberOfParticles();
FReal boxWidth = loader.getBoxWidth() / 2;
FReal centerX = loader.getCenterOfBox().getX();
FReal centerY = loader.getCenterOfBox().getY();
FReal centerZ = loader.getCenterOfBox().getZ();
fwrite(&realSize, sizeof(int), 1, fd);
fwrite(&nbPart, sizeof(FSize), 1, fd);
fwrite(&boxWidth, sizeof(FReal), 1, fd);
fwrite(&centerX, sizeof(FReal), 1, fd);
fwrite(&centerY, sizeof(FReal), 1, fd);
fwrite(&centerZ, sizeof(FReal), 1, fd);
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart)
{
fwrite( particles[idxPart].position.getDataValue(),realSize,3,fd);
fwrite(&particles[idxPart].physicalValue, realSize,1,fd);