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/function_view.h>
#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
 
class  paropt
 

Macros

#define OIIO_PARALLEL_PAROPT
 

Enumerations

enum  SplitDir {
  Split_X, Split_Y, Split_Z, Split_Biggest,
  Split_Tile
}
 

Functions

OIIO_UTIL_API void parallel_for_chunked (int64_t begin, int64_t end, int64_t chunksize, std::function< void(int64_t, int64_t)> &&task, paropt opt=paropt(0, paropt::SplitDir::Y, 1))
 
OIIO_UTIL_API void parallel_for (int32_t begin, int32_t end, function_view< void(int32_t)> task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for (int64_t begin, int64_t end, function_view< void(int64_t)> task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for (uint32_t begin, uint32_t end, function_view< void(uint32_t)> task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for (uint64_t begin, uint64_t end, function_view< void(uint64_t)> task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_range (int32_t begin, int32_t end, std::function< void(int32_t, int32_t)> &&task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_range (int64_t begin, int64_t end, std::function< void(int64_t, int64_t)> &&task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_range (uint32_t begin, uint32_t end, std::function< void(uint32_t, uint32_t)> &&task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_range (uint64_t begin, uint64_t end, std::function< void(uint64_t, uint64_t)> &&task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_chunked_2D (int64_t xbegin, int64_t xend, int64_t xchunksize, int64_t ybegin, int64_t yend, int64_t ychunksize, std::function< void(int64_t xbeg, int64_t xend, int64_t ybeg, int64_t yend)> &&task, paropt opt=0)
 
OIIO_UTIL_API void parallel_for_2D (int64_t xbegin, int64_t xend, int64_t ybegin, int64_t yend, std::function< void(int64_t x, int64_t y)> &&task, paropt opt=0)
 

Macro Definition Documentation

#define OIIO_PARALLEL_PAROPT

Definition at line 75 of file parallel.h.

Enumeration Type Documentation

enum SplitDir

Split strategies DEPRECATED(2.4)

Enumerator
Split_X 
Split_Y 
Split_Z 
Split_Biggest 
Split_Tile 

Definition at line 24 of file parallel.h.

Function Documentation

OIIO_UTIL_API void parallel_for ( int32_t  begin,
int32_t  end,
function_view< void(int32_t)>  task,
paropt  opt = 0 
)

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

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

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.

OIIO_UTIL_API void parallel_for ( int64_t  begin,
int64_t  end,
function_view< void(int64_t)>  task,
paropt  opt = 0 
)
OIIO_UTIL_API void parallel_for ( uint32_t  begin,
uint32_t  end,
function_view< void(uint32_t)>  task,
paropt  opt = 0 
)
OIIO_UTIL_API void parallel_for ( uint64_t  begin,
uint64_t  end,
function_view< void(uint64_t)>  task,
paropt  opt = 0 
)
OIIO_UTIL_API void parallel_for_2D ( int64_t  xbegin,
int64_t  xend,
int64_t  ybegin,
int64_t  yend,
std::function< void(int64_t x, int64_t y)> &&  task,
paropt  opt = 0 
)

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

OIIO_UTIL_API void parallel_for_chunked ( int64_t  begin,
int64_t  end,
int64_t  chunksize,
std::function< void(int64_t, int64_t)> &&  task,
paropt  opt = paropt(0, paropt::SplitDir::Y, 1) 
)

Parallel "for" loop, chunked: for a task that takes an int64_t [begin,end) range, break it into non-overlapping sections that run in parallel:

task (begin, begin+chunksize); task (begin+chunksize, begin+2*chunksize); ... task (begin+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.)

OIIO_UTIL_API void parallel_for_chunked_2D ( int64_t  xbegin,
int64_t  xend,
int64_t  xchunksize,
int64_t  ybegin,
int64_t  yend,
int64_t  ychunksize,
std::function< void(int64_t xbeg, int64_t xend, int64_t ybeg, int64_t yend)> &&  task,
paropt  opt = 0 
)

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

task (begin, begin+chunksize); task (begin+chunksize, begin+2*chunksize); ... task (begin+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.)

OIIO_UTIL_API void parallel_for_range ( int32_t  begin,
int32_t  end,
std::function< void(int32_t, int32_t)> &&  task,
paropt  opt = 0 
)

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

task (begin, i1); task (i1+1, i2); ... task (iN+1, end);

The chunk sizes will be chosen automatically, and are not guaranteed to all be the same size.

OIIO_UTIL_API void parallel_for_range ( int64_t  begin,
int64_t  end,
std::function< void(int64_t, int64_t)> &&  task,
paropt  opt = 0 
)
OIIO_UTIL_API void parallel_for_range ( uint32_t  begin,
uint32_t  end,
std::function< void(uint32_t, uint32_t)> &&  task,
paropt  opt = 0 
)
OIIO_UTIL_API void parallel_for_range ( uint64_t  begin,
uint64_t  end,
std::function< void(uint64_t, uint64_t)> &&  task,
paropt  opt = 0 
)