Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel sum produces different result from sequential sum #4958

Closed
scabug opened this issue Sep 1, 2011 · 4 comments
Closed

Parallel sum produces different result from sequential sum #4958

scabug opened this issue Sep 1, 2011 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 1, 2011

Summing list sequentially and in parallel produces two different results.

The following test fails:

// summands of Leibniz formula for pi
val list = 0 until 10000 map { i => BigDecimal(4) * (1 - (i % 2) * 2) / (2 * i + 1) }

val piSeq = list sum
val piPar = list.par sum

assert(piSeq == piPar)
@scabug
Copy link
Author

scabug commented Sep 1, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4958?orig=1
Reporter: Sanjin Sehic (saserr)
Affected Versions: 2.9.1
See #4658

@scabug
Copy link
Author

scabug commented Sep 1, 2011

Sanjin Sehic (saserr) said:
Additionally, replacing {{sum}} with {{reduceLeft {_ + _}}} for parallel computation returns same result as sequential one.

@scabug
Copy link
Author

scabug commented Sep 1, 2011

@soc said:
I guess even BigDecimals are not commutative under addition.

This is related to #4658, because for your actual example neither sum nor reduceLeft are necessary, because the result can be determined algorithmically.

@scabug
Copy link
Author

scabug commented Sep 4, 2011

@paulp said:
Not a bug. Create your BigDecimals with java.math.MathContext.UNLIMITED and you will get the same result from both (both will throw exceptions for non-terminating decimal expansions.) When you perform rounding operations in different orders, you get different results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants