darts/parallel_for.h file

parallel_for constructs

Functions

void parallel_for(int begin, int end, int step, std::function<void(int, size_t)> body, size_t num_threads = 0)
Executes the body of a for loop in parallel.
void parallel_for(int begin, int end, int step, std::function<void(int)> body, size_t num_threads = 0)
A version of the parallel_for accepting a body lambda that only takes the iterator index as a parameter.
void parallel_for(int begin, int end, std::function<void(int, size_t)> body, size_t num_threads = 0)
A version of parallel_for with a step of 1, providing the integer index and thread number to the loop body.
void parallel_for(int begin, int end, std::function<void(int)> body, size_t num_threads = 0)
A version of parallel_for with a step of 1, providing just the integer index to the loop body.

Function documentation

void parallel_for(int begin, int end, int step, std::function<void(int, size_t)> body, size_t num_threads = 0)

Executes the body of a for loop in parallel.

Parameters
begin The starting index of the for loop
end One past the ending index of the for loop
step How much to increment at each iteration when moving from begin to end
body The body of the for loop as a lambda, taking two parameters: the iterator index in [begin,end), and the CPU number.
num_threads Specify the number of threads to use. 0: as many as there are cores; 1: execute in serial

adapted from http://www.andythomason.com/2016/08/21/c-multithreading-an-effective-parallel-for-loop/ license unknown, presumed public domain