13#include "Containers/Array.h"
71 template <
typename FunctionType,
typename ContextType>
74 Body(Contexts[TaskIndex],
Index);
78 template <
typename FunctionType>
115 template<
typename BodyType,
typename PreWorkType,
typename ContextType>
131 if (AutoRTFM::IsClosed())
141 NumWorkers = FMath::Min(NumWorkers, Contexts.
Num());
163 for (
int32 Div = 6; Div; Div--)
165 if (
Num >= (NumWorkers * Div))
167 BatchSize = FMath::DivideAndRoundUp<int32>(
Num, (NumWorkers * Div));
168 NumBatches = FMath::DivideAndRoundUp<int32>(
Num, BatchSize);
170 if (NumBatches >= NumWorkers)
229 CaptureInheritedContext();
246 return WorkerIndex >=
Tasks.Num() ? -1 : WorkerIndex;
249 const TCHAR* DebugName;
286 FParallelExecutor::LaunchTask(
MoveTemp(Data), WorkerIndex);
295 inline bool operator()(
const bool bIsMaster =
false)
const noexcept
303 TraceId = Data->Tasks[WorkerIndex].TraceId;
314 const int32 NumBatches = Data->NumBatches;
318 if (
bIsMaster ==
false && Data->BatchItem.load(std::memory_order_relaxed) + 2 <= NumBatches)
337 const int32 BatchSize = Data->BatchSize;
344 int32 BatchIndex = Data->BatchItem.fetch_add(1, std::memory_order_relaxed);
353 BatchIndex = (NumBatches - 1);
356 int32 StartIndex = BatchIndex * BatchSize;
357 int32 EndIndex = FMath::Min<int32>(StartIndex + BatchSize,
Num);
373 Data->FinishedSignal->Trigger();
378 else if (EndIndex >=
Num)
387 auto PassedTime = [Start, &Now]() {
return Now() - Start; };
418 const int32 WorkerIndex =
InData->GetNextWorkerIndexToLaunch();
419 if (WorkerIndex != -1)
431 FParallelExecutor::LaunchAnotherWorkerIfNeeded(Data);
495template<
typename FunctionType>
510template<
typename FunctionType>
603template <
typename ContextType,
typename ContextAllocatorType,
typename ContextConstructorType,
typename BodyType,
typename PreWorkType>
605 const TCHAR* DebugName,
637template <
typename ContextType,
typename ContextAllocatorType,
typename BodyType,
typename PreWorkType>
639 const TCHAR* DebugName,
667template <
typename ContextType,
typename BodyType,
typename PreWorkType>
669 const TCHAR* DebugName,
693template <
typename ContextType,
typename ContextAllocatorType,
typename ContextConstructorType,
typename FunctionType>
721template <
typename ContextType,
typename ContextAllocatorType,
typename ContextConstructorType,
typename FunctionType>
737template <
typename ContextType,
typename ContextAllocatorType,
typename FunctionType>
763template <
typename ContextType,
typename ContextAllocatorType,
typename ContextConstructorType,
typename FunctionType>
791template <
typename ContextType,
typename ContextAllocatorType,
typename FunctionType>
814template <
typename ContextType,
typename FunctionType>
832template <
typename ContextType,
typename FunctionType>
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define verify(expr)
Definition AssertionMacros.h:319
ETaskTag
Definition CoreGlobals.h:642
CORE_API int32 GParallelForBackgroundYieldingTimeoutMs
Definition ParallelFor.cpp:8
void ParallelForWithPreWorkWithTaskContext(const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, int32 MinBatchSize, ContextConstructorType &&ContextConstructor, BodyType &&Body, PreWorkType &&CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:604
EParallelForFlags
Definition ParallelFor.h:47
void ParallelForWithExistingTaskContext(TArrayView< ContextType > Contexts, int32 Num, int32 MinBatchSize, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:815
void ParallelFor(int32 Num, TFunctionRef< void(int32)> Body, bool bForceSingleThread, bool bPumpRenderingThread=false)
Definition ParallelFor.h:481
void ParallelForWithPreWork(int32 Num, TFunctionRef< void(int32)> Body, TFunctionRef< void()> CurrentThreadWorkToDoBeforeHelping, bool bForceSingleThread, bool bPumpRenderingThread=false)
Definition ParallelFor.h:556
CORE_API bool GParallelForDisableOversubscription
Definition ParallelFor.cpp:15
void ParallelForWithPreWorkWithExistingTaskContext(const TCHAR *DebugName, TArrayView< ContextType > Contexts, int32 Num, int32 MinBatchSize, BodyType &&Body, PreWorkType &&CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:668
void ParallelForTemplate(int32 Num, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:496
void ParallelForWithTaskContext(const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, const ContextConstructorType &ContextConstructor, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:694
#define SCOPE_CYCLE_COUNTER(Stat)
Definition Stats.h:650
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define TRACE_CPUPROFILER_EVENT_SCOPE(Name)
Definition CpuProfilerTrace.h:528
#define TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(Name)
Definition CpuProfilerTrace.h:532
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
CORE_API int32 GParallelForBackgroundYieldingTimeoutMs
Definition ParallelFor.cpp:8
CORE_API bool GParallelForDisableOversubscription
Definition ParallelFor.cpp:15
#define ON_SCOPE_EXIT
Definition ScopeExit.h:73
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
CORE_API bool IsInActualRenderingThread()
Definition ThreadingBase.cpp:258
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
static CORE_API bool ShouldUseThreadingForPerformance()
Definition App.cpp:300
static CORE_API bool IsForkedMultithreadInstance()
Definition Fork.cpp:103
Definition MemStack.h:506
static CORE_API FTaskGraphInterface & Get()
Definition TaskGraph.cpp:1794
virtual uint64 ProcessThreadUntilIdle(ENamedThreads::Type CurrentThread)=0
Definition RefCounting.h:283
static FScheduler & Get()
Definition Scheduler.h:215
Definition Oversubscription.h:23
Definition ArrayView.h:139
UE_FORCEINLINE_HINT constexpr SizeType Num() const
Definition ArrayView.h:380
constexpr bool IsEmpty() const
Definition ArrayView.h:370
Definition ConcurrentLinearAllocator.h:571
Definition AssetRegistryState.h:50
Definition RefCounting.h:454
static FORCEINLINE FMemStack & Get()
Definition ThreadSingleton.h:101
Definition InheritedContext.h:118
CORE_API FInheritedContextScope RestoreInheritedContext()
Definition InheritedContext.cpp:8
Definition InheritedContext.h:54
@ AnyThread
Definition TaskGraphInterfaces.h:67
UE_FORCEINLINE_HINT Type GetRenderThread_Local()
Definition TaskGraphInterfaces.h:128
ETaskPriority
Definition Task.h:18
UE_FORCEINLINE_HINT bool TryLaunch(FTask &Task, EQueuePreference QueuePreference=EQueuePreference::DefaultPreference, bool bWakeUpWorker=true)
Definition Scheduler.h:181
Definition ParallelFor.h:68
int32 GetNumberOfThreadTasks(int32 Num, int32 MinBatchSize, EParallelForFlags Flags)
Definition ParallelFor.h:84
void CallBody(const FunctionType &Body, const TArrayView< ContextType > &Contexts, int32 TaskIndex, int32 Index)
Definition ParallelFor.h:72
void ParallelForInternal(const TCHAR *DebugName, int32 Num, int32 MinBatchSize, BodyType Body, PreWorkType CurrentThreadWorkToDoBeforeHelping, EParallelForFlags Flags, const TArrayView< ContextType > &Contexts)
Definition ParallelFor.h:116
void TASK_CORE_API Started(FId TaskId)
Definition TaskTrace.h:80
void TASK_CORE_API Launched(FId TaskId, const TCHAR *DebugName, bool bTracked, ENamedThreads::Type ThreadToExecuteOn, uint64 TaskSize)
Definition TaskTrace.h:77
const FId InvalidId
Definition TaskTrace.h:39
void TASK_CORE_API Destroyed(FId TaskId)
Definition TaskTrace.h:83
FId TASK_CORE_API GenerateTaskId()
Definition TaskTrace.h:74
uint64 FId
Definition TaskTrace.h:37
void TASK_CORE_API Completed(FId TaskId)
Definition TaskTrace.h:82
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
static CORE_API int32 NumberOfCoresIncludingHyperthreads()
Definition AndroidPlatformMisc.cpp:977
static double Seconds()
Definition AndroidPlatformTime.h:20
static FTimespan MinValue()
Definition Timespan.h:699
static FTimespan FromSeconds(double Seconds)
Definition Timespan.h:673
static FTimespan FromMilliseconds(double Milliseconds)
Definition Timespan.h:649