Commit a991bebc authored by COULAUD Olivier's avatar COULAUD Olivier

Add CMAKE_CXX_STANDARD, fix some issues detected by sonarQube

parent 26e3813d
......@@ -13,7 +13,6 @@ set(FUSE_LIST " MPI;BLAS;FFT;STARPU;CUDA;OPENCL;OMP4;SSE;AVX;AVX2;MIC;MPI2")
# Project Declaration
#===========================================================================
project(SCALFMM C CXX )
# check if compiling into source directories
string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" insource)
if(insource)
......@@ -28,7 +27,7 @@ INCLUDE(CMakeDependentOption)
# Add to check CPU info
include(GetCpuInfos)
GetCpuInfos()
#
#===========================================================================
# Version Number
#===========================================================================
......@@ -39,6 +38,10 @@ set(SCALFMM_MINOR_VERSION 0)
set(SCALFMM_PATCH_VERSION rc0)
set(SCALFMM_VERSION "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}.${SCALFMM_PATCH_VERSION}" )
SET(CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_STANDARD 14)
set( MORSE_DISTRIB_DIR "" CACHE PATH "Directory of MORSE distribution")
if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/")
......@@ -140,7 +143,7 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/
message(STATUS "CXX ${CMAKE_CXX_COMPILER_ID}" )
# Set scalfmm to default libraries
set(SCALFMM_LIBRARIES "")
set(SCALFMM_CXX_FLAGS "-std=c++14 -fpic -Wall")
set(SCALFMM_CXX_FLAGS "-fpic -Wall")
set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/Contribs")
#
#
......
......@@ -81,9 +81,12 @@ public:
~FChebM2LHandler()
{
if (U != nullptr) delete [] U;
if (B != nullptr) delete [] B;
if (C != nullptr) delete [] C;
if (U != nullptr)
{delete [] U;}
if (B != nullptr)
{ delete [] B;}
if (C != nullptr)
{delete [] C; }
}
/**
......@@ -92,9 +95,11 @@ public:
void ComputeAndCompressAndSet()
{
// measure time
FTic time; time.tic();
FTic time;
time.tic();
// check if aready set
if (U||C||B) throw std::runtime_error("Compressed M2L operator already set");
if (U||C||B) {
throw std::runtime_error("Compressed M2L operator already set"); }
rank = ComputeAndCompress(MatrixKernel, epsilon, U, C, B);
unsigned long sizeM2L = 343*rank*rank*sizeof(FReal);
......@@ -149,7 +154,8 @@ public:
*/
void applyU(const FReal *const X, FReal *const x) const
{
FBlas::gemva(nnodes, rank, 1., U, const_cast<FReal*>(X), x);
constexpr FReal ONE = 1.0 ;
FBlas::gemva(nnodes, rank, ONE, U, const_cast<FReal*>(X), x);
}
/**
......@@ -222,7 +228,9 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompress(const Matri
FReal* &B)
{
// allocate memory and store compressed M2L operators
if (U||C||B) throw std::runtime_error("Compressed M2L operators are already set");
if (U||C||B){
throw std::runtime_error("Compressed M2L operators are already set");
}
// interpolation points of source (Y) and target (X) cell
FPoint<FReal> X[nnodes], Y[nnodes];
......@@ -233,6 +241,7 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompress(const Matri
FReal *_U, *_C, *_B;
_U = _B = nullptr;
_C = new FReal [nnodes*nnodes * ninteractions];
//
unsigned int counter = 0;
for (int i=-3; i<=3; ++i) {
for (int j=-3; j<=3; ++j) {
......@@ -242,18 +251,22 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompress(const Matri
const FPoint<FReal> cy(FReal(2.*i), FReal(2.*j), FReal(2.*k));
FChebTensor<FReal, order>::setRoots(cy, FReal(2.), Y);
// evaluate m2l operator
for (unsigned int n=0; n<nnodes; ++n)
for (unsigned int m=0; m<nnodes; ++m)
for (unsigned int n=0; n<nnodes; ++n){
for (unsigned int m=0; m<nnodes; ++m){
_C[counter*nnodes*nnodes + n*nnodes + m]
= MatrixKernel->evaluate(X[m], Y[n]);
}
}
// increment interaction counter
counter++;
++counter;
}
}
}
}
if (counter != ninteractions)
if (counter != ninteractions){
delete [] _C ;
throw std::runtime_error("Number of interactions must correspond to 316");
}
//////////////////////////////////////////////////////////
......@@ -268,8 +281,9 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompress(const Matri
// svd compression of M2L
const unsigned int rank = Compress<FReal, ORDER>(epsilon, ninteractions, _U, _C, _B);
if (!(rank>0)) throw std::runtime_error("Low rank must be larger then 0!");
if (!(rank>0)) {
throw std::runtime_error("Low rank must be larger then 0!");
}
// store U
U = new FReal [nnodes * rank];
......@@ -288,11 +302,15 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompress(const Matri
const unsigned int idx = (i+3)*7*7 + (j+3)*7 + (k+3);
if (abs(i)>1 || abs(j)>1 || abs(k)>1) {
FBlas::copy(rank*rank, _C + counter*rank*rank, C + idx*rank*rank);
counter++;
} else FBlas::setzero(rank*rank, C + idx*rank*rank);
++counter;
}
else {
FBlas::setzero(rank*rank, C + idx*rank*rank);
}
if (counter != ninteractions)
}
if (counter != ninteractions){
throw std::runtime_error("Number of interactions must correspond to 316");
}
delete [] _C;
......@@ -344,9 +362,12 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ComputeAndCompressAndStoreInBi
} else throw std::runtime_error("File could not be opened to write");
stream.close();
// free memory
if (U != nullptr) delete [] U;
if (B != nullptr) delete [] B;
if (C != nullptr) delete [] C;
if (U != nullptr) {
delete [] U;}
if (B != nullptr) {
delete [] B;}
if (C != nullptr) {
delete [] C; }
// write info
std::cout << "Compressed M2L operators ("<< rank << ") stored in binary file " << filename
<< " in " << time.tacAndElapsed() << "sec." << std::endl;
......@@ -358,9 +379,12 @@ void
FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ReadFromBinaryFileAndSet()
{
// measure time
FTic time; time.tic();
FTic time;
time.tic();
// start reading process
if (U||C||B) throw std::runtime_error("Compressed M2L operator already set");
if (U||C||B) {
throw std::runtime_error("Compressed M2L operator already set");
}
const std::string filename(getFileName(epsilon));
std::ifstream stream(filename.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
......@@ -376,7 +400,9 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ReadFromBinaryFileAndSet()
// 1) read number of interpolation points (int)
int npts;
stream.read(reinterpret_cast<char*>(&npts), sizeof(int));
if (npts!=nnodes) throw std::runtime_error("nnodes and npts do not correspond");
if (npts!=nnodes) {
throw std::runtime_error("nnodes and npts do not correspond");
}
// 2) read low rank (int)
stream.read(reinterpret_cast<char*>(&rank), sizeof(int));
// 3) write U (rank*nnodes * FReal)
......@@ -388,7 +414,10 @@ FChebM2LHandler<FReal, ORDER, MatrixKernelClass>::ReadFromBinaryFileAndSet()
// 5) write 343 C (343 * rank*rank * FReal)
C = new FReal [343 * rank*rank];
stream.read(reinterpret_cast<char*>(C), sizeof(FReal)*rank*rank*343);
} else throw std::runtime_error("File could not be opened to read");
}
else {
throw std::runtime_error("File could not be opened to read");
}
stream.close();
// write info
std::cout << "Compressed M2L operators (" << rank << ") read from binary file "
......@@ -491,10 +520,10 @@ unsigned int Compress(const FReal epsilon, const unsigned int ninteractions,
// V' -> V
FReal *const V = new FReal [nnodes*ninteractions * k_row];
for (unsigned int i=0; i<k_row; ++i)
for (unsigned int i=0; i<k_row; ++i){
FBlas::copy(nnodes*ninteractions, K_row+i, nnodes,
V+i*nnodes*ninteractions, 1);
}
// rank k(epsilon) /////////////////////////////////////////////////////
const unsigned int k = k_row < k_col ? k_row : k_col;
......@@ -503,12 +532,13 @@ unsigned int Compress(const FReal epsilon, const unsigned int ninteractions,
for (unsigned int i=0; i<k; ++i) {
FBlas::scal(nnodes*ninteractions, S[i], V + i*nnodes*ninteractions);
for (unsigned int m=0; m<ninteractions; ++m)
for (unsigned int j=0; j<k; ++j)
for (unsigned int j=0; j<k; ++j) {
C[m*k*k + j*k + i]
= FBlas::scpr(nnodes,
V + i*nnodes*ninteractions + m*nnodes,
B + j*nnodes);
}
}
delete [] V;
delete [] S;
......
......@@ -9,8 +9,8 @@
#include "FChebTensor.hpp"
#include "../Interpolation/FInterpSymmetries.hpp"
#include "Kernels/Interpolation/FInterpSymmetries.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "FChebM2LHandler.hpp"
#include "Utils/FAca.hpp"
......@@ -156,6 +156,10 @@ static void precompute(const MatrixKernelClass *const MatrixKernel, const FReal
if (INFO!=0){
std::stringstream stream;
stream << INFO;
delete [] U ;
delete [] WORK ;
delete [] VT ;
delete [] S ;
throw std::runtime_error("SVD did not converge with " + stream.str());
}
rank = FSvd::getRank(S, aca_rank, Epsilon);
......@@ -348,7 +352,12 @@ public:
/** Destructor */
~SymmetryHandler()
{
for (unsigned int t=0; t<343; ++t) if (K[t]!=nullptr) delete [] K[t];
for (unsigned int t=0; t<343; ++t){
if (K[t]!=nullptr){
delete [] K[t];
}
}
}
......@@ -396,8 +405,10 @@ public:
// init all 343 item to zero, because effectively only 16 exist
K = new FReal** [TreeHeight];
LowRank = new int* [TreeHeight];
K[0] = nullptr; K[1] = nullptr;
LowRank[0] = nullptr; LowRank[1] = nullptr;
K[0] = nullptr;
K[1] = nullptr;
LowRank[0] = nullptr;
LowRank[1] = nullptr;
for (unsigned int l=2; l<TreeHeight; ++l) {
K[l] = new FReal* [343];
LowRank[l] = new int [343];
......@@ -435,10 +446,17 @@ public:
{
for (unsigned int l=0; l<TreeHeight; ++l) {
if (K[l]!=nullptr) {
for (unsigned int t=0; t<343; ++t) if (K[l][t]!=nullptr) delete [] K[l][t];
for (unsigned int t=0; t<343; ++t) {
if (K[l][t]!=nullptr){
delete [] K[l][t];
}
}
delete [] K[l];
}
if (LowRank[l]!=nullptr) delete [] LowRank[l];
if (LowRank[l]!=nullptr) {
delete [] LowRank[l];
}
}
delete [] K;
delete [] LowRank;
......@@ -476,7 +494,8 @@ static void ComputeAndCompressAndStoreInBinaryFile(const MatrixKernelClass *cons
// compute and compress ////////////
FReal* K[343];
int LowRank[343];
for (unsigned int idx=0; idx<343; ++idx) { K[idx] = nullptr; LowRank[idx] = 0; }
for (unsigned int idx=0; idx<343; ++idx)
{ K[idx] = nullptr; LowRank[idx] = 0; }
precompute<FReal,ORDER>(MatrixKernel, FReal(2.), Epsilon, K, LowRank);
// write to binary file ////////////
......@@ -510,7 +529,11 @@ static void ComputeAndCompressAndStoreInBinaryFile(const MatrixKernelClass *cons
// << " in " << time.tacAndElapsed() << "sec." << std::endl;
// free memory /////////////////////
for (unsigned int t=0; t<343; ++t) if (K[t]!=nullptr) delete [] K[t];
for (unsigned int t=0; t<343; ++t) {
if (K[t]!=nullptr) {
delete [] K[t];
}
}
}
......
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