TerminationDetection

Usage

use TerminationDetection;

In termination detection, each time a task spawns another task, the spawning task becomes the parent and the spawned task is the child. The parent must increment the ‘tasksStarted’ counter each time it creates a child, and the child must increment the ‘tasksFinished’ counter before being destroyed. Each locale has its own privatized counters, so if the parent and child are not located on the same locale, the increment and decrement occur on the respective locales counters, hence a locale can have a ‘tasksStarted’ counter that is higher or lower than the ‘tasksFinished’ counter, even if all tasks have terminated. The benefit to having increments being local is the increased locality.

Determining whether or not all tasks have terminated involves performing multiple distributed reductions, which Chapel makes very easy. Spawning a remote task on each node, and using the reduce intent is enough to implement a distributed reduction. Once the reduction has been performed twice, and if there has been no update, and if both times the reduction of both the ‘tasksStarted’ and ‘tasksFinished’ are equivalent, no task is alive at that given time.

Example of its usage:

proc visit(n : node, term : TerminationDetection) {
  doSomethingTo(n.data);

  // About to spawn two tasks...
  term.start(2);
  begin on n.left {
    visit(n.left, term);
  }
  begin on n.right {
    visit(n.right, term);
  }

  // Task just finished...
  term.finish();
}
record TerminationDetector

Termination detector.

var instance: unmanaged TerminationDetectorImpl
var pid = -1
proc init(n = 0)
proc _value
proc destroy()
proc <=>(ref lhs: TerminationDetector, ref rhs: TerminationDetector)
class TerminationDetectorImpl
var tasksStarted: chpl__processorAtomicType(int)
var tasksFinished: chpl__processorAtomicType(int)
var pid = -1
proc init(n = 0)
proc init(other, pid)
proc started(n = 1)
proc finished(n = 1)
proc getStatistics(): (int, int)
proc hasTerminated(): bool
proc awaitTermination(minBackoff = 0, maxBackoff = 1024, multBackoff = 2)
proc dsiPrivatize(pid)
proc dsiGetPrivatizeData()
proc getPrivatizedInstance()