TTaskDispatcher - task-based parallel programming
Concepts:
- task: a small part of a bigger job that is independent from the others (it doesn't access (write) the same data structure). A task is typically
a small portion of a calculation process that uses the processor with maximum load (in one thread).
- thread pool: a structure that can run jobs (tasks) in precreated and continously existing threads (where the number of threads is constant).
A thread pool can receive tasks to execute and notify the caller when the execution finished
Features:
- OOP programming of parallel algorithms in C++ (with inheritance)
- Thread pool implementation - the number of threads is always limited (practically to the number of processors)
- The number of working threads in the thread pool is parameterizable (better control on the resource consumption)
- Task control (creation of tasks, actions after task execution)
- Easy programming of simple parallel processes (there are no relations between the tasks and they can be created and parameterized before the whole parallel processing starts)
- Easy programming of recursive algorithms (the algorithm has to be able to start tasks from within the current processing). Tail- and non tail-recursive programming is possible
- Deeper recursive iteration: as the recursion is extracted to tasks (allocated on the heap), the implementation doesn't use the stack - the depth of the recursion is limited only by the available memory
- Scalability - linear performance change (increase) with the growing number of processors
- Control over the tasks execution: task execution can be called in different modes.
The dispatcher always executes as many tasks parallely as it is possible (the number of threads in the thread pool) and the new tasks can be pushed to a queue if there is no processor capacity to execute it.
The size of this queue can be limited and if this is reached (the caller receives information about this), the system is overloaded (todo: error handling).
Applications that use this parallelization:
- MEditor - this uses the parallel implementation of the QuickSort algorithm
- axargs - parallel command execution
- asort - parallel QuickSort
- imageresize - image resizing in parallel mode
Code samples: