Commit bb99ff87 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

Remove some cast (unsigned int <--> int)

Remove white space and align data
Code improvements (for cppcheck)
Add comments
parent 88347cde
......@@ -60,10 +60,10 @@ int main(int argc, char ** argv){
const FSize NbPoints = loader.getNumberOfParticles();
const unsigned int nbData = loader.getNbRecordPerline() ;
const FSize arraySize =nbData*NbPoints;
const FSize arraySize = nbData*NbPoints;
FReal * particles = new FReal[arraySize] ;
std::memset(particles,0,arraySize*sizeof(FReal));
FReal * particles = new FReal[arraySize] {};
// std::memset(particles,0,arraySize*sizeof(FReal));
FSize j = 0 ;
for(FSize idxPart = 0 ; idxPart < NbPoints ;++idxPart, j+=nbData){
......
......@@ -94,16 +94,16 @@ int main(int argc, char* argv[])
const std::string defaultFile(SCALFMMDataPath+"unitCubeXYZQ100.bfma" );
const std::string filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, defaultFile.c_str());
const unsigned int TreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeHeight.options, 5);
const unsigned int SubTreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);
const std::string filename = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, defaultFile.c_str());
const int TreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeHeight.options, 5);
const int SubTreeHeight = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);
#ifdef _OPENMP
const unsigned int NbThreads = FParameters::getValue(argc, argv, FParameterDefinitions::NbThreads.options, omp_get_max_threads());
omp_set_num_threads(NbThreads);
std::cout << "\n>> Using " << NbThreads << " threads.\n" << std::endl;
#else
const unsigned int NbThreads = FParameters::getValue(argc, argv, FParameterDefinitions::NbThreads.options, 1);
const int NbThreads = FParameters::getValue(argc, argv, FParameterDefinitions::NbThreads.options, 1);
std::cout << "\n>> Sequential version.\n" << std::endl;
#endif
//
......
......@@ -42,11 +42,11 @@ template<class FReal, class CellClass, class ContainerClass, class LeafClass_, c
class FOctree : public FNoCopyable {
public:
using FRealType = FReal;
using CellClassType = CellClass;
using CellClassType = CellClass;
using ContainerClassType = ContainerClass; //< The type of the container used to store particles in the Octree
using LeafClassType = LeafClass_; //< The type of the Leaf used in the Octree
using LeafClass = LeafClass_; //< The type of the Leaf used in the Octree
using LeafClass_T = LeafClass_; //< The type of the Leaf used in the Octree
using LeafClassType = LeafClass_; //< The type of the Leaf used in the Octree
using LeafClass = LeafClass_; //< The type of the Leaf used in the Octree
using LeafClass_T = LeafClass_; //< The type of the Leaf used in the Octree
protected:
typedef FOctree<FReal, CellClass , ContainerClass, LeafClass, CellAllocatorClass> OctreeType;
......@@ -55,10 +55,10 @@ protected:
FAbstractSubOctree<FReal, CellClass , ContainerClass, LeafClass, CellAllocatorClass>* root; //< root suboctree
FReal*const boxWidthAtLevel; //< to store the width of each boxs at all levels
FReal*const boxWidthAtLevel; //< to store the width of each box at all levels
const int height; //< tree height
const int subHeight; //< tree height
const int height; //< Total tree height
const int subHeight; //< sub tree height
const int leafIndex; //< index of leaf int array
const FPoint<FReal> boxCenter; //< the space system center
......
......@@ -4,10 +4,10 @@
#define FCHEBCELL_HPP
#include <iostream>
#include "../../Components/FBasicCell.hpp"
#include "Components/FBasicCell.hpp"
#include "./FChebTensor.hpp"
#include "../../Extensions/FExtendCellType.hpp"
#include "FChebTensor.hpp"
#include "Extensions/FExtendCellType.hpp"
/**
* @author Matthias Messner (matthias.messner@inria.fr)
......@@ -22,7 +22,7 @@ class FChebCell : public FBasicCell, public FAbstractSendable
{
// nnodes = ORDER^3
// we multiply by 2 because we store the Multipole expansion end the compressed one.
static const int VectorSize = TensorTraits<ORDER>::nnodes * 2;
static constexpr int VectorSize = TensorTraits<ORDER>::nnodes * 2;
public:
......@@ -60,7 +60,7 @@ public:
};
using multipole_t = exp_impl<class multipole_tag, NRHS>;
using multipole_t = exp_impl<class multipole_tag, NRHS>;
using local_expansion_t = exp_impl<class local_expansion_tag, NLHS>;
multipole_t m_data {};
......
......@@ -8,7 +8,7 @@
#ifndef FCHEBINTERFACE_H
#define FCHEBINTERFACE_H
#include "Utils/FGlobal.hpp"
//To access leaf datas
struct FChebLeaf_struct;
......
......@@ -2,9 +2,9 @@
#ifndef FINTERPTENSOR_HPP
#define FINTERPTENSOR_HPP
#include "../../Utils/FMath.hpp"
#include "Utils/FMath.hpp"
#include "./FInterpMapping.hpp"
#include "FInterpMapping.hpp"
/**
......
......@@ -6,9 +6,9 @@
#include "Utils/stdComplex.hpp"
#include "./FUnifTensor.hpp"
#include "../../Components/FBasicCell.hpp"
#include "../../Extensions/FExtendCellType.hpp"
#include "FUnifTensor.hpp"
#include "Components/FBasicCell.hpp"
#include "Extensions/FExtendCellType.hpp"
/**
......@@ -26,114 +26,46 @@
template < class FReal, int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
class FUnifCell : public FBasicCell, public FAbstractSendable
{
static const int VectorSize = TensorTraits<ORDER>::nnodes;
static const int TransformedVectorSize = (2*ORDER-1)*(2*ORDER-1)*(2*ORDER-1);
static const int VectorSize = TensorTraits<ORDER>::nnodes;
static const int TransformedVectorSize = (2*ORDER-1)*(2*ORDER-1)*(2*ORDER-1);
public:
template<class Tag, std::size_t N>
struct exp_impl {
FReal exp[N * NVALS * VectorSize]; //< Multipole expansion
// Multipole expansion in Fourier space
stdComplex<FReal> transformed_exp[N * NVALS * TransformedVectorSize];
const FReal* get(const int inRhs) const
{ return this->exp + inRhs*VectorSize; }
FReal* get(const int inRhs)
{ return this->exp + inRhs*VectorSize; }
const stdComplex<FReal>* getTransformed(const int inRhs) const
{ return this->transformed_exp + inRhs*TransformedVectorSize; }
stdComplex<FReal>* getTransformed(const int inRhs)
{ return this->transformed_exp + inRhs*TransformedVectorSize; }
constexpr int getVectorSize() const {
return VectorSize;
}
// to extend FAbstractSendable
template <class BufferWriterClass>
void serialize(BufferWriterClass& buffer) const{
buffer.write(this->exp, VectorSize*NVALS*N);
buffer.write(this->transformed_exp, TransformedVectorSize*NVALS*N);
}
template <class BufferReaderClass>
void deserialize(BufferReaderClass& buffer){
buffer.fillArray(this->exp, VectorSize*NVALS*N);
buffer.fillArray(this->transformed_exp, TransformedVectorSize*NVALS*N);
}
///////////////////////////////////////////////////////
// to extend Serializable
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
buffer.write(this->exp, VectorSize*NVALS*NRHS);
buffer.write(this->transformed_exp, TransformedVectorSize*NVALS*NRHS);
}
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
buffer.fillArray(this->exp, VectorSize*NVALS*NRHS);
buffer.fillArray(this->transformed_exp, TransformedVectorSize*NVALS*NRHS);
}
FSize getSavedSize() const {
return N * NVALS * VectorSize * (FSize) sizeof(FReal)
+ N * NVALS * TransformedVectorSize * (FSize) sizeof(stdComplex<FReal>);
}
};
using multipole_t = exp_impl<class multipole_tag, NRHS>;
using local_expansion_t = exp_impl<class local_expansion_tag, NLHS>;
multipole_t m_data {};
local_expansion_t l_data {};
bool hasMultipoleData() const noexcept {
return true;
}
bool hasLocalExpansionData() const noexcept {
return true;
}
template<class Tag, std::size_t N>
struct exp_impl {
/// Multipole expansion in Real space
FReal exp[N * NVALS * VectorSize]; //< Multipole expansion
/// Multipole expansion in Fourier space
stdComplex<FReal> transformed_exp[N * NVALS * TransformedVectorSize];
multipole_t& getMultipoleData() noexcept {
return m_data;
}
const multipole_t& getMultipoleData() const noexcept {
return m_data;
const FReal* get(const int inRhs) const
{ return this->exp + inRhs*VectorSize; }
FReal* get(const int inRhs)
{ return this->exp + inRhs*VectorSize; }
const stdComplex<FReal>* getTransformed(const int inRhs) const
{ return this->transformed_exp + inRhs*TransformedVectorSize;
}
stdComplex<FReal>* getTransformed(const int inRhs)
{ return this->transformed_exp + inRhs*TransformedVectorSize; }
local_expansion_t& getLocalExpansionData() noexcept {
return l_data;
constexpr int getVectorSize() const {
return VectorSize;
}
const local_expansion_t& getLocalExpansionData() const noexcept {
return l_data;
}
///////////////////////////////////////////////////////
// to extend FAbstractSendable
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void serializeUp(BufferWriterClass& buffer) const{
m_data.serialize(buffer);
void serialize(BufferWriterClass& buffer) const{
buffer.write(this->exp, VectorSize*NVALS*N);
buffer.write(this->transformed_exp, TransformedVectorSize*NVALS*N);
}
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass& buffer){
m_data.deserialize(buffer);
}
template <class BufferWriterClass>
void serializeDown(BufferWriterClass& buffer) const{
l_data.serialize(buffer);
}
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass& buffer){
l_data.deserialize(buffer);
void deserialize(BufferReaderClass& buffer){
buffer.fillArray(this->exp, VectorSize*NVALS*N);
buffer.fillArray(this->transformed_exp, TransformedVectorSize*NVALS*N);
}
///////////////////////////////////////////////////////
......@@ -141,72 +73,145 @@ public:
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FBasicCell::save(buffer);
m_data.save(buffer);
l_data.save(buffer);
buffer.write(this->exp, VectorSize*NVALS*NRHS);
buffer.write(this->transformed_exp, TransformedVectorSize*NVALS*NRHS);
}
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FBasicCell::restore(buffer);
m_data.restore(buffer);
l_data.restore(buffer);
buffer.fillArray(this->exp, VectorSize*NVALS*NRHS);
buffer.fillArray(this->transformed_exp, TransformedVectorSize*NVALS*NRHS);
}
FSize getSavedSize() const {
return m_data.getSavedSize() + l_data.getSavedSize()
+ FBasicCell::getSavedSize();
}
FSize getSavedSizeUp() const {
return m_data.getSavedSize();
}
FSize getSavedSizeDown() const {
return l_data.getSavedSize();
}
template <class StreamClass>
friend StreamClass& operator<<(StreamClass& output, const FUnifCell<FReal,ORDER, NRHS, NLHS, NVALS>& cell){
output << "Multipole exp NRHS " << NRHS
<< " NVALS " << NVALS
<< " VectorSize " << cell.getVectorSize()
<< '\n';
for (int rhs= 0 ; rhs < NRHS ; ++rhs) {
const FReal* pole = cell.getMultipole(rhs);
for (int val= 0 ; val < NVALS ; ++val) {
output<< " val : " << val << " exp: " ;
for (int i= 0 ; i < cell.getVectorSize() ; ++i) {
output<< pole[i] << " ";
}
output << std::endl;
}
}
return output;
}
return N * NVALS * VectorSize * (FSize) sizeof(FReal)
+ N * NVALS * TransformedVectorSize * (FSize) sizeof(stdComplex<FReal>);
}
};
using multipole_t = exp_impl<class multipole_tag, NRHS>;
using local_expansion_t = exp_impl<class local_expansion_tag, NLHS>;
multipole_t m_data {};
local_expansion_t l_data {};
bool hasMultipoleData() const noexcept {
return true;
}
bool hasLocalExpansionData() const noexcept {
return true;
}
multipole_t& getMultipoleData() noexcept {
return m_data;
}
const multipole_t& getMultipoleData() const noexcept {
return m_data;
}
local_expansion_t& getLocalExpansionData() noexcept {
return l_data;
}
const local_expansion_t& getLocalExpansionData() const noexcept {
return l_data;
}
///////////////////////////////////////////////////////
// to extend FAbstractSendable
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void serializeUp(BufferWriterClass& buffer) const{
m_data.serialize(buffer);
}
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass& buffer){
m_data.deserialize(buffer);
}
template <class BufferWriterClass>
void serializeDown(BufferWriterClass& buffer) const{
l_data.serialize(buffer);
}
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass& buffer){
l_data.deserialize(buffer);
}
///////////////////////////////////////////////////////
// to extend Serializable
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FBasicCell::save(buffer);
m_data.save(buffer);
l_data.save(buffer);
}
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FBasicCell::restore(buffer);
m_data.restore(buffer);
l_data.restore(buffer);
}
FSize getSavedSize() const {
return m_data.getSavedSize() + l_data.getSavedSize()
+ FBasicCell::getSavedSize();
}
FSize getSavedSizeUp() const {
return m_data.getSavedSize();
}
FSize getSavedSizeDown() const {
return l_data.getSavedSize();
}
template <class StreamClass>
friend StreamClass& operator<<(StreamClass& output, const FUnifCell<FReal,ORDER, NRHS, NLHS, NVALS>& cell){
output << "Multipole exp NRHS " << NRHS
<< " NVALS " << NVALS
<< " VectorSize " << cell.getVectorSize()
<< '\n';
for (int rhs= 0 ; rhs < NRHS ; ++rhs) {
const FReal* pole = cell.getMultipole(rhs);
for (int val= 0 ; val < NVALS ; ++val) {
output<< " val : " << val << " exp: " ;
for (int i= 0 ; i < cell.getVectorSize() ; ++i) {
output<< pole[i] << " ";
}
output << std::endl;
}
}
return output;
}
};
template <class FReal, int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
class FTypedUnifCell : public FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>, public FExtendCellType {
public:
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::save(buffer);
FExtendCellType::save(buffer);
}
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::restore(buffer);
FExtendCellType::restore(buffer);
}
void resetToInitialState(){
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::resetToInitialState();
FExtendCellType::resetToInitialState();
}
FSize getSavedSize() const {
return FExtendCellType::getSavedSize() + FUnifCell<FReal, ORDER,NRHS,NLHS,NVALS>::getSavedSize();
}
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::save(buffer);
FExtendCellType::save(buffer);
}
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::restore(buffer);
FExtendCellType::restore(buffer);
}
void resetToInitialState(){
FUnifCell<FReal,ORDER,NRHS,NLHS,NVALS>::resetToInitialState();
FExtendCellType::resetToInitialState();
}
FSize getSavedSize() const {
return FExtendCellType::getSavedSize() + FUnifCell<FReal, ORDER,NRHS,NLHS,NVALS>::getSavedSize();
}
};
#endif //FUNIFCELL_HPP
......@@ -4,7 +4,7 @@
#ifndef FUNIFTENSOR_HPP
#define FUNIFTENSOR_HPP
#include "../../Utils/FMath.hpp"
#include "Utils/FMath.hpp"
#include "FUnifRoots.hpp"
#include "../Interpolation/FInterpTensor.hpp"
......@@ -81,17 +81,26 @@ class FUnifTensor : public FInterpTensor<FReal, ORDER,FUnifRoots<FReal, ORDER>>
// Convention:
// lj=order-1 & li=0:order-1 => li-lj=1-order:0
// lj=1 & li=0:order-1 => li-lj=1:order-1
if(l<ORDER-1) lj=ORDER-1; else lj=0;
if(l<ORDER-1) {
lj=ORDER-1;}
else{
lj=0;}
li=(l-(ORDER-1))+lj;
for(unsigned int m=0; m<2*ORDER-1; ++m){
if(m<ORDER-1) mj=ORDER-1; else mj=0;
if(m<ORDER-1){
mj=ORDER-1;}
else {
mj=0;}
mi=(m-(ORDER-1))+mj;
for(unsigned int n=0; n<2*ORDER-1; ++n){
if(n<ORDER-1) nj=ORDER-1; else nj=0;
if(n<ORDER-1){
nj=ORDER-1;}
else{
nj=0;}
ni=(n-(ORDER-1))+nj;
NodeIdsPairs[ido][0]=li*ORDER*ORDER + mi*ORDER + ni;
......
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