I tried to use Java 8 parallel stream in one application where I have two long vectors (10,000 dimensional) and need to calculate a quantity using each pair of the values, then find the minimum and its index in the end.
I found a relevant question Java 8 nested loops with streams & performance but still didn't figure it out. Below is an example for making the question clear. any help is appreciated :)
public class dummyCode {
public static void main(String[] args) {
double[] a = {1, 2, 3, 4, 5};
double[] b = {5, 6, 7, 8, 9};
double min = Double.POSITIVE_INFINITY;
double root;
int index = -1;
for (int i = 0; i < a.length; i++) {
root = dummyFunction(a[i], b[i]);
if (root < min) {
min = root;
index = i;
}
}
System.out.println("the minimal is " + min + " at index " + index);
}
public static double dummyFunction(double a, double b) {
if (a < 3){
return a * a - 4 * a * b;
} else {
return a + 2 * a * b;
}
}
}