About
The static classes maxon::ParallelFor, maxon::ParallelImage and maxon::ParallelInvoke are used to execute parallelized code.
ParallelFor
The maxon::ParallelFor class is used to execute code defined in a worker method. This code is executed in a loop distributed over multiple threads. The workload is distributed either dynamically or statically.
{
pointStates[i] = false;
pointStates[i] = true;
};
{
if (pointInside)
insideCount++;
}
maxon::ParallelFor::BreakContext is a base class to define a context for maxon::ParallelFor loops that support cancellation. A class based on maxon::ParallelFor::BreakContext stores the data handled in a thread.
maxon::ParallelFor can call additional "Init" and "Finalize" functions for each thread. The behaviour is defined with these flags:
{
};
auto init = [](LocalData& context)
{
context.localCount = 0;
};
auto worker = [](
maxon::Int i, LocalData& context)
{
context.localCount++;
};
auto finalize = [&insideCount](LocalData& context)
{
insideCount += context.localCount;
};
maxon::ParallelFor::Dynamic<LocalData, maxon::PARALLELFORFLAGS::INITTHREADED_FINALIZESYNC>(0, count, init, worker, finalize)
iferr_return;
ParallelImage
maxon::ParallelImage is a special class to process image data of a given size per pixel.
if (bitmap == nullptr)
{
const maxon::Int32 red = maxon::SafeConvert<maxon::Int32>(u * 255.9);
const maxon::Int32 green = maxon::SafeConvert<maxon::Int32>(v * 255.9);
};
ParallelInvoke
The maxon::ParallelInvoke function can be used to execute multiple arbitrary functions in parallel.
maxon::Float minA = 0.0, maxA = 0.0, minB = 0.0, maxB = 0.0;
[&arrayA, &minA, &maxA] { GetMinMax(arrayA, minA, maxA); },
[&araryB, &minB, &maxB] { GetMinMax(araryB, minB, maxB); }
if ((minA > minB) && (maxA < maxB))
DiagnosticOutput(
"Min/max values of a array A are within the min/max values of array B"_s);
Further Reading
@ OK
Image loaded/created.
static void Process(Int width, Int height, Int tileSize, const WORKER &worker)
Definition: parallelimage.h:216
int64_t Int64
64 bit signed integer datatype.
Definition: apibase.h:174
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1077
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:177
#define iferr_return
Definition: resultbase.h:1434
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
Float64 Float
Definition: apibase.h:193
Definition: basearray.h:366
static IMAGERESULT Init(BaseBitmap *&res, const Filename &name, Int32 frame=-1, Bool *ismovie=nullptr, BitmapLoaderPlugin **loaderplugin=nullptr, const maxon::Delegate< void(Float progress)> &progressCallback=nullptr)
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:166
static auto Dynamic(FROMTYPE from, INDEXTYPE to, const LOOP &obj, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) -> decltype(obj(to))
Definition: parallelfor.h:238
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:172
Bool SetPixel(Int32 x, Int32 y, Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:704
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:184
uint32_t UInt32
32 bit unsigned integer datatype.
Definition: apibase.h:173
Definition: lib_math.h:18
A vector consisting of three components X, Y and Z.
Definition: vec2.h:14
maxon::Int32 Int32
Definition: ge_sys_math.h:58
Bool ShowBitmap(const Filename &fn)
constexpr T GetSquaredLength() const
Returns the squared length of the vector.
Definition: vec2.h:388
Definition: ge_autoptr.h:36
IMAGERESULT
Definition: ge_prepass.h:3659
Context for ParallelFor loops that support cancellation.
Definition: parallelfor.h:188
FLOAT Get01()
Returns the next random value in the range of [0..1].
Result< void > ParallelInvoke(Bool parallel, ARGS &&... args)
Definition: parallelinvoke.h:153