OnJava8-Examples/arrays/ParallelPrefix3.java

24 lines
688 B
Java
Raw Permalink Normal View History

// arrays/ParallelPrefix3.java
// (c)2021 MindView LLC: see Copyright.txt
2016-01-25 18:05:55 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2017-05-12 08:39:02 -06:00
// {ExcludeFromTravisCI}
2016-01-25 18:05:55 -08:00
import java.util.*;
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
*/