Navigation
API > API/Plugins > API/Plugins/PCG
Description
Helper for generic parallel loops, with support for timeslicing. This version takes a data type, expecting processing on an array of that type.
Work will be separated in chunks, that will be processed in parallel. Main thread will then collapse incoming data from async tasks. Will use AsyncState.ShouldStop() to stop execution if timeslicing is enabled. Important info:
- We will finish to process and collapse data for all data already in process, even if we need to stop. To mitigate this, try to use small chunk sizes.
- To avoid infinite loops (when we should stop even before starting working), we will at least process 1 chunk of data per thread.
- To have async tasks, you need to have at least 3 available threads (main thread + 2 futures). Otherwise, we will only process on the main thread, without collapse.
| Name | FPCGAsync::AsyncProcessing |
| Type | function |
| Header File | /Engine/Plugins/PCG/Source/PCG/Public/Helpers/PCGAsync.h |
| Include Path | #include "Helpers/PCGAsync.h" |
namespace FPCGAsync
{
template<typename OutputType, typename Func, typename AllocatorType>
bool FPCGAsync::AsyncProcessing
(
FPCGAsyncState * AsyncState,
int32 NumIterations,
TArray < OutputType, AllocatorType > & OutData,
Func && InFunc,
const bool bEnableTimeSlicing,
const int32 ChunkSize,
bool bAllowChunkSizeOverride
)
}
true if the processing is done, false otherwise. Use this to know if you need to reschedule the task.
Parameters
| Name | Remarks |
|---|---|
| AsyncState | The context containing the information about how many tasks we can launch, async read/write index for the current job and a function to know if we need to stop processing. |
| NumIterations | The number of calls that will be done to the provided function, also an upper bound on the number of data generated. |
| OutData | The array in which the results will be written to. Note that the array will be cleared before execution. |
| Func | Signature: bool(int32, OutputType&). A function that has the index [0; NumIterations] and has to write to some data & return false if the result should be discarded. |
| bEnableTimeSlicing | If false, we will not stop until all the processing is done. |
| ChunkSize | Size of the chunks to cut the input data with |
| bAllowChunkSizeOverride | If true, ChunkSize can be overridden by 'pcg.AsyncOverrideChunkSize' CVar |