FixTask Documentation

Back to summary

import "task/task";

ComputeTask class

ComputeTask allows to run computation code in parallel on multiple CPU cores.

Functions

static function create(): ComputeTask
static function create(finish_data): ComputeTask
Creates a new compute task. The provided data is passed to the finish function and it's not cloned to the compute thread.
virtual function process(): Dynamic
Runs the computation code, the result is passed to finish function in the main thread.
virtual function finish(data, result)
Finishes the computation. The data is reference in the current thread and the result is cloned from the computation thread.
function run()
Runs the task in a computation thread. It also runs finish functions for any finished tasks.

Static functions

static function run(process_func, process_data)
static function run(process_func, process_data, finish_func, finish_data)
Runs the process function in the computation thread, passing the result back to finish function in the main thread.
static function check_finished()
Checks for finished computation tasks to run their finish functions.
static function finish_all()
Waits for all unfinished computation tasks to finish and run their finish functions.
static function get_core_count(): Integer
Returns the number of CPU cores available for computation.
static function run_parallel(start: Integer, end: Integer, func, data)
static function run_parallel(start: Integer, end: Integer, min_iters: Integer, func, data)
Runs the provided function in parallel dividing the interval (end is exclusive) between the CPU cores. You can optionally pass the minimum iterations per CPU core. In case the task is too lightweight and wouldn't need more than one CPU core it is directly run. This function enables parallel readonly access (and readwrite for shared arrays) to the heap from the compute heaps using the ParentRef class.

The passed function must have this signature:
function func(data, from: Integer, to: Integer, core_id: Integer)
The from and to represent a subinterval for given CPU core (end is exclusive).