3#include <Foundation/Memory/FrameAllocator.h>
4#include <Foundation/Profiling/Profiling.h>
6template <
typename ElemType>
12 , m_uiItemsPerInvocation(uiItemsPerInvocation)
13 , m_TaskCallback(std::move(taskCallback))
20 m_TaskCallback(0, m_Payload);
25 const plUInt32 uiSliceStartIndex = uiInvocation * m_uiItemsPerInvocation;
27 const plUInt32 uiRemainingItems = uiSliceStartIndex > m_Payload.
GetCount() ? 0 : m_Payload.
GetCount() - uiSliceStartIndex;
28 const plUInt32 uiSliceItemCount =
plMath::Min(m_uiItemsPerInvocation, uiRemainingItems);
30 if (uiSliceItemCount > 0)
33 auto taskItemSlice = m_Payload.
GetSubArray(uiSliceStartIndex, uiSliceItemCount);
34 m_TaskCallback(uiSliceStartIndex, taskItemSlice);
40 plUInt32 m_uiItemsPerInvocation;
44template <
typename ElemType>
50 arrayPtrTask.ConfigureTask(taskName ? taskName :
"Generic ArrayPtr Task", params.m_NestingMode);
52 PL_PROFILE_SCOPE(arrayPtrTask.m_sTaskName);
53 arrayPtrTask.Execute();
57 plUInt32 uiMultiplicity;
58 plUInt64 uiItemsPerInvocation;
59 params.DetermineThreading(taskItems.
GetCount(), uiMultiplicity, uiItemsPerInvocation);
64 pArrayPtrTask->ConfigureTask(taskName ? taskName :
"Generic ArrayPtr Task", params.m_NestingMode);
66 pArrayPtrTask->SetMultiplicity(uiMultiplicity);
72template <
typename ElemType,
typename Callback>
75 auto wrappedCallback = [taskCallback = std::move(taskCallback)](
77 { taskCallback(taskSlice); };
79 ParallelForInternal<ElemType>(
83template <
typename ElemType,
typename Callback>
86 auto wrappedCallback = [taskCallback = std::move(taskCallback)](plUInt32 ,
plArrayPtr<ElemType> taskSlice)
89 for (ElemType& taskItem : taskSlice)
91 taskCallback(taskItem);
95 ParallelForInternal<ElemType>(
99template <
typename ElemType,
typename Callback>
103 auto wrappedCallback = [taskCallback = std::move(taskCallback)](plUInt32 uiBaseIndex,
plArrayPtr<ElemType> taskSlice)
105 for (plUInt32 uiIndex = 0; uiIndex < taskSlice.GetCount(); ++uiIndex)
108 taskCallback(uiBaseIndex + uiIndex, *(taskSlice.GetPtr() + uiIndex));
112 ParallelForInternal<ElemType>(
Definition ParallelFor_inl.h:8
void ExecuteWithMultiplicity(plUInt32 uiInvocation) const override
Override this to implement the task's supposed functionality.
Definition ParallelFor_inl.h:23
void Execute() override
Override this to implement the task's supposed functionality.
Definition ParallelFor_inl.h:17
Base class for all memory allocators.
Definition Allocator.h:23
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
PL_ALWAYS_INLINE plUInt32 GetCount() const
Returns the number of elements in the array.
Definition ArrayPtr.h:142
PL_FORCE_INLINE plArrayPtr< T > GetSubArray(plUInt32 uiStart, plUInt32 uiCount) const
Creates a sub-array from this array.
Definition ArrayPtr.h:148
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Given out by plTaskSystem::CreateTaskGroup to identify a task group.
Definition TaskSystemDeclarations.h:103
Base class for custom tasks.
Definition Task.h:10
static void ParallelForSingleIndex(plArrayPtr< ElemType > taskItems, Callback taskCallback, const char *szTaskName=nullptr, const plParallelForParams ¶ms=plParallelForParams())
Definition ParallelFor_inl.h:100
static void WaitForGroup(plTaskGroupID group)
Blocks until all tasks in the given group have finished.
Definition TaskSystemGroups.cpp:274
static void ParallelForSingle(plArrayPtr< ElemType > taskItems, Callback taskCallback, const char *szTaskName=nullptr, const plParallelForParams ¶ms=plParallelForParams())
Definition ParallelFor_inl.h:84
static void ParallelFor(plArrayPtr< ElemType > taskItems, Callback taskCallback, const char *szTaskName=nullptr, const plParallelForParams ¶ms=plParallelForParams())
Definition ParallelFor_inl.h:73
static plTaskGroupID StartSingleTask(const plSharedPtr< plTask > &pTask, plTaskPriority::Enum priority, plOnTaskGroupFinishedCallback callback=plOnTaskGroupFinishedCallback())
A helper function to insert a single task into the system and start it right away....
Definition TaskSystemTasks.cpp:20
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Settings for plTaskSystem::ParallelFor invocations.
Definition TaskSystemDeclarations.h:167
plAllocator * m_pTaskAllocator
The allocator used to for the tasks that the parallel-for uses internally. If null,...
Definition TaskSystemDeclarations.h:186
plUInt32 m_uiBinSize
Definition TaskSystemDeclarations.h:173
@ EarlyThisFrame
Highest priority, guaranteed to get finished in this frame.
Definition TaskSystemDeclarations.h:42