Question

I would like to write some performance-sensitive numerical code involving long formulas with complex numbers. Consider something simple like a=(b+c)*(d+e+f). I prefer to use C++ (which has the std::complex class), but I'm worried about the fact that the compiled code may create temporary class objects to hold the intermediate values b+c, d+e, and d+e+f, hence causing a slowdown. On the other hand, Fortran has native complex types which may lead to better compiler optimization. The code is multi-dimensional numerical integration, and the performance bottleneck is the evaluation of the integrand.

Are modern C++ compilers (such as Intel's) good enough at optimization that this is actually not a problem?

Was it helpful?

Solution

All Fortran can do (too) is to emulate the type.
There is no native machine type for complex numbers (on x86 at least).

Your concern is temporary usage of some stack bytes, that´s it.
If there is no other reason to keep it, even the stack resizing can be optimized away.
There is nothing Fortran could do better.

(Gcc and Clang are NOT generally worse than Intel. Each one has some good and bad points)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top