Collectives¶
Usage
use Collectives;
or
import Collectives;
Support for barriers between tasks.
The barrier type provided in this module can be used to prevent tasks from proceeding until all other related tasks have also reached the barrier.
In the following example, all of the tasks created by the coforall loop will print their “entering the barrier” messages in an unspecified order, then all of the tasks will print their “past the barrier” messages, also in an unspecified order. Because of the barrier, all of the “entering the barrier” messages will be printed before any of the “past the barrier” messages.
use Collectives;
config const numTasks = here.maxTaskPar;
var b = new barrier(numTasks);
coforall tid in 1..numTasks {
writeln("Task ", tid, " is entering the barrier");
b.barrier();
writeln("Task ", tid, " is past the barrier");
}
Note: When a barrier instance goes out of scope it is automatically deleted. After it is deleted, any copies of the barrier that remain are invalid.
Future direction¶
In the future, we expect to add more language-level support for a “task-team” concept. A task-team will more directly support collective operations such as barriers between the tasks within a team.
The current implementation is designed for correctness, but is not expected to perform well at scale. We expect performance at scale to improve as this barrier implementation is optimized and as the task-team concept is implemented and optimized.
- enum BarrierType { Atomic, Sync }¶
An enumeration of the different barrier implementations. Used to choose the implementation to use when constructing a new barrier object.
BarrierType.Atomic uses Chapel atomic variables to control the barrier.
BarrierType.Sync uses Chapel sync variables to control the barrier.
Warning
BarrierType is deprecated, please use the default barrier implementation
- record barrier¶
A barrier that will cause numTasks to wait before proceeding.
- proc init(numTasks: int)¶
Construct a new barrier object.
- Arguments
numTasks – The number of tasks that will use this barrier
- proc init(numTasks: int, reusable: bool)
Construct a new barrier object.
- Arguments
numTasks – The number of tasks that will use this barrier
reusable – Incur some extra overhead to allow reuse of this barrier?
Warning
non-reusable barriers are deprecated, please remove the ‘reusable’ argument from this initializer call
- proc init(numTasks: int, barrierType: BarrierType, reusable: bool = true)
Construct a new barrier object.
- Arguments
numTasks – The number of tasks that will use this barrier
barrierType – The barrier implementation to use
reusable – Incur some extra overhead to allow reuse of this barrier?
Warning
choosing a barrier type is deprecated, please remove the ‘barrierType’ argument
- proc barrier()¶
Block until all related tasks have called this method. If reusable is true, reset the barrier to be used again.
- proc notify()¶
Notify the barrier that this task has reached this point.
- proc wait()¶
Wait until n tasks have called
notify
. If reusable is true, reset the barrier to be used again.Note: if reusable is true the tasks will wait until all n tasks have called both
notify
andwait
at which point the barrier will automatically be reset for the next use. If reusable is false, each task callingwait
can return as soon as all n tasks have callednotify
.
- proc check(): bool¶
Warning
‘barrier.check()’ is deprecated, please use ‘!barrier.pending()’ instead