KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
List of all members
Kratos::OpenMPUtils Class Reference

Implements basic tasks for OpenMP parallelism and suitable scalar alternatives. More...

#include <openmp_utils.h>

Collaboration diagram for Kratos::OpenMPUtils:

Public Types

Type definitions
typedef std::vector< intPartitionVector
 Vector type for the output of DivideInPartitions method. More...
 

Operations

 KRATOS_DEPRECATED_MESSAGE ("This is legacy version, please use the \"ParallelUtilities\" instead") static inline int GetNumThreads()
 Wrapper for omp_get_max_threads(). More...
 
 KRATOS_DEPRECATED_MESSAGE ("This is legacy version, please use the \"ParallelUtilities\" instead") static int GetNumberOfProcessors()
 Wrapper for omp_get_num_procs(). More...
 
 KRATOS_DEPRECATED_MESSAGE ("This is legacy version, please use the \"utilities/builtin_timer.h\" instead") static double GetCurrentTime()
 Timing routine. More...
 
static int GetCurrentNumberOfThreads ()
 Wrapper for omp_get_num_threads(). More...
 
static int IsDynamic ()
 Wrapper for omp_get_dynamic(). More...
 
static int ThisThread ()
 Wrapper for omp_get_thread_num(). More...
 
static int IsInParallel ()
 Wrapper for omp_in_parallel(). More...
 
static void DivideInPartitions (const int NumTerms, const int NumThreads, PartitionVector &Partitions)
 Divide an array of length NumTerms between NumThreads threads. More...
 
template<class TVector >
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 positions for each thread. More...
 

Detailed Description

Implements basic tasks for OpenMP parallelism and suitable scalar alternatives.

This class defines utility functions that implement some basic OpenMP capabilities and an equivalent scalar alternative to use in compilations where OpenMP is not enabled. The idea is to allow Kratos developers to design their code in parallel, knowing that it will work in scalar runs as well.

Member Typedef Documentation

◆ PartitionVector

Vector type for the output of DivideInPartitions method.

See also
OpenMPUtils::DivideInPartitions

Member Function Documentation

◆ DivideInPartitions()

static void Kratos::OpenMPUtils::DivideInPartitions ( const int  NumTerms,
const int  NumThreads,
PartitionVector Partitions 
)
inlinestatic

Divide an array of length NumTerms between NumThreads threads.

Creates a std::vector containing NumThreads + 1 terms, where term k is the first and position of the array that corresponds to thread k. The k+1 term is the end of the array, so that the vector can be used to iterate the array between 'k' and 'k+1' in each thread.

Parameters
NumTermsNumber of objects to be divided between the threads.
NumThreadsThe number of parallel threads that will be used.
PartitionsThis object will contain the begin and end positions for each thread.

◆ GetCurrentNumberOfThreads()

static int Kratos::OpenMPUtils::GetCurrentNumberOfThreads ( )
inlinestatic

Wrapper for omp_get_num_threads().

Returns
Number of OpenMP threads in the current team.

◆ IsDynamic()

static int Kratos::OpenMPUtils::IsDynamic ( )
inlinestatic

Wrapper for omp_get_dynamic().

Returns
Dynamic teams are enabled.

◆ IsInParallel()

static int Kratos::OpenMPUtils::IsInParallel ( )
inlinestatic

Wrapper for omp_in_parallel().

Returns
Maximum number of OpenMP threads that will be used in parallel regions.

◆ KRATOS_DEPRECATED_MESSAGE() [1/3]

Kratos::OpenMPUtils::KRATOS_DEPRECATED_MESSAGE ( "This is legacy  version,
please use the \"ParallelUtilities\" instead"   
)
inline

Wrapper for omp_get_max_threads().

Returns
Maximum number of OpenMP threads that will be used in parallel regions.

◆ KRATOS_DEPRECATED_MESSAGE() [2/3]

Kratos::OpenMPUtils::KRATOS_DEPRECATED_MESSAGE ( "This is legacy  version,
please use the \"ParallelUtilities\" instead"   
)
inline

Wrapper for omp_get_num_procs().

Returns
Number of processors available to the device.

◆ KRATOS_DEPRECATED_MESSAGE() [3/3]

Kratos::OpenMPUtils::KRATOS_DEPRECATED_MESSAGE ( "This is legacy  version,
please use the \"utilities/builtin_timer.h\" instead"   
)
inline

Timing routine.

Determine the current time by calling an appropiate (scalar or parallel) timer class.

Returns
Current time

◆ PartitionedIterators()

template<class TVector >
static void Kratos::OpenMPUtils::PartitionedIterators ( TVector &  rVector,
typename TVector::iterator &  rBegin,
typename TVector::iterator &  rEnd 
)
inlinestatic

Generate a partition for an std::vector-like array, providing iterators to the begin and end positions for each thread.

This function assumes that the vector class will have an iterator type and implement begin(), end() and size() methods.

Parameters
rVectorAn arary containing the elements to be distributed between the threads.
rBeginIterator pointing to the first element in rVector to be used in the current thread.
rEndIterator pointing to the end position for the current thread in rVector.

◆ ThisThread()

static int Kratos::OpenMPUtils::ThisThread ( )
inlinestatic

Wrapper for omp_get_thread_num().

Returns
The thread number for this thread, 0 if scalar run.

The documentation for this class was generated from the following file: