Class V5

java.lang.Object
edu.wustl.cse231s.v5.V5

public class V5
extends java.lang.Object
Author:
Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/)
See Also:
X10: An Object-Oriented Approach to Non-Uniform Cluster Computing
  • Constructor Details

    • V5

      public V5()
  • Method Details

    • finish

      public static void finish​(CheckedRunnable body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Executes the specified computation, waiting for all spawned async and future descendant tasks to terminate.
      Parameters:
      body - run method defines the computation
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • async

      public static void async​(CheckedRunnable body)
      Spawn an asynchronous child task.
      Parameters:
      body - run method defines the computation of the task
    • async

      public static void async​(boolean isParallelDesired, CheckedRunnable body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally spawn an asynchronous child task. The semantics of:
       async(rangeLength>threshold, body);
       
      is:
       if (rangeLength>threshold) {
           async(body);
       } else {
           body.run();
       }
       
      Parameters:
      isParallelDesired - whether or not to run the task in parallel
      body - run method defines the execution of the task
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • future

      public static <R> java.util.concurrent.Future<R> future​(CheckedCallable<R> body)
      Spawn an asynchronous child task which returns a value.
      Type Parameters:
      R - the return type of the computation
      Parameters:
      body - run method defines the computation of the task
      Returns:
      a Future object from which the result of the computation can be acquired via its get() method.
    • future

      public static <R> java.util.concurrent.Future<R> future​(boolean isParallelDesired, CheckedCallable<R> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally spawn an asynchronous child task. The semantics of:
       return future(rangeLength>threshold, body);
       
      is:
       if (rangeLength>threshold) {
           return future(body);
       } else {
           R value = body.call();
           return ConcurrentUtils.constantFuture(value);
       }
       
      Type Parameters:
      R - the return type of the computation
      Parameters:
      isParallelDesired - whether or not to run the task in parallel
      body - call method defines the execution of the task
      Returns:
      a Future object from which the result of the computation can be acquired via its get() method.
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forseq

      public static void forseq​(int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over the range [min, maxExclusive). The semantics of:
       forseq(0, N, (int i) -> {
           f(i);
       });
       
      is:
       for(int i=0; i<N; i++) {
           f(i);
       }
       
      Parameters:
      min - minimum (inclusive) index of the for loop
      maxExclusive - maximum (exclusive) index of the for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forasync

      public static void forasync​(int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over the range [min, maxExclusive) without a wrapping finish. Although the implementation may divide-and-conquer the range, the semantics of:
       forasync(0, N, (int i) -> {
           f(i);
       });
       
      is:
       for(int i=0; i<N; i++) {
           async(() -> {
               f(i);
           });
       }
       
      Parameters:
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forall

      public static void forall​(int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over the range [min, maxExclusive) with a wrapping finish. The semantics of:
       forall(0, N, (int i) -> {
           f(i);
       });
       
      is:
       finish(() -> {
           forasync(0, N, (int i) -> {
               f(i);
           });
       });
       
      Parameters:
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(int, int, CheckedIntConsumer)
    • forasync

      public static void forasync​(boolean isParallelDesired, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over the range [min, maxExclusive) without a wrapping finish. The semantics of:
       forasync(isParallelDesired, min, maxExclusive, body);
       
      is:
       if (isParallelDesired) {
           forasync(min, maxExclusive, body);
       } else {
           forseq(min, maxExclusive, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(int, int, CheckedIntConsumer), forseq(int, int, CheckedIntConsumer)
    • forall

      public static void forall​(boolean isParallelDesired, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over the range [min, maxExclusive) with a wrapping finish. The semantics of:
       forall(isParallelDesired, min, maxExclusive, body);
       
      is:
       if (isParallelDesired) {
           forall(min, maxExclusive, body);
       } else {
           forseq(min, maxExclusive, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(int, int, CheckedIntConsumer), forseq(int, int, CheckedIntConsumer)
    • forseq

      public static void forseq​(ChunkedOption chunkedOption, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over the range [min, maxExclusive) with a chunked() option to allow easy switching back and forth between parallel and sequential code versions. The semantics of:
       forseq(chunked(), min, maxExclusive, body);
       
      is:
       forseq(min, maxExclusive, body);
       
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      min - minimum (inclusive) index of the for loop
      maxExclusive - maximum (exclusive) index of the for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int), forseq(int, int, CheckedIntConsumer)
    • forasync

      public static void forasync​(ChunkedOption chunkedOption, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over the range [min, maxExclusive) without a wrapping finish. The semantics of:
       forasync(chunked(), min, maxExclusive, body);
       
      is similar to forasync(int, int, CheckedIntConsumer) except that the runtime will stop short of creating a task per index when the range falls below the desired the chunk size.
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int)
    • forall

      public static void forall​(ChunkedOption chunkedOption, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over the range [min, maxExclusive) with a wrapping finish. The semantics of:
       forall(chunked(), 0, N, (int i) -> {
           f(i);
       });
       
      is:
       finish(() -> {
           forasync(chunked(), 0, N, (int i) -> {
               f(i);
           });
       });
       
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(ChunkedOption, int, int, CheckedIntConsumer)
    • forasync

      public static void forasync​(boolean isParallelDesired, ChunkedOption chunkedOption, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over the range [min, maxExclusive) without a wrapping finish. The semantics of:
       forasync(isParallelDesired, chunked(), min, maxExclusive, body);
       
      is:
       if (isParallelDesired) {
           forasync(chunked(), min, maxExclusive, body);
       } else {
           forseq(min, maxExclusive, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(ChunkedOption, int, int, CheckedIntConsumer), forseq(int, int, CheckedIntConsumer)
    • forall

      public static void forall​(boolean isParallelDesired, ChunkedOption chunkedOption, int min, int maxExclusive, CheckedIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over the range [min, maxExclusive) with a wrapping finish. The semantics of:
       forall(isParallelDesired, chunked(), min, maxExclusive, body);
       
      is:
       if (isParallelDesired) {
           forall(min, chunked(), maxExclusive, body);
       } else {
           forseq(min, maxExclusive, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      min - minimum (inclusive) index of the parallel for loop
      maxExclusive - maximum (exclusive) index of the parallel for loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(ChunkedOption, int, int, CheckedIntConsumer), forseq(int, int, CheckedIntConsumer)
    • forseq

      public static <T> void forseq​(T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over an array. The semantics of:
       forseq(array, (T element) -> {
           f(element);
       });
       
      is:
       
       for(T element : array) {
           f(element);
       }
       
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forasync

      public static <T> void forasync​(T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over an array without a wrapping finish. Although the implementation may divide-and-conquer the array, the semantics of:
       forasync(array, (T element) -> {
           f(element);
       });
       
      is:
       for(T element : array) {
           async(() -> {
               f(element);
           });
       }
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forall

      public static <T> void forall​(T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over an array with a wrapping finish. The semantics of:
       forall(array, (T element) -> {
           f(element);
       });
       
      is:
       finish(() -> {
           forasync(array, (T element) -> {
               f(i);
           });
       });
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(Object[], CheckedConsumer)
    • forasync

      public static <T> void forasync​(boolean isParallelDesired, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over an array without a wrapping finish. The semantics of:
       forasync(isParallelDesired, array, body);
       
      is:
       if (isParallelDesired) {
           forasync(array, body);
       } else {
           forseq(array, body);
       }
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(Object[], CheckedConsumer), forseq(Object[], CheckedConsumer)
    • forall

      public static <T> void forall​(boolean isParallelDesired, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over an array with a wrapping finish. The semantics of:
       forall(isParallelDesired, array, body);
       
      is:
       if (isParallelDesired) {
           forall(array, body);
       } else {
           forseq(array, body);
       }
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(Object[], CheckedConsumer), forseq(Object[], CheckedConsumer)
    • forseq

      public static <T> void forseq​(ChunkedOption chunkedOption, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over an array with a chunked() option to allow easy switching back and forth between parallel and sequential code versions. The semantics of:
       forseq(chunked(), array, body);
       
      is:
       forseq(array, body);
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int), forseq(Object[], CheckedConsumer)
    • forasync

      public static <T> void forasync​(ChunkedOption chunkedOption, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over an array without a wrapping finish. The semantics of:
       forasync(chunked(), array, body);
       
      is similar to forasync(Object[], CheckedConsumer) except that the runtime will stop short of creating a task per element when the range falls below the desired the chunk size.
      Type Parameters:
      T - the component type of the array
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int)
    • forall

      public static <T> void forall​(ChunkedOption chunkedOption, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over an array with a wrapping finish. The semantics of:
       forall(chunked(), array, (T element) -> {
           f(element);
       });
       
      is:
       finish(() -> {
           forasync(chunked(), array, (T element) -> {
               f(element);
           });
       });
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(ChunkedOption, Object[], CheckedConsumer)
    • forasync

      public static <T> void forasync​(boolean isParallelDesired, ChunkedOption chunkedOption, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over an array without a wrapping finish. The semantics of:
       forasync(isParallelDesired, chunked(), array, body);
       
      is:
       if (isParallelDesired) {
           forasync(chunked(), array, body);
       } else {
           forseq(array, body);
       }
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(ChunkedOption, Object[], CheckedConsumer), forseq(Object[], CheckedConsumer)
    • forall

      public static <T> void forall​(boolean isParallelDesired, ChunkedOption chunkedOption, T[] array, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over an array with a wrapping finish. The semantics of:
       forall(isParallelDesired, chunked(), array, body);
       
      is:
       if (isParallelDesired) {
           forall(chunked(), array, body);
       } else {
           forseq(array, body);
       }
       
      Type Parameters:
      T - the component type of the array
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      array - the array which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(ChunkedOption, Object[], CheckedConsumer), forseq(Object[], CheckedConsumer)
    • forseq

      public static <T> void forseq​(java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over an iterable. The semantics of:
       forseq(iterable, (T element) -> {
           f(element);
       });
       
      is:
       
       for(T item : iterable) {
           f(item);
       }
       
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forasync

      public static <T> void forasync​(java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Although the implementation may divide-and-conquer the iterable, the semantics of:
       forasync(iterable, (T item) -> {
           f(item);
       });
       
      is:
       for(T item : iterable) {
           async(() -> {
               f(item);
           });
       }
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forall

      public static <T> void forall​(java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      The semantics of:
       forall(iterable, (T element) -> {
           f(element);
       });
       
      is:
       finish(() -> {
           forasync(iterable, (T element) -> {
               f(i);
           });
       });
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(Iterable, CheckedConsumer)
    • forasync

      public static <T> void forasync​(boolean isParallelDesired, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over an iterable without a wrapping finish. The semantics of:
       forasync(isParallelDesired, iterable, body);
       
      is:
       if (isParallelDesired) {
           forasync(iterable, body);
       } else {
           forseq(iterable, body);
       }
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(Iterable, CheckedConsumer), forseq(Iterable, CheckedConsumer)
    • forall

      public static <T> void forall​(boolean isParallelDesired, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over an iterable with a wrapping finish. The semantics of:
       forall(isParallelDesired, iterable, body);
       
      is:
       if (isParallelDesired) {
           forall(iterable, body);
       } else {
           forseq(iterable, body);
       }
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(Iterable, CheckedConsumer), forseq(Iterable, CheckedConsumer)
    • forseq

      public static <T> void forseq​(ChunkedOption chunkedOption, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Sequential loop over an array with a chunked() option to allow easy switching back and forth between parallel and sequential code versions. The semantics of:
       forseq(chunked(), iterable, body);
       
      is:
       forseq(iterable, body);
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int), forseq(Object[], CheckedConsumer)
    • forasync

      public static <T> void forasync​(ChunkedOption chunkedOption, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over an iterable without a wrapping finish. The semantics of:
       forasync(chunked(), iterable, body);
       
      is similar to forasync(Iterable, CheckedConsumer) except that the runtime will stop short of creating a task per item when the range falls below the desired the chunk size.
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int)
    • forall

      public static <T> void forall​(ChunkedOption chunkedOption, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over an iterable with a wrapping finish. The semantics of:
       forall(chunked(), iterable, (T item) -> {
           f(element);
       });
       
      is:
       finish(() -> {
           forasync(chunked(), iterable, (T item) -> {
               f(item);
           });
       });
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync(ChunkedOption, Iterable, CheckedConsumer)
    • forasync

      public static <T> void forasync​(boolean isParallelDesired, ChunkedOption chunkedOption, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over an iterable without a wrapping finish. The semantics of:
       forasync(isParallelDesired, chunked(), iterable, body);
       
      is:
       if (isParallelDesired) {
           forasync(chunked(), iterable, body);
       } else {
           forseq(iterable, body);
       }
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync(ChunkedOption, Iterable, CheckedConsumer), forseq(Iterable, CheckedConsumer)
    • forall

      public static <T> void forall​(boolean isParallelDesired, ChunkedOption chunkedOption, java.lang.Iterable<T> iterable, CheckedConsumer<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked conditionally parallel loop over an iterable with a wrapping finish. The semantics of:
       forall(isParallelDesired, chunked(), iterable, body);
       
      is:
       if (isParallelDesired) {
           forall(chunked(), iterable, body);
       } else {
           forseq(iterable, body);
       }
       
      Type Parameters:
      T - the parameterized type of the iterable
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      iterable - the iterable which the loop operates on
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall(ChunkedOption, Iterable, CheckedConsumer), forseq(Iterable, CheckedConsumer)
    • forseq2d

      public static void forseq2d​(int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Nested sequential loops over the ranges [minA, maxExclusiveA) and [minB, maxExclusiveB). The semantics of:
       forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, (int i, int j) -> {
           f(i, j);
       });
       
      is:
       for(int i=minA; i<maxExclusiveA; i++) {
           for(int j=minB; j<maxExclusiveB; j++) {
               f(i, j);
           }
       }
       
      Parameters:
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forasync2d

      public static void forasync2d​(int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) without a wrapping finish. Although the implementation may divide-and-conquer the range(s), the semantics of:
       forasync2d(minA, maxExclusiveA, minB, maxExclusiveB, (int i, int j) -> {
           f(i, j);
       });
       
      is:
       for(int i=minA; i<maxExclusiveA; i++) {
           for(int j=minB; j<maxExclusiveB; j++) {
               async(() -> {
                   f(i, j);
               });
           }
       }
       
      Parameters:
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
    • forall2d

      public static void forall2d​(int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) with a wrapping finish. The semantics of:
       forall2d(minA, maxExclusiveA, minB, maxExclusiveB, (int i, int j) -> {
           f(i, j);
       });
       
      is:
       finish(() -> {
           forasync2d(minA, maxExclusiveA, minB, maxExclusiveB, (int i, int j) -> {
               f(i, j);
           });
       });
       
      Parameters:
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync2d(int, int, int, int, CheckedIntIntConsumer)
    • forasync2d

      public static void forasync2d​(boolean isParallelDesired, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) without a wrapping finish. The semantics of:
       forasync2d(isParallelDesired, minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       if (isParallelDesired) {
           forasync2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       } else {
           forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync2d(int, int, int, int, CheckedIntIntConsumer), forseq2d(int, int, int, int, CheckedIntIntConsumer)
    • forall2d

      public static void forall2d​(boolean isParallelDesired, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) with a wrapping finish. The semantics of:
       forall2d(isParallelDesired, minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       if (isParallelDesired) {
           forall2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       } else {
           forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall2d(int, int, int, int, CheckedIntIntConsumer), forseq2d(int, int, int, int, CheckedIntIntConsumer)
    • forseq2d

      public static void forseq2d​(ChunkedOption chunkedOption, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Nested sequential loops over the ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) with a chunked() option to allow easy switching back and forth between parallel and sequential code versions. The semantics of:
       forseq2d(chunked(), minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int), forseq2d(int, int, int, int, CheckedIntIntConsumer)
    • forasync2d

      public static void forasync2d​(ChunkedOption chunkedOption, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) without a wrapping finish. The semantics of:
       forasync2d(chunked(), inA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is similar to forasync2d(int, int, int, int, CheckedIntIntConsumer) except that the runtime will stop short of creating a task per index when the range falls below the desired the chunk size.
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      chunked(), chunked(int)
    • forall2d

      public static void forall2d​(ChunkedOption chunkedOption, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Chunked parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) with a wrapping finish. The semantics of:
       forall(chunked(), minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       finish(() -> {
           forasync(chunked(), minA, maxExclusiveA, minB, maxExclusiveB, body);
       });
       
      Parameters:
      chunkedOption - result of either chunked() or chunked(int)
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      finish(CheckedRunnable), forasync2d(ChunkedOption, int, int, int, int, CheckedIntIntConsumer)
    • forasync2d

      public static void forasync2d​(boolean isParallelDesired, ChunkedOption chunkedOption, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally chunked parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) without a wrapping finish. The semantics of:
       forasync2d(isParallelDesired, chunked(), minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       if (isParallelDesired) {
           forasync2d(minA, chunked(), maxExclusiveA, minB, maxExclusiveB, body);
       } else {
           forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forasync2d(ChunkedOption, int, int, int, int, CheckedIntIntConsumer), forseq2d(int, int, int, int, CheckedIntIntConsumer)
    • forall2d

      public static void forall2d​(boolean isParallelDesired, ChunkedOption chunkedOption, int minA, int maxExclusiveA, int minB, int maxExclusiveB, CheckedIntIntConsumer body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Conditionally chunked parallel loop over the nested ranges [minA, maxExclusiveA) and [minB, maxExclusiveB) with a wrapping finish. The semantics of:
       forall2d(isParallelDesired, chunked(), minA, maxExclusiveA, minB, maxExclusiveB, body);
       
      is:
       if (isParallelDesired) {
           forall2d(minA, chunked(), maxExclusiveA, minB, maxExclusiveB, body);
       } else {
           forseq2d(minA, maxExclusiveA, minB, maxExclusiveB, body);
       }
       
      Parameters:
      isParallelDesired - whether or not to run the tasks in parallel
      chunkedOption - result of either chunked() or chunked(int)
      minA - minimum (inclusive) index of the outer loop
      maxExclusiveA - maximum (exclusive) index of the outer loop
      minB - minimum (inclusive) index of the inner loop
      maxExclusiveB - maximum (exclusive) index of the inner loop
      body - accept method defines the execution of the tasks
      Throws:
      java.lang.InterruptedException - if the computation was cancelled
      java.util.concurrent.ExecutionException - if the computation threw an exception
      See Also:
      forall2d(ChunkedOption, int, int, int, int, CheckedIntIntConsumer), forseq2d(int, int, int, int, CheckedIntIntConsumer)
    • async

      public static void async​(AwaitFuturesOption awaitFuturesOption, CheckedRunnable body)
    • future

      public static <R> java.util.concurrent.Future<R> future​(AwaitFuturesOption awaitFuturesOption, CheckedCallable<R> body)
    • finish

      public static void finish​(RegisterAccumulatorsOption registerAccumulatorsOption, CheckedRunnable body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • numWorkerThreads

      public static int numWorkerThreads()
    • isLaunched

      public static boolean isLaunched()
    • doWork

      public static void doWork​(long n)
    • await

      public static AwaitFuturesOption await​(java.util.concurrent.Future<?> futureA, java.util.concurrent.Future<?>... futuresBtoZ)
    • chunked

      public static ChunkedOption chunked()
    • chunked

      public static ChunkedOption chunked​(int size)
    • register

      public static RegisterAccumulatorsOption register​(FinishAccumulator<?> accumulatorA, FinishAccumulator<?>... accumulatorBtoZ)
    • single

      public static SingleOption single​(java.lang.Runnable runnable)
    • newIntegerFinishAccumulator

      public static FinishAccumulator<java.lang.Integer> newIntegerFinishAccumulator​(NumberReductionOperator operator, ContentionLevel contentionLevel)
    • newIntegerFinishAccumulator

      public static FinishAccumulator<java.lang.Integer> newIntegerFinishAccumulator​(NumberReductionOperator operator)
    • newDoubleFinishAccumulator

      public static FinishAccumulator<java.lang.Double> newDoubleFinishAccumulator​(NumberReductionOperator operator, ContentionLevel contentionLevel, DoubleAccumulationDeterminismPolicy determinismPolicy)
    • newDoubleFinishAccumulator

      public static FinishAccumulator<java.lang.Double> newDoubleFinishAccumulator​(NumberReductionOperator operator, ContentionLevel contentionLevel)
    • newDoubleFinishAccumulator

      public static FinishAccumulator<java.lang.Double> newDoubleFinishAccumulator​(NumberReductionOperator operator)
    • newReducerFinishAccumulator

      public static <T> FinishAccumulator<T> newReducerFinishAccumulator​(AccumulatorReducer<T> reducer, ContentionLevel contentionLevel)
    • newReducerFinishAccumulator

      public static <T> FinishAccumulator<T> newReducerFinishAccumulator​(AccumulatorReducer<T> reducer)
    • shutdownIfNecessary

      public static void shutdownIfNecessary()
    • launchApp

      public static void launchApp​(CheckedRunnable body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • launchAppWithReturn

      public static <T> T launchAppWithReturn​(CheckedCallable<T> body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • launchApp

      public static void launchApp​(SystemPropertiesOption systemPropertiesOption, CheckedRunnable body) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • launchApp

      public static void launchApp​(SystemPropertiesOption systemPropertiesOption, CheckedRunnable body, java.util.function.BiConsumer<Metrics,​Bookkeeping> preFinalizeCallback) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getCurrentActivity

      public static java.util.Optional<Activity> getCurrentActivity()
    • resetBookkeeping

      public static void resetBookkeeping()