Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_task.h
| Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | typedef struct TaskParallelTLS { | ||||
| /* Identifier of the thread who this data belongs to. */ | /* Identifier of the thread who this data belongs to. */ | ||||
| int thread_id; | int thread_id; | ||||
| /* Copy of user-specifier chunk, which is copied from original chunk to all | /* Copy of user-specifier chunk, which is copied from original chunk to all | ||||
| * worker threads. This is similar to OpenMP's firstprivate. | * worker threads. This is similar to OpenMP's firstprivate. | ||||
| */ | */ | ||||
| void *userdata_chunk; | void *userdata_chunk; | ||||
| } TaskParallelTLS; | } TaskParallelTLS; | ||||
| typedef void (*TaskParallelFinalizeFunc)(void *__restrict userdata, | |||||
| void *__restrict userdata_chunk); | |||||
| typedef void (*TaskParallelRangeFunc)(void *__restrict userdata, | typedef void (*TaskParallelRangeFunc)(void *__restrict userdata, | ||||
| const int iter, | const int iter, | ||||
| const TaskParallelTLS *__restrict tls); | const TaskParallelTLS *__restrict tls); | ||||
| typedef void (*TaskParallelReduceFunc)(const void *__restrict userdata, | |||||
| void *__restrict chunk_join, | |||||
| void *__restrict chunk); | |||||
| typedef void (*TaskParallelFreeFunc)(const void *__restrict userdata, void *__restrict chunk); | |||||
| typedef struct TaskParallelSettings { | typedef struct TaskParallelSettings { | ||||
| /* Whether caller allows to do threading of the particular range. | /* Whether caller allows to do threading of the particular range. | ||||
| * Usually set by some equation, which forces threading off when threading | * Usually set by some equation, which forces threading off when threading | ||||
| * overhead becomes higher than speed benefit. | * overhead becomes higher than speed benefit. | ||||
| * BLI_task_parallel_range() by itself will always use threading when range | * BLI_task_parallel_range() by itself will always use threading when range | ||||
| * is higher than a chunk size. As in, threading will always be performed. | * is higher than a chunk size. As in, threading will always be performed. | ||||
| */ | */ | ||||
| bool use_threading; | bool use_threading; | ||||
| /* Scheduling mode to use for this parallel range invocation. */ | /* Scheduling mode to use for this parallel range invocation. */ | ||||
| eTaskSchedulingMode scheduling_mode; | eTaskSchedulingMode scheduling_mode; | ||||
| /* Each instance of looping chunks will get a copy of this data | /* Each instance of looping chunks will get a copy of this data | ||||
| * (similar to OpenMP's firstprivate). | * (similar to OpenMP's firstprivate). | ||||
| */ | */ | ||||
| void *userdata_chunk; /* Pointer to actual data. */ | void *userdata_chunk; /* Pointer to actual data. */ | ||||
| size_t userdata_chunk_size; /* Size of that data. */ | size_t userdata_chunk_size; /* Size of that data. */ | ||||
| /* Function called from calling thread once whole range have been | /* Function called from calling thread once whole range have been | ||||
| * processed. | * processed. | ||||
| */ | */ | ||||
| TaskParallelFinalizeFunc func_finalize; | /* Function called to join user data chunk into another, to reduce | ||||
| * the result to the original userdata_chunk memory. | |||||
| * The reduce functions should have no side effects, so that they | |||||
| * can be run on any thread. */ | |||||
| TaskParallelReduceFunc func_reduce; | |||||
| /* Function called to free data created by TaskParallelRangeFunc. */ | |||||
| TaskParallelFreeFunc func_free; | |||||
| /* Minimum allowed number of range iterators to be handled by a single | /* Minimum allowed number of range iterators to be handled by a single | ||||
| * thread. This allows to achieve following: | * thread. This allows to achieve following: | ||||
| * - Reduce amount of threading overhead. | * - Reduce amount of threading overhead. | ||||
| * - Partially occupy thread pool with ranges which are computationally | * - Partially occupy thread pool with ranges which are computationally | ||||
| * expensive, but which are smaller than amount of available threads. | * expensive, but which are smaller than amount of available threads. | ||||
| * For example, it's possible to multi-thread [0 .. 64] range into 4 | * For example, it's possible to multi-thread [0 .. 64] range into 4 | ||||
| * thread which will be doing 16 iterators each. | * thread which will be doing 16 iterators each. | ||||
| * This is a preferred way to tell scheduler when to start threading than | * This is a preferred way to tell scheduler when to start threading than | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||