Skip to main content
8 votes

Ensuring IEEE 754 Compliance and Numerical Precision in C++ HPC Projects

IEEE 754 conforming floating point arithmetic has rounding errors. The rounding errors are well defined and reproducible, so two calculations will give you the exact same results - with the same ...
gnasher729's user avatar
8 votes

Unexpected result when summing sorted (and unsorted) positive floating point numbers

Very interesting problem! I might have a partial answer. To start, I replicated a simple C++ demo that can reproduce the effect ...
Mikael Öhman's user avatar
7 votes

Ensuring IEEE 754 Compliance and Numerical Precision in C++ HPC Projects

My suggestion is to just not worry about it. We run the ~13,000 tests of the deal.II project in both debug and release mode (the latter involving high optimization flags) and do not observe ...
Wolfgang Bangerth's user avatar
7 votes
Accepted

C++ Run-time parameter constants

Do yourself a favor and use JSON files for the configuration of your program. Nothing beats json in terms of extensibility and simplicity: Serialization (writing) and de-serialization (reading) of ...
davidhigh's user avatar
  • 3,167
7 votes

Why do my satellites fall out of orbit?

Start with fewer bodies, can you simulate two masses with a spring or an earth/moon system? Track the total kinetic energy and potential energy of the system to verify that your integrator is (...
MPIchael's user avatar
  • 2,985
5 votes

Speeding up 3 body problem acceleration calculation

Welcome to Scicomp! For all following points, always measure and compare. Don't fall for premature optimization! It is the root of all evil. Is the time you spend on optimizing your code worth your ...
MPIchael's user avatar
  • 2,985
5 votes
Accepted

Understanding leapfrog integration algorithm

In the second code the full time stepping is given by three lines in main() ...
user9794's user avatar
  • 465
4 votes

Understanding leapfrog integration algorithm

The first code is wrong if you have multiple particles that interact. Due to the structure of the loop, the interaction forces with particles at the start of the list are computed with the updated ...
Lutz Lehmann's user avatar
  • 6,109
3 votes
Accepted

Computing LJ force from LJ potential, or not?

Which one is computationally more accutate [sic] and why? The first one is more accurate. It uses the exact derivative of the LJ potential. By contrast, the second one not only uses a numerical ...
jjramsey's user avatar
  • 198
3 votes

How can I write a unit test for this routine?

Divide and conquer refactor your code, so that you have smaller methods with well defined purposes. Give these methods short descriptive names of what they are doing. You make the code more testable ...
MPIchael's user avatar
  • 2,985
3 votes
Accepted

How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

The problem is your loop iterates through all possible rows, but your COO data has more than that amount of data (only 5 rows, but you have 6 COO entries because you sum into position 0,0 twice). ...
helloworld922's user avatar
3 votes

Ensuring IEEE 754 Compliance and Numerical Precision in C++ HPC Projects

In complementation of others answers that say to write runnable tests with tolerances, I further add to not write static tests at all. Optimizing compilers are in the business of generating results, ...
André L F S Bacci's user avatar
2 votes

Ensuring IEEE 754 Compliance and Numerical Precision in C++ HPC Projects

I agree with the answer of @Wolfgang Bangerth. If you insist on testing the effects yourself you could set up explicit assertions or even unit tests for the 5 rounding types and the recommended ...
MPIchael's user avatar
  • 2,985
2 votes
Accepted

How to calculate the force of solid applied by fluid? Using finite difference method, DNS, staggered grid, SIMPLE algorithm, immersive boundary

The question is solved. I use wrong coefficient formula. I should use 2d formula but actually I use 3d. And my calculation method using momentum conversation may be wrong, but that is fine, I can use ...
CheapMeow's user avatar
1 vote

c++ software packages to solve linear systems subject to constraints

deal.II has a tutorial showing how to solve the obstacle problem, which has one-sided bounds constraints, using an active set approach. PETSc also has a variational inequality solver SNESVINEWTONRSLS ...
Daniel Shapero's user avatar
1 vote

C++ Run-time parameter constants

An alternative to JSON is to use Google’s protocol buffers. You can think of it as a strongly typed generalization of JSON that allows for generating classes in your favorite language via compilation ...
spektr's user avatar
  • 4,258

Only top scored, non community-wiki answers of a minimum length are eligible