Module parallel_runner

Module parallel_runner 

Source
Expand description

API for running data operations in parallel in a multi-threaded environment. This module allows the JPEG XL caller to define their own way of creating and assigning threads.

The JxlParallelRunner function type defines a parallel data processing runner that may be implemented by the caller to allow the library to process in multiple threads. The multi-threaded processing in this library only requires to run the same function over each number of a range, possibly running each call in a different thread. The JPEG XL caller is responsible for implementing this logic using the thread APIs available in their system. For convenience, a C++ implementation based on std::thread is provided in super::thread_parallel_runner (part of the jpegxl_threads library).

Thread pools usually store small numbers of heterogeneous tasks in a queue. When tasks are identical or differ only by an integer input parameter, it is much faster to store just one function of an integer parameter and call it for each value. Conventional vector-of-tasks can be run in parallel using a lambda function adapter that simply calls task_funcs[task].

If no multi-threading is desired, a NULL value of JxlParallelRunner will use an internal implementation without multi-threading.

Constants§

JXL_PARALLEL_RET_RUNNER_ERROR
Code returned by the JxlParallelRunInit function to indicate a general error.
JXL_PARALLEL_RET_SUCCESS
Code returned by the JxlParallelRunInit function to indicate success.

Type Aliases§

JxlParallelRetCode
Return code used in the JxlParallel* functions as return value. A value of JXL_PARALLEL_RET_SUCCESS means success and any other value means error. The special value JXL_PARALLEL_RET_RUNNER_ERROR can be used by the runner to indicate any other error.
JxlParallelRunFunction
Parallel run data processing callback. See JxlParallelRunner for details.
JxlParallelRunInit
Parallel run initialization callback. See JxlParallelRunner for details.
JxlParallelRunner
JxlParallelRunner function type. A parallel runner implementation can be provided by a JPEG XL caller to allow running computations in multiple threads. This function must call the initialization function init in the same thread that called it and then call the passed func once for every number in the range [start_range, end_range) (including start_range but not including end_range) possibly from different multiple threads in parallel.