|
|
[Up to jsr166y.forkjoin Examples]
There are several ways to inject data into a Parallel Array. You can assign a single value to all elements, or you can add a primitive array or the contents of another Parallel Array,
The examples below use ParallelDoubleArray, but analogous operation exist for ParallelArray<T> and ParallelLongArray. We will assume you are familiar with Creating arrays and have a ParallelDoubleArray reference, pda.
pda.replaceWithValue(0.0);
The addAll methods work like java.util collections: they add the content of another array to a Parallel Array. (addAll() does not perform numeric addition.)
// adds the elements of a double[] to the end of a Parallel Array
double[] array = // some operation to obtain a double[]
pda.addAll(array);// Given an existing Parallel Array 'pda', we can constuct
// another Parallel Array 'other'
// with the same contents. However, the two arrays are not linked.
ParallelDoubleArray other = ParallelDoubleArray.createFromCopy(pda.size, pda.getExecutor())
other.addAll(pda);
See also Modifying arrays.