Commit 3205c613 authored by BRAMAS Berenger's avatar BRAMAS Berenger

Remove old custom openmp barrier

parent d739df70
// ===================================================================================
// 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 FOMPBARRIER_HPP
#define FOMPBARRIER_HPP
#include <omp.h>
#include <climits>
/** This function is a custom omp barrier
* Because openmp give only a global barrier we need
* to be ablo to peform a barrier operation between a group
* of threads only.
*/
class FOmpBarrier {
private:
int nbThreads; //<The number of threads for this barrier
int currentNbThread; //<The current number of threads waiting
bool sense; //<Direct barrier feedback protection
omp_lock_t mutex; //<To have an atomic int
FOmpBarrier(FOmpBarrier&){}
FOmpBarrier& operator=(FOmpBarrier&){return *this;}
public:
/** Constructor with the number of threads */
FOmpBarrier(const int inNbThreads = INT_MAX)
: nbThreads(inNbThreads), currentNbThread(0), sense(false) {
omp_init_lock( &mutex );
}
/** Destructor, release the omp lock */
~FOmpBarrier(){
omp_destroy_lock( &mutex );
}
/** Perform a barrier */
void wait(){
const bool mySense = sense;
omp_set_lock( &mutex );
const int nbThreadsArrived = (++currentNbThread);
omp_unset_lock( &mutex );
if(nbThreadsArrived == nbThreads) {
currentNbThread = 0;
sense = !sense;
#pragma omp flush
}
else {
volatile const bool* const ptSense = &sense;
while( (*ptSense) == mySense){
}
}
}
/** Change the number of threads */
void setNbThreads(const int inNbThread){
omp_set_lock( &mutex );
nbThreads = inNbThread;
omp_unset_lock( &mutex );
}
};
#endif // FOMPBARRIER_HPP
......@@ -27,8 +27,6 @@
#include "FMemUtils.hpp"
#include "FTrace.hpp"
#include "FOmpBarrier.hpp"
/** This class is parallel quick sort
* It hold a mpi version
* + 2 openmp versions (one on tasks and the other like mpi)
......
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