Task Programming Model - Maple Help

Introduction

 • The Task Programming Model is a high-level multithreaded programming model.  It is designed to allow Maple code to be written that takes advantage of multiple processors, while avoiding much of the complexity of traditional multithreaded programming.
 • Here are a few advantages of using the Task Programming Model:
 • Maple schedules the Tasks to the processors so that the code scales to the number of available processors.
 • Multiple algorithms written using the Task Programming Model can run at the same time without significant performance impact.
 • Complex problems can be solved without requiring traditional synchronization tools such as Mutexes and Condition Variables.
 • If such synchronization tools are not used, the function cannot be deadlocked.
 • The Task functions are simple and the model mirrors conventional function calling.

Overview

 • Consider the following Maple function:
 > f := proc( args )     # work     ...     return cont( fc1( c1args ), fc2( c2args ) ); end proc;
 • To compute f, we do some work, execute fc1, then fc2, then finally execute cont by passing the return values of fc1 and fc2 as arguments.
 • In the Task Programming Model, instead of executing fc1, fc2, and cont in the same thread, we create a task for each function.  A task is a small unit of work, represented in Maple by a function call, that is, a procedure and the arguments to that procedure.  Some of the arguments to the procedure may be the result of evaluating other tasks.  If all of a task's arguments are available, it can be executed.  If some arguments are not available, the task waits for the results to be available.  In this example, fc1 and fc2 could be executed immediately, however cont cannot.  When fc1 and fc2 are complete, their return values are passed to cont. When cont gets its arguments, it can be executed.

As tasks create new tasks, a dependency tree is created where some tasks wait for other tasks to complete before they can execute.

 • Here is a simple example of a Task-based implementation of add:

Start creates the initial task and then waits until that task is complete. In this example

creates a task that executes task( 1,10^8 ). task checks the size of the range, and if it is small enough, we simply compute the add directly. If the range is large enough, we split it in half and create two child tasks.