UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ParallelFor.h File Reference

Go to the source code of this file.

Namespaces

namespace  UE
 
namespace  UE::LLMPrivate
 
namespace  ParallelForImpl
 

Enumerations

enum class  EParallelForFlags {
  None , ForceSingleThread = 1 , Unbalanced = 2 , PumpRenderingThread = 4 ,
  BackgroundPriority = 8
}
 

Functions

template<typename FunctionType , typename ContextType >
void ParallelForImpl::CallBody (const FunctionType &Body, const TArrayView< ContextType > &Contexts, int32 TaskIndex, int32 Index)
 
template<typename FunctionType >
void ParallelForImpl::CallBody (const FunctionType &Body, const TArrayView< TYPE_OF_NULLPTR > &, int32, int32 Index)
 
int32 ParallelForImpl::GetNumberOfThreadTasks (int32 Num, int32 MinBatchSize, EParallelForFlags Flags)
 
template<typename BodyType , typename PreWorkType , typename ContextType >
void ParallelForImpl::ParallelForInternal (const TCHAR *DebugName, int32 Num, int32 MinBatchSize, BodyType Body, PreWorkType CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags, const TArrayView< ContextType > &Contexts)
 
void ParallelFor (int32 Num, TFunctionRef< void(int32)> Body, bool bForceSingleThread, bool bPumpRenderingThread=false)
 
