Example #1
1
 /**
  * The trace is DEEP copied.
  *
  * @param sacPath to extract waveform from
  * @return DEEP copied {@link Trace} from waveform in the sacFile
  * @throws IOException If sacFile does not exist, if an I/O error occurs.
  */
 public static Trace createTrace(Path sacPath) throws IOException {
   Map<SACHeaderEnum, String> header = readHeader(sacPath);
   double[] timeAxis = new double[Integer.parseInt(header.get(SACHeaderEnum.NPTS))];
   double delta = Double.parseDouble(header.get(SACHeaderEnum.DELTA));
   double b = Double.parseDouble(header.get(SACHeaderEnum.B));
   Arrays.parallelSetAll(timeAxis, i -> i * delta + b);
   return new Trace(timeAxis, readSACData(sacPath));
 }
  public ParallelTest() {
    StopWatch watch = new StopWatch("Timer");
    List<Integer> numbersToSum = new ArrayList<Integer>();

    System.out.println("Preparing data...");
    for (int i = 0; i < 1_000_000; i++) {
      numbersToSum.add(i);
    }
    System.out.println("Data prepared");
    watch.start("Parallel sum");
    Long sum = numbersToSum.stream().parallel().map(it -> it.longValue()).reduce(0L, Long::sum);
    watch.stop();

    watch.start("Sequence sum");
    sum = numbersToSum.stream().map(it -> it.longValue()).reduce(0L, Long::sum);
    watch.stop();

    Long[] arrayOfLong = new Long[20_000_000];
    // prepare array
    Arrays.parallelSetAll(arrayOfLong, it -> ThreadLocalRandom.current().nextLong(100_000));

    // make a copy
    Long[] arrayOfLongCopy = Arrays.copyOf(arrayOfLong, arrayOfLong.length);

    // print array
    Arrays.stream(arrayOfLong).limit(10).forEach(it -> System.out.print(it + ", "));
    System.out.println();
    watch.start("Parallel sort");
    // sort array and print
    Arrays.parallelSort(arrayOfLong);
    watch.stop();
    Arrays.stream(arrayOfLong).limit(10).forEach(it -> System.out.print(it + ", "));
    System.out.println();
    watch.start("Seq sort");
    Arrays.sort(arrayOfLongCopy);
    watch.stop();
    Arrays.stream(arrayOfLongCopy).limit(10).forEach(it -> System.out.print(it + ", "));

    System.out.println(watch.prettyPrint());
  }
 public static void main(String[] args) {
   P3ParallelSetAll p3ParallelSetAll = new P3ParallelSetAll();
   Arrays.parallelSetAll(p3ParallelSetAll.createLargeArray(), x -> x * 100);
 }
 public Integer[] createLargeArray() {
   Integer[] array = new Integer[1024 * 1024 * 4]; // 4M
   Arrays.parallelSetAll(array, i -> new Integer(new Random().nextInt()));
   return array;
 }
 public void createLargeArrayWithCustomGenerator() {
   Integer[] array = new Integer[1024 * 1024 * 4]; // 4M
   Arrays.parallelSetAll(array, i -> new Integer(customGenerator(getNextSensorValue())));
 }