HashedDist

Usage

use HashedDist;

or

import HashedDist;

Warning

HashedDist is unstable and may change in the future

record hashedDist : writeSerializable

The hashedDist distribution maps an associative domain and its array to a set of target locales. Each index (or key) in the domain is mapped to a locale based upon its value. When constructing a hashedDist distribution, you can optionally provide a mapper function or function object to compute the destination locale for each index.

The mapper provided can be a class, record, or first class function. When called, it will be passed the index and the targetLocales array that the hashedDist distribution was initialized with. For example, the following record declares a custom mapper:

record CustomMapper {
  proc this(ind:string, targetLocs: [?D] locale) : D.idxType {
    const numlocs = targetLocs.domain.size;
    // use the first digit of the string to choose the destination locale
    var byte: int = ind.byte(1);
    return byte % numlocs;
  }
}

If a custom mapper is not provided, a default mapper will be used. The default mapper computes the target locale based upon a hash of the index.

Note

Hashed is not yet interface stable.

Example

The following example uses the custom mapper that was defined earlier in order to add string keys to a distributed domain:

  use HashedDist;

  var D: domain(string) dmapped new hashedDist(mapper=new CustomMapper(),
                                               idxType=string);

  // Now D is a distributed associative domain (set) of strings
  D += "one";
  D += "two";
  D += "three";
  D += "four";
  D += "five";
  D += "six";

  var A: [D] int;
  // Now A is a distributed associative array (map) from string to int
  forall a in A do
    a = a.locale.id;

  for (key, value) in zip(D, A) {
    writeln(key, " -> ", value);
  }

When run on 6 locales, the output is:

one -> 2
three -> 2
six -> 3
four -> 3
five -> 3
two -> 5

Initializer Arguments

The hashedDist domain map initializer is defined as follows:

proc init(type idxType,
          mapper:?t = new DefaultMapper(),
          targetLocales: [] locale = Locales)