The task system schedules functions and inputs to run on a preset number of threads. The number of threads to be used is given by the variable allowableThreads, and may be examined and changed as follows.
|
|
To run a function in another thread use schedule, as in the following example.
|
|
|
|
|
Note that schedule returns a task, not the result of the computation, which will be accessible only after the task has completed the computation.
|
Use isReady to check whether the result is available yet.
|
|
To retrieve the result, use taskResult.
|
|
It is possible to make a task without starting it running, using createTask.
|
|
Start it running with schedule.
|
|
|
|
One may use addStartTask to specify that one task is to be started after another one finishes. In the following example, G will start after F finishes.
|
|
|
|
|
|
|
|
Use addCancelTask to specify that the completion of one task triggers the cancellation of another, by means of an interrupt exception.
Use addDependencyTask to schedule a task, but to ensure that it will not run until one or more other tasks finish running.
Using the functions above, essentially any parallel functionality needed can be created.
Low level C API functionality using the same scheduler also exists in the Macaulay2/system directory. It works essentially the same way as the Macaulay2 interface.
Warning: Access to external libraries such as singular, etc., may not currently be thread safe.