Blender  V2.93
Classes | Macros | Typedefs | Functions
task_iterator.c File Reference
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_mempool.h"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "atomic_ops.h"

Go to the source code of this file.

Classes

struct  TaskParallelIteratorState
 
struct  ParallelMempoolState
 

Macros

#define MALLOCA(_size)   ((_size) <= 8192) ? alloca((_size)) : MEM_mallocN((_size), __func__)
 
#define MALLOCA_FREE(_mem, _size)
 

Typedefs

typedef struct TaskParallelIteratorState TaskParallelIteratorState
 
typedef struct ParallelMempoolState ParallelMempoolState
 

Functions

BLI_INLINE void task_parallel_calc_chunk_size (const TaskParallelSettings *settings, const int tot_items, int num_tasks, int *r_chunk_size)
 
static void parallel_iterator_func_do (TaskParallelIteratorState *__restrict state, void *userdata_chunk)
 
static void parallel_iterator_func (TaskPool *__restrict pool, void *userdata_chunk)
 
static void task_parallel_iterator_no_threads (const TaskParallelSettings *settings, TaskParallelIteratorState *state)
 
static void task_parallel_iterator_do (const TaskParallelSettings *settings, TaskParallelIteratorState *state)
 
void BLI_task_parallel_iterator (void *userdata, TaskParallelIteratorIterFunc iter_func, void *init_item, const int init_index, const int tot_items, TaskParallelIteratorFunc func, const TaskParallelSettings *settings)
 
static void task_parallel_listbase_get (void *__restrict UNUSED(userdata), const TaskParallelTLS *__restrict UNUSED(tls), void **r_next_item, int *r_next_index, bool *r_do_abort)
 
void BLI_task_parallel_listbase (ListBase *listbase, void *userdata, TaskParallelIteratorFunc func, const TaskParallelSettings *settings)
 
static void parallel_mempool_func (TaskPool *__restrict pool, void *taskdata)
 
void BLI_task_parallel_mempool (BLI_mempool *mempool, void *userdata, TaskParallelMempoolFunc func, const bool use_threading)
 

Detailed Description

Parallel tasks over all elements in a container.

Definition in file task_iterator.c.

Macro Definition Documentation

◆ MALLOCA

#define MALLOCA (   _size)    ((_size) <= 8192) ? alloca((_size)) : MEM_mallocN((_size), __func__)

Definition at line 38 of file task_iterator.c.

◆ MALLOCA_FREE

#define MALLOCA_FREE (   _mem,
  _size 
)
Value:
if (((_mem) != NULL) && ((_size) > 8192)) { \
MEM_freeN((_mem)); \
} \
((void)0)

Definition at line 39 of file task_iterator.c.

Typedef Documentation

◆ ParallelMempoolState

◆ TaskParallelIteratorState

Function Documentation

◆ BLI_task_parallel_iterator()

void BLI_task_parallel_iterator ( void *  userdata,
TaskParallelIteratorIterFunc  iter_func,
void *  init_item,
const int  init_index,
const int  tot_items,
TaskParallelIteratorFunc  func,
const TaskParallelSettings settings 
)

This function allows to parallelize for loops using a generic iterator.

Parameters
userdataCommon userdata passed to all instances of func.
iter_funcCallback function used to generate chunks of items.
init_itemThe initial item, if necessary (may be NULL if unused).
init_indexThe initial index.
tot_itemsThe total amount of items to iterate over (if unknown, set it to a negative number).
funcCallback function.
settingsSee public API doc of TaskParallelSettings for description of all settings.
Note
Static scheduling is only available when tot_items is >= 0.

Definition at line 276 of file task_iterator.c.

References state, and task_parallel_iterator_do().

◆ BLI_task_parallel_listbase()

void BLI_task_parallel_listbase ( ListBase listbase,
void *  userdata,
TaskParallelIteratorFunc  func,
const TaskParallelSettings settings 
)

This function allows to parallelize for loops over ListBase items.

Parameters
listbaseThe double linked list to loop over.
userdataCommon userdata passed to all instances of func.
funcCallback function.
settingsSee public API doc of ParallelRangeSettings for description of all settings.
Note
There is no static scheduling here, since it would need another full loop over items to count them.

Definition at line 324 of file task_iterator.c.

References BLI_listbase_count(), BLI_listbase_is_empty(), ListBase::first, state, task_parallel_iterator_do(), and task_parallel_listbase_get().

Referenced by task_listbase_test_do(), and TEST().

◆ BLI_task_parallel_mempool()

void BLI_task_parallel_mempool ( BLI_mempool mempool,
void *  userdata,
TaskParallelMempoolFunc  func,
const bool  use_threading 
)

This function allows to parallelize for loops over Mempool items.

Parameters
mempoolThe iterable BLI_mempool to loop over.
userdataCommon userdata passed to all instances of func.
funcCallback function.
use_threadingIf true, actually split-execute loop in threads, else just do a sequential for loop (allows caller to use any kind of test to switch on parallelization or not).
Note
There is no static scheduling here.

Definition at line 377 of file task_iterator.c.

References BLI_mempool_iter_threadsafe_create(), BLI_mempool_iter_threadsafe_free(), BLI_mempool_iternew(), BLI_mempool_iterstep(), BLI_mempool_len(), BLI_task_pool_create(), BLI_task_pool_free(), BLI_task_pool_push(), BLI_task_pool_work_and_wait(), BLI_task_scheduler_num_threads(), NULL, parallel_mempool_func(), state, task_pool, and TASK_PRIORITY_HIGH.

Referenced by armature_deform_coords_impl(), lattice_deform_coords_impl(), and TEST().

◆ parallel_iterator_func()

static void parallel_iterator_func ( TaskPool *__restrict  pool,
void *  userdata_chunk 
)
static

◆ parallel_iterator_func_do()

static void parallel_iterator_func_do ( TaskParallelIteratorState *__restrict  state,
void *  userdata_chunk 
)
static

◆ parallel_mempool_func()

static void parallel_mempool_func ( TaskPool *__restrict  pool,
void *  taskdata 
)
static

◆ task_parallel_calc_chunk_size()

BLI_INLINE void task_parallel_calc_chunk_size ( const TaskParallelSettings settings,
const int  tot_items,
int  num_tasks,
int *  r_chunk_size 
)

◆ task_parallel_iterator_do()

static void task_parallel_iterator_do ( const TaskParallelSettings settings,
TaskParallelIteratorState state 
)
static

◆ task_parallel_iterator_no_threads()

static void task_parallel_iterator_no_threads ( const TaskParallelSettings settings,
TaskParallelIteratorState state 
)
static

◆ task_parallel_listbase_get()

static void task_parallel_listbase_get ( void *__restrict   UNUSEDuserdata,
const TaskParallelTLS *__restrict   UNUSEDtls,
void **  r_next_item,
int *  r_next_index,
bool *  r_do_abort 
)
static

Definition at line 297 of file task_iterator.c.

References Link::next, and NULL.

Referenced by BLI_task_parallel_listbase().