Commit 47f68e5c authored by ESTERIE Pierre's avatar ESTERIE Pierre

Fix omp_get_max_threads to omp_get_num_threads

parent 04977157
......@@ -142,7 +142,7 @@ public:
{
#pragma omp critical
{
_kernels[i] = std::make_unique<kernel_t>(*kernel);
_kernels[omp_get_num_thread()] = std::make_unique<kernel_t>(*kernel);
}
}
}
......
......@@ -29,7 +29,7 @@ protected:
std::vector< std::vector< std::vector<BlockInteractions<CellContainerClass>>>> externalInteractionsAllLevel;
std::vector< std::vector<BlockInteractions<ParticleGroupClass>>> externalInteractionsLeafLevel;
const int MaxThreads; //< The number of threads
int MaxThreads; //< The number of threads
OctreeClass*const tree; //< The Tree
KernelClass** kernels; //< The kernels
......@@ -38,22 +38,24 @@ public:
using local_expansion_t = typename std::remove_pointer<typename OctreeClass::CellGroupIterator::value_type>::type::local_expansion_t;
using symbolic_data_t = typename std::remove_pointer<typename OctreeClass::CellGroupIterator::value_type>::type::symbolic_data_t;
FGroupTaskAlgorithm(OctreeClass*const inTree, KernelClass* inKernels, const int inMaxThreads = -1)
: MaxThreads(inMaxThreads==-1?omp_get_max_threads():inMaxThreads), tree(inTree), kernels(nullptr){
FGroupTaskAlgorithm(OctreeClass*const inTree, KernelClass* inKernels)
: tree(inTree), kernels(nullptr)
{
FAssertLF(tree, "tree cannot be null");
FAssertLF(inKernels, "kernels cannot be null");
FAbstractAlgorithm::setNbLevelsInTree(tree->getHeight());
kernels = new KernelClass*[MaxThreads];
#pragma omp parallel for schedule(static) num_threads(MaxThreads)
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
// We want to ensure that each thread allocate data close to him
// and that only one thread at a time call the copy constructor
#pragma omp critical (FGroupTaskDepAlgorithm_InitKernels)
{
this->kernels[idxThread] = new KernelClass(*inKernels);
}
MaxThreads = 1;
#pragma omp parallel
#pragma omp master
MaxThreads = omp_get_num_threads();
this->kernels = new KernelClass*[MaxThreads];
#pragma omp parallel num_threads(MaxThreads)
{
#pragma omp critical (FGroupTaskAlgorithm_InitKernels)
this->kernels[omp_get_thread_num()] = new KernelClass(*inKernels);
}
rebuildInteractions();
......
......@@ -57,7 +57,7 @@ protected:
std::vector< std::vector< std::vector<BlockInteractions<CellContainerClass>>>> externalInteractionsAllLevel;
std::vector< std::vector<BlockInteractions<ParticleGroupClass>>> externalInteractionsLeafLevel;
const int MaxThreads; //< The number of threads
int MaxThreads; //< The number of threads
OctreeClass*const tree; //< The Tree
KernelClass** kernels; //< The kernels
const bool noCommuteAtLastLevel;
......@@ -75,8 +75,8 @@ public:
using local_expansion_t = LocalCellClass;
using symbolic_data_t = SymboleCellClass;
FGroupTaskDepAlgorithm(OctreeClass*const inTree, KernelClass* inKernels, const int inMaxThreads = -1)
: MaxThreads(inMaxThreads==-1?omp_get_max_threads():inMaxThreads), tree(inTree), kernels(nullptr),
FGroupTaskDepAlgorithm(OctreeClass*const inTree, const KernelClass* const inKernels, const int inMaxThreads = -1)
: tree(inTree), kernels(nullptr),
noCommuteAtLastLevel(getenv("SCALFMM_NO_COMMUTE_LAST_L2L") != NULL && getenv("SCALFMM_NO_COMMUTE_LAST_L2L")[0] != '1'?false:true)
#ifdef SCALFMM_TIME_OMPTASKS
, taskTimeRecorder(MaxThreads)
......@@ -90,15 +90,16 @@ public:
FAbstractAlgorithm::setNbLevelsInTree(tree->getHeight());
kernels = new KernelClass*[MaxThreads];
#pragma omp parallel for schedule(static) num_threads(MaxThreads)
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
// We want to ensure that each thread allocate data close to him
// and that only one thread at a time call the copy constructor
#pragma omp critical (FGroupTaskDepAlgorithm_InitKernels)
{
this->kernels[idxThread] = new KernelClass(*inKernels);
}
MaxThreads = 1;
#pragma omp parallel
#pragma omp master
MaxThreads = omp_get_num_threads();
this->kernels = new KernelClass*[MaxThreads];
#pragma omp parallel num_threads(MaxThreads)
{
#pragma omp critical (FGroupTaskDepAlgorithm_InitKernels)
this->kernels[omp_get_thread_num()] = new KernelClass(*inKernels);
}
rebuildInteractions();
......
......@@ -11,7 +11,7 @@
*/
template <class SharedClass>
class FParObject{
const int nbThreads;
int nbThreads;
SharedClass* objects;
FParObject(const FParObject&) = delete;
......@@ -20,7 +20,13 @@ class FParObject{
public:
template <class... ArgsClass>
explicit FParObject(ArgsClass... args) : nbThreads(omp_get_max_threads()), objects(nullptr) {
explicit FParObject(ArgsClass... args) : objects(nullptr)
{
nbThreads = 1;
#pragma omp parallel
#pragma omp master
nbThreads = omp_get_num_threads();
objects = reinterpret_cast<SharedClass*>(new unsigned char[sizeof(SharedClass)*nbThreads]);
for(int idxThread = 0 ; idxThread < nbThreads ; ++idxThread){
new (&objects[idxThread]) SharedClass(args...);
......@@ -87,7 +93,7 @@ public:
template <class SharedClass>
class FParArray{
const int nbThreads;
int nbThreads;
SharedClass** arrays;
size_t arraySize;
......@@ -97,7 +103,13 @@ class FParArray{
public:
explicit FParArray(const size_t inArraySize = 0)
: nbThreads(omp_get_max_threads()), arrays(nullptr), arraySize(inArraySize) {
: arrays(nullptr), arraySize(inArraySize)
{
nbThreads = 1;
#pragma omp parallel
#pragma omp master
nbThreads = omp_get_num_threads();
arrays = new SharedClass*[nbThreads];
#pragma omp parallel for schedule(static)
for(int idxThread = 0 ; idxThread < nbThreads ; ++idxThread){
......
......@@ -131,7 +131,12 @@ public:
#ifdef FQS_TASKS_ARE_DISABLED
static void QsOmp(SortType elements[], const int nbElements, const infOrEqualPtr infOrEqual){
const int nbTasksRequiere = (omp_get_max_threads() * 5);
int threads = 1;
#pragma omp parallel
#pragma omp master
threads = omp_get_num_threads();
const int nbTasksRequiere = (threads * 5);
int deep = 0;
while( (1 << deep) < nbTasksRequiere ) deep += 1;
......@@ -193,7 +198,13 @@ public:
#else
/** The openmp quick sort */
static void QsOmp(SortType array[], const IndexType size, const infOrEqualPtr infOrEqual){
const int nbTasksRequiere = (omp_get_max_threads() * 5);
int threads = 1;
#pragma omp parallel
#pragma omp master
threads = omp_get_num_threads();
const int nbTasksRequiere = (threads * 5);
int deep = 0;
while( (1 << deep) < nbTasksRequiere ) deep += 1;
......
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