CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Speeding my Fortran Code (https://www.cfd-online.com/Forums/main/8934-speeding-my-fortran-code.html)

S March 30, 2005 04:48

Speeding my Fortran Code
 
I have a fortran serial code in fortran 90 and ifc compiler with red hat linux 9. I would like to speed my fortran code. How can I do so? S

autofly March 30, 2005 05:38

Re: Speeding my Fortran Code
 
use hugh level optimize it when you compile the code for example , f77 -O4 test.f -o test

S March 30, 2005 05:55

Re: Speeding my Fortran Code
 
How much faster did you get when you use this optimization S

scar March 30, 2005 07:58

Re: Speeding my Fortran Code
 
Before to applied any special flag in the compiler, you should check if your code was written properly, considering

loop unrolling use a correct memory pattern fusion loop correct use of cache piping ...

A good reference is the book "High Performance Computing" Dowd, K. O'Reilly

Afterward, you can improve the performance using the flags.


giorgio March 30, 2005 11:31

Re: Speeding my Fortran Code
 
You can also profile your code using the appropriate flags (-pg or -p). In this way you'll have a report of the most time-consuming routines to optimize (man gprof or man prof to know more)

Good luck, Giorgio

Xiong Yan March 31, 2005 00:52

Re: Speeding my Fortran Code
 
Optimize you source code and choose a proper compile flag (e.g. pgf90 -fastsse will do great in speed campared with "without -fastsse" when the program running on SSE instruction supported cpu)

S March 31, 2005 02:21

Re: Speeding my Fortran Code
 
I told you I have ifc compiler and I tested all level of optimzation the code without optimzations runs faster S

Xiong Yan March 31, 2005 02:53

Re: Speeding my Fortran Code
 
I just want to give u some personal advice. Now that u have tested all level of optimization the code. What answer do u want? Revise ur code or change another compiler maybe work.

andy March 31, 2005 04:10

Re: Speeding my Fortran Code
 
It is the modern practise that if you omit the optimisation flag the compiler defaults to quite a high level of optimisation. To see the performance without optimisation you probably need to pass a "no optimisation" flag.

It is also quite normal for the highest levels of optimisation to take ages to compile, produce large object code and run slower.

If you want to see effective combinations of optimisation flags for the Intel compiler look at the flags used to get the published SPEC figures on www.spec.org.

If you are passing around dynamic arrays in Fortran 95 rather than using simple Fortran 77 arrays this can impact performance. There have been articles discussing how to avoid tripping yourself up (I recall one by NAG) but I cannot find any at the moment. You will have to google for one.

I have also noticed that current Fortran optimizers on PCs are often not as effective as main frame optimizers from 20 years ago. Attention to stride length, loop ordering, using 1D rather than 3D arrays seem to have a bigger effect than they should since a Fortran optimizer (unlike a C/C++ optimizer) should be able to perform most of this.

Salvador March 31, 2005 06:11

Re: Speeding my Fortran Code
 
ifc -O3 -tpp7 the last one depending on the processor you use (P4 in this case), nothing faster so do it and forget it. Do not expect miracles only slight iprovements. ifc takes -O2 by default so even -O3 will not do much. If you are using dynamic arrays the effects maybe larger. Try running -pg and using gprof to see which subroutines take the most time and then re-think them, you will (surely) probably speed up the code much more in that way. Beware of exponential and powers, they can take a lot of time (use x*x istead of x**2). Specially if you are doing expansion series and using a lot of terms a lot of times (yp will see it in gprof) Minimize writing to files, 1D arrays instead of 3D, usual staff ... If you do not have memory costraint try to to precompute everything you can and store it before the big loops. The same apply to clusters, try reduce comunication between procs, barriers..


Tom March 31, 2005 07:08

Re: Speeding my Fortran Code
 
You probably need to use the -vec_report5 flag when you compile (I use "-xW -O3" or "-xN -O3") to see why your code is not vectorizing. You also need to ensure that you have not set any debug options since these will override any optimization (i.e. you don't want "-g" or "-check bounds" or anything similar on the compile line).

It's possible that you may need to restructure some do loops in order to help the vectorizer optimize your code. Read the optimization documentation that comes with the compiler.

Márcio Ricardo March 31, 2005 14:50

Re: Speeding my Fortran Code
 
If you're running your programs on a Pentium, you could use the Intel mkl math library. It is freely avaiable for download, like the compiler, and it's designed to work optimally with ifc and PIV.


All times are GMT -4. The time now is 23:26.