Robotsystem of the Robot Group Leipzig: quickmp.h File Reference

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# quickmp.h File Reference

`#include <iostream>`
`#include <vector>`

Include dependency graph for quickmp.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Namespaces
namespace | quickmp
namespace | qmp_internal
## 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
## Defines
#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.
#define | QMP_END_PARALLEL_FOR
| Defines the end of a parallel for loop.
#define | QMP_SET_NUM_THREADS(numThreads) qmp_internal::ParallelTaskManager::instance().setNumThreads(numThreads)
| Specifies the number of threads to use in subsequent parallel for loops.
#define | QMP_GET_NUM_THREADS qmp_internal::ParallelTaskManager::instance().getNumThreads
| Returns the number of threads currently being used.
#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_THREAD_NUM parallelForLoopThreadIndexUniqueSymbol
| The zero-based index of the current thread.
#define | QMP_GET_NUM_PROCS qmp_internal::ParallelTaskManager::instance().getNumProcessors
| Returns the number of processors in the current machine at runtime.
#define | QMP_IN_PARALLEL qmp_internal::ParallelTaskManager::instance().inParallel
| Returns true if called within a parallel for loop and false otherwise.
#define | QMP_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionBegin
| Defines the beginning of a critical section used for synchronization.
#define | QMP_END_CRITICAL qmp_internal::ParallelTaskManager::instance().criticalSectionEnd
| Defines the beginning of a critical section used for synchronization.
#define | QMP_BARRIER qmp_internal::ParallelTaskManager::instance().barrier
| Defines a barrier routine used to synchronize threads.
#define | QMP_SHARE(variableName)
| Exposes the given variable to any parallel for loops later in the same scope.
#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.
#define | QMP_ASSERT(condition)
| Assert macro.
## Enumerations
enum | quickmp::ScheduleHint { quickmp::SEQUENTIAL, quickmp::INTERLEAVED }
| Types of loop scheduling methods. More...
## Functions
void * | qmp_internal::threadRoutine (void *threadIndex)
| The routine to be executed by the threads.

## Define Documentation

#define QMP_ASSERT | ( | condition |  | ) |

Value:

    {\
            if (!(condition))\
            {\
                    std::cout << "[QuickMP] Assertion failed in " << __FUNCTION__ \
                            << "(line " << __LINE__ << "): assert(" << #condition << ")" \
                            << std::endl;\
                    ::exit(1);\
            }\
    }

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

Value:

    } \
                    } \
            }QMP_UNIQUE_SYMBOL(Instance); \
            qmp_internal::ParallelTaskManager::instance().process( \
                    &QMP_UNIQUE_SYMBOL(Instance)); \
    }

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 |  | ) |

Value:

    { \
            qmp_internal::ParallelTaskManager::instance().setLoopIndices( \
                    loopFirstIndex, __VA_ARGS__); \
            static class QMP_UNIQUE_SYMBOL(ParallelTaskSubclass) : \
                    public qmp_internal::ParallelTask \
            { \
            public: \
                    virtual void run(int QMP_UNIQUE_SYMBOL(parallelForLoopFirstIndex), \
                            int QMP_UNIQUE_SYMBOL(parallelForLoopLastIndex), \
                            const unsigned int parallelForLoopThreadIndexUniqueSymbol, \
                            int QMP_UNIQUE_SYMBOL(parallelForLoopIndexIncrement)) \
                    { \
                            for (int indexName = QMP_UNIQUE_SYMBOL(parallelForLoopFirstIndex); \
                                    indexName <= QMP_UNIQUE_SYMBOL(parallelForLoopLastIndex); \
                                    indexName += QMP_UNIQUE_SYMBOL(parallelForLoopIndexIncrement)) \
                            {

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 |  | ) |

Value:

    static void* variableName##_tempImportCopy = NULL; \
            variableName##_tempImportCopy = (void*)&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 |  | ) |

Value:

    __VA_ARGS__& variableName = \
            *((__VA_ARGS__*)variableName##_tempImportCopy);

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).