MATLAB Answers

Can mapreduce change the order of the elements in the output array?

1 view (last 30 days)
Nebitno
Nebitno on 26 Jun 2016
Commented: Nebitno on 26 Jun 2016
I am using mapreduce to compute distances between pairs of points, and when I look at the output it appears that mapreduce sorted these distances differently. So, I was wondering whether mapreduce can indeed change the order of the elements in the output and what would be possible ways to avoid this. Thanks.

Answers (1)

Walter Roberson
Walter Roberson on 26 Jun 2016
Yes, any change in the order of calculation of floating point values can result in different round off, and sorting is sensitive to the exact floating point representation. You can have the same issue with vectorization compared to looping, and you can have the same issue with parfor compared to for, and you can have the same issue if Mathworks changes the Just In Time (JIT) engine.
The way to avoid this is to do your distance calculations and comparisons in infinite precision. Depending on how you do your calculations, the Symbolic Toolbox might suffice for that. (Be warned that I encountered an calculation about a month ago for which calculating to over 200000 digits was not sufficient.)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!