2016-08-23 09:33:05 -06:00
|
|
|
// arrays/ParallelPrefix3.java
|
2016-01-25 18:05:55 -08:00
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
|
|
import java.util.*;
|
|
|
|
|
2016-08-23 09:33:05 -06:00
|
|
|
public class ParallelPrefix3 {
|
2016-07-08 14:13:13 -06:00
|
|
|
static final int SIZE = 10_000_000;
|
2016-01-25 18:05:55 -08:00
|
|
|
public static void main(String[] args) {
|
|
|
|
long[] nums = new long[SIZE];
|
|
|
|
Arrays.setAll(nums, n -> n);
|
|
|
|
Arrays.parallelPrefix(nums, Long::sum);
|
|
|
|
System.out.println("First 20: " + nums[19]);
|
|
|
|
System.out.println("First 200: " + nums[199]);
|
|
|
|
System.out.println("All: " + nums[nums.length-1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
|
|
|
First 20: 190
|
|
|
|
First 200: 19900
|
2016-07-22 14:45:35 -06:00
|
|
|
All: 49999995000000
|
2016-01-25 18:05:55 -08:00
|
|
|
*/
|