Commit 5498145d authored by BRAMAS Berenger's avatar BRAMAS Berenger

clean some code and add comments

parent fc4fae17
......@@ -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);
}
......
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 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);
}
}
}
......
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