package edu.rice.hj.example.comp322.labs.lab3; import edu.rice.hj.api.HjFuture; import edu.rice.hj.api.HjMetrics; import edu.rice.hj.api.SuspendableException; import edu.rice.hj.runtime.config.HjSystemProperty; import edu.rice.hj.runtime.metrics.AbstractMetricsManager; import java.util.Random; import static edu.rice.hj.Module1.*; /** * ArraySum2.hj --- Parallel recursive example program for computing the sum of an array using futures. *
* This example program creates an array of n random int's, and computes their sum in parallel. The default value of n * is 1024, but any size can be provided as argv[0] by using the command "run ArraySum2 size" in the DrHJ Interactions * Pane or "hj ArraySum2 size" on the command line. *
* NOTE: this example program is intended for illustrating abstract performance metrics, and is not intended to be used
* as abenchmark for real performance.
*
* @author Vivek Sarkar (vsarkar@rice.edu)
*/
public class ArraySum2 {
static final int default_n = 128;
static final String err = "Incorrect argument for array size (should be > 0), assuming n = " + default_n;
static int computeSum(final int[] X, final int lo, final int hi) throws SuspendableException {
if (lo > hi) {
return 0;
} else if (lo == hi) {
return X[lo];
} else {
final int mid = (lo + hi) / 2;
final HjFuture main.