Robot Simulator of the Robotics Group for Self-Organization of Control
0.8.0
|
#include <stdint.h>
#include <iostream>
#include <vector>
Go to the source code of this file.
Classes | |
class | ParallelTask |
A base class for parallel task classes which are defined by a set of macros. More... | |
class | ParallelTaskManager |
A singleton class to manage parallel code tasks. More... | |
struct | PlatformThreadObjects |
Namespaces | |
quickmp | |
A namespace for symbols that are part of the public API. | |
qmp_internal | |
A namespace for internal data structures. | |
Macros | |
#define | QMP_UNIQUE_SYMBOL_HELPER2(prefix, line) prefix##_uniqueSymbol##line |
#define | QMP_UNIQUE_SYMBOL_HELPER1(prefix, line) QMP_UNIQUE_SYMBOL_HELPER2(prefix, line) |
#define | QMP_UNIQUE_SYMBOL(prefix) QMP_UNIQUE_SYMBOL_HELPER1(prefix, __LINE__) |
#define | QMP_PARALLEL_FOR(indexName, loopFirstIndex,...) |
Defines the beginning of a parallel for loop. More... | |
#define | QMP_END_PARALLEL_FOR |
Defines the end of a parallel for loop. More... | |
#define | QMP_SET_NUM_THREADS(numThreads) qmp_internal::ParallelTaskManager::instance().setNumThreads(numThreads) |
Specifies the number of threads to use in subsequent parallel for loops. More... | |
#define | QMP_GET_NUM_THREADS qmp_internal::ParallelTaskManager::instance().getNumThreads |
Returns the number of threads currently being used. More... | |
#define | QMP_GET_MAX_THREADS qmp_internal::ParallelTaskManager::instance().getMaxThreads |
Returns the total number of threads allocated for use in all parallel for loops. More... | |
#define | QMP_THREAD_NUM parallelForLoopThreadIndexUniqueSymbol |
The zero-based index of the current thread. More... | |
#define | QMP_GET_NUM_PROCS qmp_internal::ParallelTaskManager::instance().getNumProcessors |
Returns the number of processors in the current machine at runtime. More... | |
#define | QMP_IN_PARALLEL qmp_internal::ParallelTaskManager::instance().inParallel |
Returns true if called within a parallel for loop and false otherwise. More... | |
#define | QMP_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionBegin |
Defines the beginning of a critical section used for synchronization. More... | |
#define | QMP_END_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionEnd |
Defines the beginning of a critical section used for synchronization. More... | |
#define | QMP_BARRIER qmp_internal::ParallelTaskManager::instance().barrier |
Defines a barrier routine used to synchronize threads. More... | |
#define | QMP_SHARE(variableName) |
Exposes the given variable to any parallel for loops later in the same scope. More... | |
#define | QMP_USE_SHARED(variableName,...) |
This provides access to the given variable within the parallel for loop, which must have been exposed before the beginning of the loop. More... | |
#define | QMP_ASSERT(condition) |
Assert macro. More... | |
Enumerations | |
enum | ScheduleHint { SEQUENTIAL, INTERLEAVED } |
Types of loop scheduling methods. More... | |
Functions | |
void * | threadRoutine (void *threadIndex) |
The routine to be executed by the threads. More... | |
#define QMP_ASSERT | ( | condition | ) |
Assert macro.
#define QMP_BARRIER qmp_internal::ParallelTaskManager::instance().barrier |
Defines a barrier routine used to synchronize threads.
Each thread blocks at the barrier until all threads have reached it. This can be expensive and can often be avoided by splitting one parallel for loop into two.
#define QMP_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionBegin |
Defines the beginning of a critical section used for synchronization.
This is necessary to protect shared variables which are read and written by multiple threads. The given id should be unique for each critical section within a parallel for loop. Keep the ids low to avoid allocating too many internal critical sections. Be very careful to use matching ids for the begin and end.
#define QMP_END_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionEnd |
Defines the beginning of a critical section used for synchronization.
The given id must match the id given at the beginning of the critical section. Keep the ids low to avoid allocating too many internal critical sections. Be very careful to use matching ids for the begin and end.
#define QMP_END_PARALLEL_FOR |
Defines the end of a parallel for loop.
#define QMP_GET_MAX_THREADS qmp_internal::ParallelTaskManager::instance().getMaxThreads |
Returns the total number of threads allocated for use in all parallel for loops.
#define QMP_GET_NUM_PROCS qmp_internal::ParallelTaskManager::instance().getNumProcessors |
Returns the number of processors in the current machine at runtime.
#define QMP_GET_NUM_THREADS qmp_internal::ParallelTaskManager::instance().getNumThreads |
Returns the number of threads currently being used.
In sequential code sections this returns 1; in parallel for loops this returns the total number of threads allocated for use in parallel for loops.
#define QMP_IN_PARALLEL qmp_internal::ParallelTaskManager::instance().inParallel |
Returns true if called within a parallel for loop and false otherwise.
#define QMP_PARALLEL_FOR | ( | indexName, | |
loopFirstIndex, | |||
... | |||
) |
Defines the beginning of a parallel for loop.
The arguments are the name of the integer index variable (accessible within the loop), the starting value of the index, the number of iterations to perform, and (optionally) the schedule hint. The index counts up from the starting value. The valid schedule hints are: quickmp::SEQUENTIAL (default, better for equal-duration loop iterations; similar to OpenMP "static" schedule with default (equal) chunk size) and quickmp::INTERLEAVED (better for non-equal-duration loop iterations; similar to OpenMP "static" schedule with chunk size 1).
#define QMP_SET_NUM_THREADS | ( | numThreads | ) | qmp_internal::ParallelTaskManager::instance().setNumThreads(numThreads) |
Specifies the number of threads to use in subsequent parallel for loops.
This is optional; without calling this, the system will use one thread per processor. If used, this must be called outside any parallel for loops. This can be called any number of times. This destroys and creates the internal thread pool, which might take time, so use it sparingly.
#define QMP_SHARE | ( | variableName | ) |
Exposes the given variable to any parallel for loops later in the same scope.
The arguments are the variable's type and name. This must be called outside the loop. The variable must remain valid as long as they are being accessed by any loops. Statically-allocated arrays must be given as pointers; for example, int myData[50] requires a pointer int* myDataPtr = myData, then QMP_SHARE(myDataPtr), not QMP_SHARE(myData).
#define QMP_THREAD_NUM parallelForLoopThreadIndexUniqueSymbol |
The zero-based index of the current thread.
This is only valid within a parallel for loop code section. Note: this is not a function call like most other macros (i.e. don't use () at the end).
#define QMP_UNIQUE_SYMBOL | ( | prefix | ) | QMP_UNIQUE_SYMBOL_HELPER1(prefix, __LINE__) |
#define QMP_UNIQUE_SYMBOL_HELPER1 | ( | prefix, | |
line | |||
) | QMP_UNIQUE_SYMBOL_HELPER2(prefix, line) |
#define QMP_UNIQUE_SYMBOL_HELPER2 | ( | prefix, | |
line | |||
) | prefix##_uniqueSymbol##line |
#define QMP_USE_SHARED | ( | variableName, | |
... | |||
) |
This provides access to the given variable within the parallel for loop, which must have been exposed before the beginning of the loop.
This must be called within the loop. Statically-allocated arrays must be given as pointers; for example, int myData[50] requires a pointer int* myDataPtr = myData exposed via QMP_SHARE(myDataPtr) then accessed via QMP_USE_SHARED(int*, myDataPtr).