Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

scatter

sherhut edited this page Oct 29, 2011 · 9 revisions

Synopsis

myArray.scatter(indices, defaultValue, conflictFunction, length)

##Arguments indices array of indices in the resulting array

defaultValue optional argument indicating the value of elements not set by scatter *When not present, the default value is undefined

conflictFunction optional function to resolve conflicts, details below.

length optional argument indicating the length of the resulting array. If absent, the length is the same as the length of the indices argument.

##Returns

A freshly minted ParallelArray A where each element A[i] is defined as

  • A[indices[i]] = this[i], when indices[i] is unique

  • A[indices[i]] = conflictFunction(A[indices[i]]), when A[indices[i]] has a previously assigned value. The value of this during the evaluation of conflictFunction is the value of the source array at the current position i.

  • defaultValue, when i is not present in indices array

##Example: an identity function

pa.scatter(indices); where indices is a ParallelArray where element === index

##Conflict Function A conflict occurs when multiple elements are scattered to the same location. It results in a call to conflictFunction, which is an optional third argument to scatter. If conflictFunction is undefined, conflicts are non-deterministically resolved.

Synopsis

function (other)

Arguments

this is the value at the current index in the input array, i.e., the value that is currently being scattered. other is the value that has already been written to the target index of the current scatter operation.

It is the programmer’s responsibility to provide a conflict function that is associative and commutative, since there is no guarantee in what order the conflicts will be resolved. Otherwise the result will be non-deterministic.

###Returns

Value to place in result[indices[index]]

###Example: Resolve conflict with larger number

chooseMax(other){
    return (this>other)?this:other;
}
Clone this wiki locally