*asked by vladimir*I'm running CreditRiskExample on 11 nodes cluster (16 Gb RAM, core i7, 1 Tb each node). I'm using parallel stream of Java 8. Why parralel version which uses Java 8 lambdas (Code B) is slower then not parallel version (Code A)?

Code A (Credit risk [crdRisk=627147.908398507, duration=73667ms]):

double[] losses = new double[num];

for (int i = 0; i < num; i++)

{

for (Credit crd : portfolio)

{

int remDays = Math.min(crd.getRemainingTerm(), horizon);

if (rndGen.nextDouble() >= 1 - crd.getDefaultProbability(remDays))

losses[i] += (1 + crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365)

* crd.getRemainingAmount();

else

losses[i] -= crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365 *

crd.getRemainingAmount();

}

}

------------------------------------------------------------------------------

Code B (Credit risk [crdRisk=752244.1112362606, duration=151260ms]):

double[] losses = new double[num];

IntStream.range(0, num).parallel().forEach(i ->

{

for (Credit crd : portfolio)

{

int remDays = Math.min(crd.getRemainingTerm(), horizon);

if (rndGen.nextDouble() >= 1 - crd.getDefaultProbability(remDays))

losses[i] += (1 + crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365)

* crd.getRemainingAmount();

else

losses[i] -= crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365 *

crd.getRemainingAmount();

}

}

);

-----

*This post is migrated from now discontinued Apache Ignite forum at
*

http://apacheignite.readme.io/v1.0/discuss