template<typename FunctionType >
void ParallelForTemplate (int32 Num, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename FunctionType >
void ParallelForTemplate (const TCHAR *DebugName, int32 Num, int32 MinBatchSize, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
void ParallelFor (int32 Num, TFunctionRef< void(int32)> Body, EParallelForFlags Flags=EParallelForFlags::None)
 
void ParallelFor (const TCHAR *DebugName, int32 Num, int32 MinBatchSize, TFunctionRef< void(int32)> Body, EParallelForFlags Flags=EParallelForFlags::None)
 
void ParallelForWithPreWork (int32 Num, TFunctionRef< void(int32)> Body, TFunctionRef< void()> CurrentThreadWorkToDoBeforeHelping, bool bForceSingleThread, bool bPumpRenderingThread=false)
 
void ParallelForWithPreWork (int32 Num, TFunctionRef< void(int32)> Body, TFunctionRef< void()> CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
 
void ParallelForWithPreWork (const TCHAR *DebugName, int32 Num, int32 MinBatchSize, TFunctionRef< void(int32)> Body, TFunctionRef< void()> CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename ContextConstructorType , typename BodyType , typename PreWorkType >
void ParallelForWithPreWorkWithTaskContext (const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, int32 MinBatchSize, ContextConstructorType &&ContextConstructor, BodyType &&Body, PreWorkType &&CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename BodyType , typename PreWorkType >
void ParallelForWithPreWorkWithTaskContext (const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, int32 MinBatchSize, BodyType &&Body, PreWorkType &&CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename BodyType , typename PreWorkType >
void ParallelForWithPreWorkWithExistingTaskContext (const TCHAR *DebugName, TArrayView< ContextType > Contexts, int32 Num, int32 MinBatchSize, BodyType &&Body, PreWorkType &&CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename ContextConstructorType , typename FunctionType >
void ParallelForWithTaskContext (const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, const ContextConstructorType &ContextConstructor, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
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=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename FunctionType >
void ParallelForWithTaskContext (TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename ContextConstructorType , typename FunctionType >
void ParallelForWithTaskContext (const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, int32 MinBatchSize, const ContextConstructorType &ContextConstructor, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename ContextAllocatorType , typename FunctionType >
void ParallelForWithTaskContext (const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, int32 MinBatchSize, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename FunctionType >
void ParallelForWithExistingTaskContext (TArrayView< ContextType > Contexts, int32 Num, int32 MinBatchSize, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 
template<typename ContextType , typename FunctionType >
void ParallelForWithExistingTaskContext (const TCHAR *DebugName, TArrayView< ContextType > Contexts, int32 Num, int32 MinBatchSize, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
 

Variables

CORE_API int32 GParallelForBackgroundYieldingTimeoutMs
 
CORE_API bool GParallelForDisableOversubscription
 

Enumeration Type Documentation

◆ EParallelForFlags

enum class EParallelForFlags
strong
Enumerator
None 
ForceSingleThread 
Unbalanced 
PumpRenderingThread 
BackgroundPriority 

Function Documentation

◆ ParallelFor() [1/3]

void ParallelFor ( const TCHAR DebugName,
int32  Num,
int32  MinBatchSize,
TFunctionRef< void(int32)>  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph for unbalanced tasks Offers better work distribution among threads at the cost of a little bit more synchronization. This should be used for tasks with highly variable computational time.

Parameters
DebugName;ProfilingScope and Debugname
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
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.

◆ ParallelFor() [2/3]

void ParallelFor ( int32  Num,
TFunctionRef< void(int32)>  Body,
bool  bForceSingleThread,
bool  bPumpRenderingThread = false 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
Body;Function to call from multiple threads
bForceSingleThread;Mostly used for testing, if true, run single threaded instead. 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.

◆ ParallelFor() [3/3]

void ParallelFor ( int32  Num,
TFunctionRef< void(int32)>  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph for unbalanced tasks Offers better work distribution among threads at the cost of a little bit more synchronization. This should be used for tasks with highly variable computational time.

Parameters
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
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.

◆ ParallelForTemplate() [1/2]

template<typename FunctionType >
void ParallelForTemplate ( const TCHAR DebugName,
int32  Num,
int32  MinBatchSize,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
DebugName;ProfilingScope and Debugname
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
Body;Function to call from multiple threads
bForceSingleThread;Mostly used for testing, if true, run single threaded instead. 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.

◆ ParallelForTemplate() [2/2]

template<typename FunctionType >
void ParallelForTemplate ( int32  Num,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
Body;Function to call from multiple threads
bForceSingleThread;Mostly used for testing, if true, run single threaded instead. 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.

◆ ParallelForWithExistingTaskContext() [1/2]

template<typename ContextType , typename FunctionType >
void ParallelForWithExistingTaskContext ( const TCHAR DebugName,
TArrayView< ContextType >  Contexts,
int32  Num,
int32  MinBatchSize,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph. This variant takes an array of user-defined context objects for each task that may get spawned to do work (one task per context at most), and passes them to the loop body to give it a task-local "workspace" that can be mutated without need for synchronization primitives.

Parameters
DebugName;ProfilingScope and Debugname
Contexts;User-privided array of user-defined task-level context objects
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
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.

◆ ParallelForWithExistingTaskContext() [2/2]

template<typename ContextType , typename FunctionType >
void ParallelForWithExistingTaskContext ( TArrayView< ContextType >  Contexts,
int32  Num,
int32  MinBatchSize,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph. This variant takes an array of user-defined context objects for each task that may get spawned to do work (one task per context at most), and passes them to the loop body to give it a task-local "workspace" that can be mutated without need for synchronization primitives.

Parameters
Contexts;User-privided array of user-defined task-level context objects
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
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.

◆ ParallelForWithPreWork() [1/3]

void ParallelForWithPreWork ( const TCHAR DebugName,
int32  Num,
int32  MinBatchSize,
TFunctionRef< void(int32)>  Body,
TFunctionRef< void()>  CurrentThreadWorkToDoBeforeHelping,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
DebugName;ProfilingScope and Debugname
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
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.

◆ ParallelForWithPreWork() [2/3]

void ParallelForWithPreWork ( int32  Num,
TFunctionRef< void(int32)>  Body,
TFunctionRef< void()>  CurrentThreadWorkToDoBeforeHelping,
bool  bForceSingleThread,
bool  bPumpRenderingThread = false 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
bForceSingleThread;Mostly used for testing, if true, run single threaded instead. 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.

◆ ParallelForWithPreWork() [3/3]

void ParallelForWithPreWork ( int32  Num,
TFunctionRef< void(int32)>  Body,
TFunctionRef< void()>  CurrentThreadWorkToDoBeforeHelping,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
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.

◆ ParallelForWithPreWorkWithExistingTaskContext()

template<typename ContextType , typename BodyType , typename PreWorkType >
void ParallelForWithPreWorkWithExistingTaskContext ( const TCHAR DebugName,
TArrayView< ContextType >  Contexts,
int32  Num,
int32  MinBatchSize,
BodyType &&  Body,
PreWorkType &&  CurrentThreadWorkToDoBeforeHelping,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
DebugName;ProfilingScope and DebugName
Contexts;User-privided array of user-defined task-level context objects
Num;number of calls of Body; Body(0), Body(1), ..., Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
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.

◆ ParallelForWithPreWorkWithTaskContext() [1/2]

void ParallelForWithPreWorkWithTaskContext ( const TCHAR DebugName,
TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
int32  MinBatchSize,
BodyType &&  Body,
PreWorkType &&  CurrentThreadWorkToDoBeforeHelping,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
DebugName;ProfilingScope and DebugName
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)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
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.

◆ ParallelForWithPreWorkWithTaskContext() [2/2]

void ParallelForWithPreWorkWithTaskContext ( const TCHAR DebugName,
TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
int32  MinBatchSize,
ContextConstructorType &&  ContextConstructor,
BodyType &&  Body,
PreWorkType &&  CurrentThreadWorkToDoBeforeHelping,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

General purpose parallel for that uses the taskgraph

Parameters
DebugName;ProfilingScope and DebugName
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)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
ContextConstructor;Function to call to initialize each task context allocated for the operation
Body;Function to call from multiple threads
CurrentThreadWorkToDoBeforeHelping;The work is performed on the main thread before it starts helping with the ParallelFor proper
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.

◆ ParallelForWithTaskContext() [1/5]

void ParallelForWithTaskContext ( const TCHAR DebugName,
TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
const ContextConstructorType ContextConstructor,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

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
OutContexts;Array that will hold the user-defined, task-level context objects (allocated per parallel task)
DebugName;ProfilingScope and Debugname
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.

◆ ParallelForWithTaskContext() [2/5]

void ParallelForWithTaskContext ( const TCHAR DebugName,
TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
int32  MinBatchSize,
const ContextConstructorType ContextConstructor,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

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
OutContexts;Array that will hold the user-defined, task-level context objects (allocated per parallel task)
DebugName;ProfilingScope and Debugname
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
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.

◆ ParallelForWithTaskContext() [3/5]

template<typename ContextType , typename ContextAllocatorType , typename FunctionType >
void ParallelForWithTaskContext ( const TCHAR DebugName,
TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
int32  MinBatchSize,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

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.

Parameters
OutContexts;Array that will hold the user-defined, task-level context objects (allocated per parallel task)
DebugName;ProfilingScope and Debugname
Num;number of calls of Body; Body(0), Body(1)....Body(Num - 1)
MinBatchSize;Minimum Size of a Batch (will only launch DivUp(Num, MinBatchSize) Workers
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.

◆ ParallelForWithTaskContext() [4/5]

void ParallelForWithTaskContext ( TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
const ContextConstructorType ContextConstructor,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

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
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.

◆ ParallelForWithTaskContext() [5/5]

template<typename ContextType , typename ContextAllocatorType , typename FunctionType >
void ParallelForWithTaskContext ( TArray< ContextType, ContextAllocatorType > &  OutContexts,
int32  Num,
const FunctionType &  Body,
EParallelForFlags  Flags = EParallelForFlags::None 
)
inline

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.

Parameters
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)
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.

Variable Documentation

◆ GParallelForBackgroundYieldingTimeoutMs

CORE_API int32 GParallelForBackgroundYieldingTimeoutMs
extern

◆ GParallelForDisableOversubscription

CORE_API bool GParallelForDisableOversubscription
extern