Barriers

Usage

use Barriers;

or

import Barriers;

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 Barriers;

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.

Warning

The ‘Barriers’ module is deprecated, please use ‘Collectives’ instead

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.

Warning

The ‘Barrier’ type is deprecated, please use ‘Collectives.barrier’ instead

proc init(numTasks: int, 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?

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 and wait at which point the barrier will automatically be reset for the next use. If reusable is false, each task calling wait can return as soon as all n tasks have called notify.

proc check(): bool

Return true if n tasks have called notify

proc reset(nTasks: int)

Reset the barrier, setting it to work with nTasks tasks. If some (but not all) tasks had already called barrier or check when reset is called, the behavior is undefined.