Navigation
API > API/Plugins > API/Plugins/PCG
Description
A Helper for generic parallel loops, with support for timeslicing. This version only uses indexes allowing more flexible usage to process many arrays in parallel or use it for other batch updating.
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::AsyncProcessingEx |
| Type | function |
| Header File | /Engine/Plugins/PCG/Source/PCG/Public/Helpers/PCGAsync.h |
| Include Path | #include "Helpers/PCGAsync.h" |
namespace FPCGAsync
{
template<typename InitializeFunc, typename ProcessElementFunc, typename MoveFunc, typename FinishedFunc>
bool FPCGAsync::AsyncProcessingEx
(
FPCGAsyncState * AsyncState,
int32 NumIterations,
InitializeFunc && Initialize,
ProcessElementFunc && ProcessElement,
MoveFunc && MoveData,
FinishedFunc && Finished,
const bool bEnableTimeSlicing,
const int32 ChunkSize,
const 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. |
| Initialize | Signature: void(). A function that will be called once on the first timeslice, where you can reserve data for processing |
| ProcessElement | Signature: bool(int32 ReadIndex, int32 WriteIndex). A function that processes |
| MoveData | Signature: void(int32 ReadIndex, int32 WriteIndex). If the processing filters points, this will be used to move elements from one index to another |
| Finished | Signature: void(int32 Count). Called once on finished, and tells you the total count of points written. |
| 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 |