ParallelForWithTaskContext

General purpose parallel for that uses the taskgraph.

Choose your operating system:

Windows

macOS

Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Async/ParallelFor.h

Include

#include "Async/ParallelFor.h"

Syntax

template<typename ContextType, typename ContextAllocatorType, typename ContextConstructorType, typename FunctionType>
void ParallelForWithTaskContext
(
    TArray< ContextType, ContextAllocatorType > & OutContexts,
    int32 Num,
    const ContextConstructorType & ContextConstructor,
    const FunctionType & Body,
    EParallelForFlags Flags
)

Remarks

General purpose parallel for that uses the taskgraph. This variant constructs for the caller a user-defined context object for each task that may get spawned to do work, and passes it on to the loop body to give it a task-local "workspace" that can be mutated without need for synchronization primitives. For this variant, the user provides a callable to construct each context element.

Parameters

Parameter

Description

OutContexts;

Array that will hold the user-defined, task-level context objects (allocated per parallel task)

Num;

number of calls of Body; Body(0), Body(1)....Body(Num - 1)

ContextConstructor;

Function to call to initialize each task context allocated for the operation

Body;

Function to call from multiple threads

Flags;

Used to customize the behavior of the ParallelFor if needed. Notes: Please add stats around to calls to parallel for and within your lambda as appropriate. Do not clog the task graph with long running tasks or tasks that block.