Practices for scientific programming

I would like to write good statements in terms of speed and accuracy. If I remember this line correctly: b=(a+1)*a creates a better program than this: b=(a^2+a) .

This is just an example, it may be wrong, but now it does not matter, the question is, where can I find a compendium of best practices for scientific computing?

+4
source share
5 answers

You can see Numerical Recipes in C. I'm not sure if he introduces or teaches you optimizations, but this is a very popular book, as scientific computing in C goes. There may even be a book for C ++.

+5
source

What you do here is called premature optimization , and this is the root of many evils. What you should do is write your programs, then profile them and try to optimize critical parts. A complete collection of optimization methods for scientific computing is likely to be a very thick book, so you need to narrow the problem down to finding solutions.

+3
source

One useful method is to create all the templates for your functions in a data type, and then run the algorithm with an arithmetic type of intervals instead of a floating point type. This gives an upper bound on the accuracy of the result for a given set of inputs without the need for extensive numerical analysis.

It is also important to have an idea of ​​the expected values ​​of your results and any intermediate links, so you can quickly tell if something is wrong.

+1
source

Looking around https://scicomp.stackexchange.com/ or even asking can help you a lot.

Good luck

0
source

This is not an ordinary discussion of "premature optimization." This is not about performance; this is accuracy, that is the problem. I agree with OP - it's worth paying attention to.

The biggest thing you can pay attention to is the accumulation of rounding errors .

You must sort the arrays in ascending order before adding them if you can:

http://www.ibiblio.org/pub/languages/fortran/ch4-9.html

You can find this help:

http://www.codeproject.com/Articles/25294/Avoiding-Overflow-Underflow-and-Loss-of-Precision

You Need to Read What Every Computer Scientist Should Know About Floating-Point Arithmetic

0
source

Source: https://habr.com/ru/post/1392679/


All Articles