HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parallel.h File Reference
#include <algorithm>
#include <atomic>
#include <future>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
#include <OpenImageIO/strutil.h>
#include <OpenImageIO/thread.h>
+ Include dependency graph for parallel.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  parallel_options
 Encapsulation of options that control parallel_image(). More...
 

Enumerations

enum  SplitDir {
  Split_X, Split_Y, Split_Z, Split_Biggest,
  Split_Tile
}
 Split strategies. More...
 

Functions

OIIO_API void parallel_for_chunked (int64_t start, int64_t end, int64_t chunksize, std::function< void(int id, int64_t b, int64_t e)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
 
void parallel_for_chunked (int64_t start, int64_t end, int64_t chunksize, std::function< void(int64_t, int64_t)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
 
void parallel_for (int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
 
void parallel_for (int64_t start, int64_t end, std::function< void(int id, int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
 
template<class InputIt , class UnaryFunction >
UnaryFunction parallel_for_each (InputIt first, InputIt last, UnaryFunction f, parallel_options opt=parallel_options(0, Split_Y, 1))
 
OIIO_API void parallel_for_chunked_2D (int64_t xstart, int64_t xend, int64_t xchunksize, int64_t ystart, int64_t yend, int64_t ychunksize, std::function< void(int id, int64_t, int64_t, int64_t, int64_t)> &&task, parallel_options opt=0)
 
void parallel_for_chunked_2D (int64_t xstart, int64_t xend, int64_t xchunksize, int64_t ystart, int64_t yend, int64_t ychunksize, std::function< void(int64_t, int64_t, int64_t, int64_t)> &&task, parallel_options opt=0)
 
void parallel_for_2D (int64_t xstart, int64_t xend, int64_t ystart, int64_t yend, std::function< void(int id, int64_t i, int64_t j)> &&task, parallel_options opt=0)
 
void parallel_for_2D (int64_t xstart, int64_t xend, int64_t ystart, int64_t yend, std::function< void(int64_t i, int64_t j)> &&task, parallel_options opt=0)
 
void parallel_for_2D (int64_t xstart, int64_t xend, int64_t, int64_t ystart, int64_t yend, int64_t, std::function< void(int id, int64_t i, int64_t j)> &&task)
 

Enumeration Type Documentation

enum SplitDir

Split strategies.

Enumerator
Split_X 
Split_Y 
Split_Z 
Split_Biggest 
Split_Tile 

Definition at line 24 of file parallel.h.

Function Documentation

void parallel_for ( int64_t  start,
int64_t  end,
std::function< void(int64_t index)> &&  task,
parallel_options  opt = parallel_options(0,Split_Y,1) 
)
inline

Parallel "for" loop, for a task that takes a single int64_t index, run it on all indices on the range [begin,end):

task (begin); task (begin+1); ... task (end-1);

Using the default thread pool, spawn parallel jobs. Conceptually, it behaves as if each index gets called separately, but actually each thread will iterate over some chunk of adjacent indices (to aid data coherence and minimize the amount of thread queue diddling). The chunk size is chosen automatically.

Definition at line 127 of file parallel.h.

void parallel_for ( int64_t  start,
int64_t  end,
std::function< void(int id, int64_t index)> &&  task,
parallel_options  opt = parallel_options(0,Split_Y,1) 
)
inline

parallel_for, for a task that takes an int threadid and an int64_t index, running all of: task (id, begin); task (id, begin+1); ... task (id, end-1);

Definition at line 145 of file parallel.h.

void parallel_for_2D ( int64_t  xstart,
int64_t  xend,
int64_t  ystart,
int64_t  yend,
std::function< void(int id, int64_t i, int64_t j)> &&  task,
parallel_options  opt = 0 
)
inline

parallel_for, for a task that takes an int threadid and int64_t x & y indices, running all of: task (id, xstart, ystart); ... task (id, xend-1, ystart); task (id, xstart, ystart+1); task (id, xend-1, ystart+1); ... task (id, xend-1, yend-1);

Definition at line 233 of file parallel.h.

void parallel_for_2D ( int64_t  xstart,
int64_t  xend,
int64_t  ystart,
int64_t  yend,
std::function< void(int64_t i, int64_t j)> &&  task,
parallel_options  opt = 0 
)
inline

parallel_for, for a task that takes an int threadid and int64_t x & y indices, running all of: task (xstart, ystart); ... task (xend-1, ystart); task (xstart, ystart+1); task (xend-1, ystart+1); ... task (xend-1, yend-1);

Definition at line 258 of file parallel.h.

void parallel_for_2D ( int64_t  xstart,
int64_t  xend,
int64_t  ,
int64_t  ystart,
int64_t  yend,
int64_t  ,
std::function< void(int id, int64_t i, int64_t j)> &&  task 
)
inline

Definition at line 277 of file parallel.h.

OIIO_API void parallel_for_chunked ( int64_t  start,
int64_t  end,
int64_t  chunksize,
std::function< void(int id, int64_t b, int64_t e)> &&  task,
parallel_options  opt = parallel_options(0, Split_Y, 1) 
)

Parallel "for" loop, chunked: for a task that takes an int thread ID followed by an int64_t [begin,end) range, break it into non-overlapping sections that run in parallel using the default thread pool:

task (threadid, start, start+chunksize); task (threadid, start+chunksize, start+2*chunksize); ... task (threadid, start+n*chunksize, end);

and wait for them all to complete.

If chunksize is 0, a chunksize will be chosen to divide the range into a number of chunks equal to the twice number of threads in the queue. (We do this to offer better load balancing than if we used exactly the thread count.)

Note that the thread_id may be -1, indicating that it's being executed by the calling thread itself, or perhaps some other helpful thread that is stealing work from the pool.

void parallel_for_chunked ( int64_t  start,
int64_t  end,
int64_t  chunksize,
std::function< void(int64_t, int64_t)> &&  task,
parallel_options  opt = parallel_options(0, Split_Y, 1) 
)
inline

Parallel "for" loop, chunked: for a task that takes a [begin,end) range (but not a thread ID).

Definition at line 103 of file parallel.h.

OIIO_API void parallel_for_chunked_2D ( int64_t  xstart,
int64_t  xend,
int64_t  xchunksize,
int64_t  ystart,
int64_t  yend,
int64_t  ychunksize,
std::function< void(int id, int64_t, int64_t, int64_t, int64_t)> &&  task,
parallel_options  opt = 0 
)

Parallel "for" loop in 2D, chunked: for a task that takes an int thread ID followed by begin, end, chunksize for each of x and y, subdivide that run in parallel using the default thread pool.

task (threadid, xstart, xstart+xchunksize, ); task (threadid, start+chunksize, start+2*chunksize); ... task (threadid, start+n*chunksize, end);

and wait for them all to complete.

If chunksize is 0, a chunksize will be chosen to divide the range into a number of chunks equal to the twice number of threads in the queue. (We do this to offer better load balancing than if we used exactly the thread count.)

void parallel_for_chunked_2D ( int64_t  xstart,
int64_t  xend,
int64_t  xchunksize,
int64_t  ystart,
int64_t  yend,
int64_t  ychunksize,
std::function< void(int64_t, int64_t, int64_t, int64_t)> &&  task,
parallel_options  opt = 0 
)
inline

Parallel "for" loop, chunked: for a task that takes a 2D [begin,end) range and chunk sizes.

Definition at line 209 of file parallel.h.

template<class InputIt , class UnaryFunction >
UnaryFunction parallel_for_each ( InputIt  first,
InputIt  last,
UnaryFunction  f,
parallel_options  opt = parallel_options(0,Split_Y,1) 
)

parallel_for_each, semantically is like std::for_each(), but each iteration is a separate job for the default thread pool.

Definition at line 161 of file parallel.h.