I've recently implemented 3 small CFD solvers one in C++, one in Fortran 95/2003 and one in Matlab for comparation purposes, both compiled codes were parallelized using OpenMP.
I've noticed that for the first iterations all 3 solvers have comparable precision (about 10 digits), after a while (a few hundreds of iterations) the C++ performance was degraded.
I wonder if some of you have the same experience with numerical precision in C++.
As a note:
- Matlab works by default in double precision
- in Fortran I've used double precision (Intel Fortran )
- in C++ double (Intel C++)
A simple example on a 64 bits computer
acos(-1) , exact value = pi
C/C++ using long double:
Fortran 95 using selected_real_kind(32,99)
arbitrary precision calculator, precision set to 36 digits:
C/C++ gets about 18 exact decimals vs 15 for a simple double !!!!!
I have a similar problem in C++ and MATLAB like yours.
I have two cfd code that do same calculation. the two codes give exactly the same results for low reynolds numbers. For high reynolds number, i.e. 10000, MATLAB code converges succesfully, but c++ code does not converge. :confused:
Do you know any way to increase the numerical precision of C++?
If you are sure both codes have no bugs, than you can try to play with precision in C++.
Try first to convert floats to doubles, and after that doubles to long double.
What I suspect is that your codes have different turbulence models, this will explain why for low Re numbers you have the same solution and for higher Re your results differs or one of the code does not converge.
this may be down to the algorithm used in calculating PI. It may be different in fortran and c/c++. This is why it is difficult to conclude anything about precision from this info.
Other than that i have written cfd solvers in c++ only and i have never faced problems at least in double precision.
There is one thing though, different compilers initialise vairables differently. i have noticed that if one is not careful about it then it might cause problems. (I am assuming this is not the case but i think it is worth mentioning because sometimes most obvious bugs are overlooked).
Sorry to say, but if the difference has become noticeable, and you are running in double precision, then there is probably something substantially different between the codes. For example you may be indexing incorrectly. Of there may be a bug such as overrunning an array or something hasn't been initialized correctly. Of course I'm not saying that the difference of precision isn't causing your problem. But, if it was, then you would also see noticeable differences if you were running optimized or unoptimized, the flow of the codes were different, some functions were inlined or not, etc.
|All times are GMT -4. The time now is 17:49.|