artem-ogre / CDT

Constrained Delaunay Triangulation (C++)
https://artem-ogre.github.io/CDT/
Mozilla Public License 2.0
1.07k stars 133 forks source link

Can we get different results depending on the OS? #103

Closed stla closed 2 years ago

stla commented 2 years ago

Hello,

I did a R package wrapping CDT. When submitting a R package for publication, it is tested with multiple OS. A unit test fails on Mac. The results of a constrained Delaunay triangulation are not the same as the ones obtained on Windows and Unix (the edges are not the same). Does it make sense? The constrained Delaunay triangulation is not unique, is it? But how is it possible to get different results depending on the OS? The algorithm is deterministic, isn't it?

artem-ogre commented 2 years ago

Could you provide a minimal reproducible example?

stla commented 2 years ago

Hi, I'm preparing a figure, to see if at least the Mac results make sense. I'll post the results of my investigations here.

stla commented 2 years ago

That makes sense, the triangulation is correct. The first figure is the one obtained with Windows and Unix, the second one is the one obtained with Mac. The red edges are the fixed edges.

issueNoMac

issueMac

artem-ogre commented 2 years ago

Concyclic points are known not to have a unique Delaunay triangulation. And different order of vertex insertion can produce slightly different results.

But when called with exactly the same inputs/parameters it should provide the same result regardless the OS.

stla commented 2 years ago

Yes, strange. I have been told that Mac has no longer support for long doubles. Could it be the cause?

artem-ogre commented 2 years ago

It could be. I observed different triangulations with doubles vs floats converted from doubles. It is a guessing game without a concrete example.

msokalski commented 2 years ago

Im almost sure, different results are caused by different random.h implementations on win and linux.

artem-ogre commented 2 years ago

@msokalski std::mt19937 PRNG with a fixed seed is used and nothing else. This should be portable to my knowledge. I also run the tests on Windows/macOS/Ubuntu and did not find any platform specific results. @stla Could you please provide the exact input example?

msokalski commented 2 years ago

Sure, i'll do tonight. I'm not sure which part of RNG tricked me in similar way (mersenne tweester or actual distribiution generator) but I've experienced differences between linux and windows in my random input to DCT test generator.

artem-ogre commented 2 years ago

@msokalski If I remember right distributions are not portable, but plane generator should be fine.

msokalski commented 2 years ago

Ahh, probably you're right. So the other thing that came to my mind is different FAST_FMA define on Mac. If @stla used buggy predicates it could make a difference. Anyway I'm going to check the RNG thing.

msokalski commented 2 years ago

Nope, RNG results are same on Win10+VC and Ubuntu 20.04+gcc/clang. I was wrong, sorry.

stla commented 2 years ago

I get the same results with Windows and Linux. Different results are on Mac. I'll give the point coordinates later.

stla commented 2 years ago

Here is the input.

(0, 1)
(1, 2)
...
(10, 11)
(11, 0)

and

(12, 13)
(13, 14)
...
(22, 23)
(23, 12)
artem-ogre commented 2 years ago

@stla To my knowledge trigonometric functions are not bit to bit portable. Can you trigger different triangulation outcomes when pre-computing and hard-coding vertex positions?

stla commented 2 years ago

I don't know, I don't have a Mac. (not sure to understand your question actually)

The trigonometric coordinates are calculated in R, not in C++. Do you think there can be some differences depending on the OS?

artem-ogre commented 2 years ago

Yes, different results of sin/cos depending on a platform. Try computing and saving coordinates on one platform and hard-code them as an input. Hope it’s clear now.

artem-ogre commented 2 years ago

@stla FYI I am going to close this issue as not reproducible soon.