Commit 805fadda authored by BRAMAS Berenger's avatar BRAMAS Berenger

Really split the symb from the data of the particles

parent cc21eddf
......@@ -13,7 +13,7 @@
* The idea is to hidde the group allocation from the group tree but
* to keep the same interface than the FBasicParticlesContainer.
*/
template <unsigned NbAttributesPerParticle, class AttributeClass = FReal>
template <unsigned NbSymbAttributes, unsigned NbAttributesPerParticle, class AttributeClass = FReal>
class FGroupAttachedLeaf {
protected:
//< Nb of particles in the current leaf
......@@ -21,13 +21,13 @@ protected:
//< Pointers to the positions of the particles
FReal* positionsPointers[3];
//< Pointers to the attributes of the particles
AttributeClass* attributes[NbAttributesPerParticle];
AttributeClass* attributes[NbSymbAttributes+NbAttributesPerParticle];
public:
/** Empty constructor to point to nothing */
FGroupAttachedLeaf() : nbParticles(-1) {
memset(positionsPointers, 0, sizeof(FReal*) * 3);
memset(attributes, 0, sizeof(AttributeClass*) * NbAttributesPerParticle);
memset(attributes, 0, sizeof(AttributeClass*) * (NbSymbAttributes+NbAttributesPerParticle));
}
/**
......@@ -46,14 +46,19 @@ public:
positionsPointers[1] = reinterpret_cast<FReal*>(reinterpret_cast<unsigned char*>(inPositionBuffer) + inLeadingPosition);
positionsPointers[2] = reinterpret_cast<FReal*>(reinterpret_cast<unsigned char*>(inPositionBuffer) + inLeadingPosition*2);
unsigned char* symAttributes = reinterpret_cast<unsigned char*>(reinterpret_cast<unsigned char*>(inPositionBuffer) + inLeadingPosition*3);
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes ; ++idxAttribute){
attributes[idxAttribute] = reinterpret_cast<AttributeClass*>(symAttributes + idxAttribute*inLeadingAttributes);
}
// Redirect pointers to data
if(inAttributesBuffer){
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = reinterpret_cast<AttributeClass*>(reinterpret_cast<unsigned char*>(inAttributesBuffer) + idxAttribute*inLeadingAttributes);
attributes[idxAttribute+NbSymbAttributes] = reinterpret_cast<AttributeClass*>(reinterpret_cast<unsigned char*>(inAttributesBuffer) + idxAttribute*inLeadingAttributes);
}
}
else{
memset(attributes, 0, sizeof(AttributeClass*)*NbAttributesPerParticle);
memset(&attributes[NbSymbAttributes], 0, sizeof(AttributeClass*)*NbAttributesPerParticle);
}
}
......@@ -64,7 +69,7 @@ public:
positionsPointers[2] = other.positionsPointers[2];
// Redirect pointers to data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes+NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = other.attributes[idxAttribute];
}
}
......@@ -78,7 +83,7 @@ public:
positionsPointers[2] = other.positionsPointers[2];
// Redirect pointers to data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes+NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = other.attributes[idxAttribute];
}
......@@ -132,7 +137,7 @@ public:
*/
template <int index>
AttributeClass* getAttribute() {
static_assert(index < NbAttributesPerParticle, "Index to get attributes is out of scope.");
static_assert(index < NbSymbAttributes+NbAttributesPerParticle, "Index to get attributes is out of scope.");
return attributes[index];
}
......@@ -141,7 +146,7 @@ public:
*/
template <int index>
const AttributeClass* getAttribute() const {
static_assert(index < NbAttributesPerParticle, "Index to get attributes is out of scope.");
static_assert(index < NbSymbAttributes+NbAttributesPerParticle, "Index to get attributes is out of scope.");
return attributes[index];
}
......@@ -160,7 +165,7 @@ public:
memcpy(positionsPointers[2], particles->getPositions()[2] + offsetInSrcContainer, nbParticles*sizeof(FReal));
// Copy data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes+NbAttributesPerParticle ; ++idxAttribute){
memcpy(attributes[idxAttribute], particles->getAttribute(idxAttribute) + offsetInSrcContainer, nbParticles*sizeof(AttributeClass));
}
}
......@@ -175,7 +180,7 @@ public:
positionsPointers[2][destPartIdx] = particles->getPositions()[2][srcPartIdx];
// Copy data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes+NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute][destPartIdx] = particles->getAttribute(idxAttribute)[srcPartIdx];
}
}
......
......@@ -17,7 +17,7 @@
/**
* @brief The FGroupOfParticles class manages the leaves in block allocation.
*/
template <unsigned NbAttributesPerParticle, class AttributeClass = FReal>
template <unsigned NbSymbAttributes, unsigned NbAttributesPerParticle, class AttributeClass = FReal>
class FGroupOfParticles {
/** One header is allocated at the beginning of each block */
struct alignas(FStarPUDefaultAlign::StructAlign) BlockHeader{
......@@ -79,7 +79,7 @@ protected:
//< Pointers to the particles data inside the block memory
AttributeClass* attributesBuffer;
AttributeClass* particleAttributes[NbAttributesPerParticle];
AttributeClass* particleAttributes[NbSymbAttributes+NbAttributesPerParticle];
/** To know if we have to delete the buffer */
bool deleteBuffer;
......@@ -109,10 +109,15 @@ public:
// Redirect pointer to data
blockHeader->attributeOffset = (sizeof(AttributeClass) * blockHeader->nbParticlesAllocatedInGroup);
AttributeClass* symAttributes = (AttributeClass*)(&particlePosition[2][blockHeader->nbParticlesAllocatedInGroup]);
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes ; ++idxAttribute){
particleAttributes[idxAttribute] = symAttributes;
symAttributes += blockHeader->nbParticlesAllocatedInGroup;
}
if(inAttributes){
attributesBuffer = (AttributeClass*)inAttributes;
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
particleAttributes[idxAttribute] = &attributesBuffer[idxAttribute*(blockHeader->nbParticlesAllocatedInGroup/sizeof(AttributeClass))];
particleAttributes[idxAttribute+NbSymbAttributes] = &attributesBuffer[idxAttribute*blockHeader->nbParticlesAllocatedInGroup];
}
}
}
......@@ -135,7 +140,7 @@ public:
const int blockIndexesTableSize = int(inEndingIndex-inStartingIndex);
FAssertLF(inNumberOfLeaves <= blockIndexesTableSize);
// Total number of bytes in the block
const size_t sizeOfOneParticle = (3*sizeof(FReal));
const size_t sizeOfOneParticle = (3*sizeof(FReal) + NbSymbAttributes*sizeof(AttributeClass));
const size_t memoryToAlloc = sizeof(BlockHeader)
+ (blockIndexesTableSize*sizeof(int))
+ (inNumberOfLeaves*sizeof(LeafHeader))
......@@ -170,10 +175,16 @@ public:
// Redirect pointer to data
blockHeader->attributeOffset = (sizeof(AttributeClass) * nbParticlesAllocatedInGroup);
AttributeClass* symAttributes = (AttributeClass*)(&particlePosition[2][blockHeader->nbParticlesAllocatedInGroup]);
for(unsigned idxAttribute = 0 ; idxAttribute < NbSymbAttributes ; ++idxAttribute){
particleAttributes[idxAttribute] = symAttributes;
symAttributes += blockHeader->nbParticlesAllocatedInGroup;
}
attributesBuffer = (AttributeClass*)FAlignedMemory::Allocate32BAligned(blockHeader->attributeOffset*NbAttributesPerParticle);
memset(attributesBuffer, 0, blockHeader->attributeOffset*NbAttributesPerParticle);
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
particleAttributes[idxAttribute] = &attributesBuffer[idxAttribute*(blockHeader->nbParticlesAllocatedInGroup/sizeof(AttributeClass))];
particleAttributes[idxAttribute+NbSymbAttributes] = &attributesBuffer[idxAttribute*(blockHeader->nbParticlesAllocatedInGroup/sizeof(AttributeClass))];
}
// Set all index to not used
......
......@@ -18,11 +18,11 @@
template <class CompositeCellClass, class SymboleCellClass, class PoleCellClass, class LocalCellClass,
class GroupAttachedLeafClass, unsigned NbAttributesPerParticle, class AttributeClass = FReal>
class GroupAttachedLeafClass, unsigned NbSymbAttributes, unsigned NbAttributesPerParticle, class AttributeClass = FReal>
class FGroupTree {
public:
typedef GroupAttachedLeafClass BasicAttachedClass;
typedef FGroupOfParticles<NbAttributesPerParticle,AttributeClass> ParticleGroupClass;
typedef FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle,AttributeClass> ParticleGroupClass;
typedef FGroupOfCells<CompositeCellClass, SymboleCellClass, PoleCellClass, LocalCellClass> CellGroupClass;
protected:
......@@ -108,7 +108,7 @@ public:
CellGroupClass*const newBlock = new CellGroupClass(blockIteratorInOctree.getCurrentGlobalIndex(),
octreeIterator.getCurrentGlobalIndex()+1,
sizeOfBlock);
FGroupOfParticles<NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbAttributesPerParticle, AttributeClass>(blockIteratorInOctree.getCurrentGlobalIndex(),
FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>(blockIteratorInOctree.getCurrentGlobalIndex(),
octreeIterator.getCurrentGlobalIndex()+1,
sizeOfBlock, nbParticlesInGroup);
......@@ -265,7 +265,7 @@ public:
CellGroupClass*const newBlock = new CellGroupClass(currentBlockIndexes[0],
currentBlockIndexes[sizeOfBlock-1]+1,
sizeOfBlock);
FGroupOfParticles<NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbAttributesPerParticle, AttributeClass>(currentBlockIndexes[0],
FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>(currentBlockIndexes[0],
currentBlockIndexes[sizeOfBlock-1]+1,
sizeOfBlock, lastParticle-firstParticle);
......@@ -444,7 +444,7 @@ public:
CellGroupClass*const newBlock = new CellGroupClass(currentBlockIndexes[0],
currentBlockIndexes[sizeOfBlock-1]+1,
sizeOfBlock);
FGroupOfParticles<NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbAttributesPerParticle, AttributeClass>(currentBlockIndexes[0],
FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>*const newParticleBlock = new FGroupOfParticles<NbSymbAttributes, NbAttributesPerParticle, AttributeClass>(currentBlockIndexes[0],
currentBlockIndexes[sizeOfBlock-1]+1,
sizeOfBlock, lastParticle-firstParticle);
......
......@@ -7,8 +7,8 @@
#include "FGroupAttachedLeaf.hpp"
template<int NRHS = 1, int NLHS = 1>
class FP2PGroupParticleContainer : public FGroupAttachedLeaf<NRHS+4*NLHS, FReal> {
typedef FGroupAttachedLeaf<NRHS+4*NLHS, FReal> Parent;
class FP2PGroupParticleContainer : public FGroupAttachedLeaf<NRHS, 4*NLHS, FReal> {
typedef FGroupAttachedLeaf<NRHS, 4*NLHS, FReal> Parent;
public:
FP2PGroupParticleContainer(){}
......
......@@ -6,8 +6,8 @@
#include "../Core/FGroupAttachedLeaf.hpp"
class FGroupTestParticleContainer : public FGroupAttachedLeaf<2, long long int> {
typedef FGroupAttachedLeaf<2, long long int> Parent;
class FGroupTestParticleContainer : public FGroupAttachedLeaf<0, 1, long long int> {
typedef FGroupAttachedLeaf<0, 1, long long int> Parent;
public:
FGroupTestParticleContainer(){}
......
......@@ -59,7 +59,7 @@ int main(int argc, char* argv[]){
typedef FGroupTestParticleContainer GroupContainerClass;
typedef FGroupTree< GroupCellClass, GroupCellSymbClass, GroupCellUpClass, GroupCellDownClass,
GroupContainerClass, 2, long long int> GroupOctreeClass;
GroupContainerClass, 0, 1, long long int> GroupOctreeClass;
#ifdef ScalFMM_USE_STARPU
typedef FStarPUAllCpuCapacities<FTestKernels< GroupCellClass, GroupContainerClass >> GroupKernelClass;
typedef FStarPUCpuWrapper<typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass> GroupCpuWrapper;
......
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