Speed ​​increase

The broad question I know, but:

Does anyone have general tips for increasing execution speed in Fortran programs?

+6
performance optimization fortran
source share
6 answers

Broad answer for wide quesiton:

while (the speed is not satisfied) Use a profile to find the bottle neck optimize that part of code. 
+12
source share

As others suggested a profile of your code before thinking about changing it.

BUT the best thing you can do is carefully read the compiler manual, in turn, word for word, and carefully monitor all the options that it gives you. In my experience (I have a lot of experience in HPC for computational electromagnets, not that you have to believe what you read here!), You get the most hits for your dollars in optimizing performance through the intelligent use of the compiler.

Once you have exhausted the compiler (and, as one of the other respondents said, make sure you have a good compiler - they are not expensive, and I get a c40% reduction in execution time for most programs coming from g95 for a paid compiler), then you You should NOT start doing things like:

- scan cycle;

- reordering the team;

- attachment function;

- other things that we did all the time back during the day.

Currently, most of these code tuning tools are better than ours, carbon-based life forms can do this thanks to the good compiler optimizer.

If you have to mess around, mess with memory access - for example, you can use your array access to use the cache. If you do, set the tile size parameters (etc.), so that in the next year or year after that you move it to another architecture, you only need to configure a few parameters, and not change the code again.

Finally, have fun optimizing the performance of Fortran programs — a great way to spend your day!

+4
source share

This is a very wide field, but ...

  • If you are doing matrix arithmetic, consider learning this in libraries. They are probably faster and support multithreading, which will give you increased performance on multiprocessor machines.

  • Profiling as pierr suggests. This will tell you where your program is really spending its time. Knowing this, you can focus on bits that really need tuning.

  • Cache line and word alignment plus optimizing snippets for insertion into processor caches. They are considered more oriented to C programming, as it is easier to manage such things with C. However, the same problems can cause problems with FORTRAN programs for the same reasons.

    The cache will miss a fine on a modern processor is very large, and optimizing the use of the cache can in some cases make a difference in order of magnitude. If you identify this as a problem, you might want to rewrite the main calculation in C to give you finer-grained control over data structures.

  • If you are really connected to the CPU, you can get some mileage from techniques such as GPU programming.

+1
source share

Just because no one mentioned this:

  • Buy a faster car.

(Please don't hit me :-) ...)

+1
source share

None of fortran specific except:

  • optimize your algorithms
  • optimize data access patterns
  • use a modern compiler, for example. which supports OMP
  • Consider porting high-critical code to an environment that gives you more options — for example, for C / C ++ code, to take advantage of thread parallelization and SIMD instructions)

There is also some material available, forran optimizations for googling searches, for example. included, for example, this (PDF) and this . However, be careful with the old literature and their assumptions: recently, an optimization guide for many platforms (rightfully) suggested that memory was insufficient, memory access was cheap, and instructions were expensive. Not this way.

0
source share

The Fortran code I am familiar with is very different from code in other languages. In other languages, the data structure is much more dominant, along with layers of abstractions, deep call stacks, and slowdown caused by redundant calls .

Fortran, on the other hand, seeks to get used to mathematical algorithms with large arrays and not so much call depth. They have much more cache problems, as well as problems with the algorithm. For example, I work a lot with non-linear modeling of the mixed effect, and such issues as tolerances, advanced or central difference gradients, analytical gradients are crucial. ODE solution methods such as Runge-Kutta, implicit methods, matrix exponent, or closed form create huge differences.

In addition, if you can (by sampling) identify sections of code that are true hot spots (that is, when the PC spends most of the time without calling subroutines) and which are in the code that you are actually compiling (and not in the third-party library), then it will make a difference when optimizing compiler optimization.

Personally, I’m not interested in the types of optimization that Fortran compilers usually do, scramble the code to cut loops in code that uses less than 1% of the time fraction, making it very difficult to debug.

0
source share

All Articles