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. */ | |||||
| TaskParallelReduceFunc func_reduce; | |||||
| /* Function called to free user data chunk. */ | |||||
| 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 | ||||
| * having a global use_threading switch based on just range size. | * having a global use_threading switch based on just range size. | ||||
| */ | */ | ||||
| int min_iter_per_thread; | int min_iter_per_thread; | ||||
| } TaskParallelSettings; | } TaskParallelSettings; | ||||
| BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings); | BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings); | ||||
| void BLI_task_parallel_range(const int start, | void BLI_task_parallel_range(const int start, | ||||
| const int stop, | const int stop, | ||||
| void *userdata, | void *userdata, | ||||
| TaskParallelRangeFunc func, | TaskParallelRangeFunc func, | ||||
| TaskParallelSettings *settings); | TaskParallelSettings *settings); | ||||
| #ifdef TASK_RANGE_POOL | |||||
| typedef struct TaskParallelRangePool TaskParallelRangePool; | typedef struct TaskParallelRangePool TaskParallelRangePool; | ||||
| struct TaskParallelRangePool *BLI_task_parallel_range_pool_init( | struct TaskParallelRangePool *BLI_task_parallel_range_pool_init( | ||||
| const struct TaskParallelSettings *settings); | const struct TaskParallelSettings *settings); | ||||
| void BLI_task_parallel_range_pool_push(struct TaskParallelRangePool *range_pool, | void BLI_task_parallel_range_pool_push(struct TaskParallelRangePool *range_pool, | ||||
| const int start, | const int start, | ||||
| const int stop, | const int stop, | ||||
| void *userdata, | void *userdata, | ||||
| TaskParallelRangeFunc func, | TaskParallelRangeFunc func, | ||||
| const struct TaskParallelSettings *settings); | const struct TaskParallelSettings *settings); | ||||
| void BLI_task_parallel_range_pool_work_and_wait(struct TaskParallelRangePool *range_pool); | void BLI_task_parallel_range_pool_work_and_wait(struct TaskParallelRangePool *range_pool); | ||||
| void BLI_task_parallel_range_pool_free(struct TaskParallelRangePool *range_pool); | void BLI_task_parallel_range_pool_free(struct TaskParallelRangePool *range_pool); | ||||
| #endif | |||||
| /* This data is shared between all tasks, its access needs thread lock or similar protection. | /* This data is shared between all tasks, its access needs thread lock or similar protection. | ||||
| */ | */ | ||||
| typedef struct TaskParallelIteratorStateShared { | typedef struct TaskParallelIteratorStateShared { | ||||
| /* Maximum amount of items to acquire at once. */ | /* Maximum amount of items to acquire at once. */ | ||||
| int chunk_size; | int chunk_size; | ||||
| /* Next item to be acquired. */ | /* Next item to be acquired. */ | ||||
| void *next_item; | void *next_item; | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||