13 #ifndef KRATOS_OPENMP_UTILS_H
14 #define KRATOS_OPENMP_UTILS_H
19 #ifdef KRATOS_SMP_OPENMP
76 return omp_get_num_threads();
86 KRATOS_DEPRECATED_MESSAGE(
"This is legacy version, please use the \"ParallelUtilities\" instead") static
int GetNumberOfProcessors()
98 return omp_get_dynamic();
111 return omp_get_thread_num();
125 return omp_in_parallel();
137 KRATOS_DEPRECATED_MESSAGE(
"This is legacy version, please use the \"utilities/builtin_timer.h\" instead") static
double GetCurrentTime()
140 return std::clock()/
static_cast<double>(CLOCKS_PER_SEC);
142 return omp_get_wtime();
160 const int NumThreads,
163 Partitions.resize(NumThreads + 1);
164 int PartitionSize = NumTerms / NumThreads;
166 Partitions[NumThreads] = NumTerms;
167 for(
int i = 1;
i < NumThreads;
i++)
168 Partitions[
i] = Partitions[
i-1] + PartitionSize ;
177 template<
class TVector >
180 typename TVector::iterator& rBegin,
181 typename TVector::iterator& rEnd)
184 int NumTerms = rVector.size();
185 int ThreadNum = omp_get_thread_num();
186 int NumThreads = omp_get_max_threads();
187 int PartitionSize = NumTerms / NumThreads;
189 rBegin = rVector.begin() + ThreadNum * PartitionSize;
191 if ( (ThreadNum + 1) != NumThreads )
192 rEnd = rBegin + PartitionSize;
194 rEnd = rVector.end();
196 rBegin = rVector.begin();
197 rEnd = rVector.end();
209 KRATOS_DEPRECATED_MESSAGE(
"This is legacy version, please use the \"ParallelUtilities\" instead") static inline
void SetNumThreads(
int NumThreads = 1)
217 static inline void PrintOMPInfo()
221 int nthreads,tid, procs, maxt, inpar, dynamic, nested;
225 #pragma omp parallel private(nthreads, tid)
228 tid = omp_get_thread_num();
233 printf(
" Thread %d getting environment info...\n", tid);
236 procs = omp_get_num_procs();
237 nthreads = omp_get_num_threads();
238 maxt = omp_get_max_threads();
239 inpar = omp_in_parallel();
241 dynamic = omp_get_dynamic();
243 nested = omp_get_nested();
246 printf(
" | ------------ OMP IN USE --------- |\n");
247 printf(
" | Machine number of processors = %d |\n", procs);
248 printf(
" | Number of threads set = %d |\n", nthreads);
249 printf(
" | Max threads in use = %d |\n", maxt);
250 printf(
" | In parallel? = %d |\n", inpar);
251 printf(
" | Dynamic threads enabled? = %d |\n", dynamic);
252 printf(
" | Nested parallelism supported? = %d |\n", nested);
253 printf(
" | --------------------------------- |\n");
256 if( procs < nthreads )
257 std::cout<<
" ( WARNING: Maximimun number of threads is EXCEEDED )"<<std::endl;
268 static inline
void CreatePartition(
unsigned int number_of_threads,
const int number_of_rows, T& partitions)
270 partitions.resize(number_of_threads+1);
271 int partition_size = number_of_rows / number_of_threads;
273 partitions[number_of_threads] = number_of_rows;
274 for(
unsigned int i = 1;
i<number_of_threads;
i++)
275 partitions[
i] = partitions[
i-1] + partition_size ;
Implements basic tasks for OpenMP parallelism and suitable scalar alternatives.
Definition: openmp_utils.h:43
static void DivideInPartitions(const int NumTerms, const int NumThreads, PartitionVector &Partitions)
Divide an array of length NumTerms between NumThreads threads.
Definition: openmp_utils.h:158
static int GetCurrentNumberOfThreads()
Wrapper for omp_get_num_threads().
Definition: openmp_utils.h:73
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
KRATOS_DEPRECATED_MESSAGE("This is legacy version, please use the \"ParallelUtilities\" instead") static inline int GetNumThreads()
Wrapper for omp_get_max_threads().
Definition: openmp_utils.h:64
static int IsInParallel()
Wrapper for omp_in_parallel().
Definition: openmp_utils.h:122
KRATOS_DEPRECATED_MESSAGE("This is legacy version, please use the \"ParallelUtilities\" instead") static int GetNumberOfProcessors()
Wrapper for omp_get_num_procs().
Definition: openmp_utils.h:86
KRATOS_DEPRECATED_MESSAGE("This is legacy version, please use the \"utilities/builtin_timer.h\" instead") static double GetCurrentTime()
Timing routine.
Definition: openmp_utils.h:137
static void PartitionedIterators(TVector &rVector, typename TVector::iterator &rBegin, typename TVector::iterator &rEnd)
Generate a partition for an std::vector-like array, providing iterators to the begin and end position...
Definition: openmp_utils.h:179
static int IsDynamic()
Wrapper for omp_get_dynamic().
Definition: openmp_utils.h:95
std::vector< int > PartitionVector
Vector type for the output of DivideInPartitions method.
Definition: openmp_utils.h:53
static void SetNumThreads(const int NumThreads)
Sets the current number of threads.
Definition: parallel_utilities.cpp:49
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
static int GetNumProcs()
Returns the number of processors available to this device This can include the multiple threads per p...
Definition: parallel_utilities.cpp:69
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
tuple const
Definition: ode_solve.py:403
integer i
Definition: TensorModule.f:17