Making FORTRAN code more efficient


 
Thread Tools Search this Thread
Top Forums Programming Making FORTRAN code more efficient
# 1  
Old 08-06-2010
Making FORTRAN code more efficient

Hi, I have a very large, very old FORTRAN code that I work with. The code is quite messy and I was wondering if I can speed up execution time by finding subroutines that code execution spends the most time in. Is there any kind of software I can use to see where the code spends most of the execution process?

Also, I made some changes to the code so it writes a whole bunch of extra output files during execution. I just ran the unmodified version of the code and noticed it seems to run a lot faster than my modified version. Does writing to text files bog down the execution that much?
# 2  
Old 08-10-2010
Hi.

Here is a contrived code in Fortran-77 style (change the do-enddo to do ... statement-number, if you wish):
Code:
	program main
	parameter ( n = 10 000 000 )
	dimension t(n)
	do i = 1, n
	t(i) = i
	enddo
	call a ( t, int( .10*n ), sum )
	call b ( t, int( .25*n ), sum )
	call c ( t, n, sum )
	end
	subroutine a ( t, n, sum )
	write(*,*) " Entered: a"
	call a1 ( t, n, sum )
	return
	end
	subroutine a1 ( t, n, sum ) 
	dimension t(n)
	write(*,*) " Entered: a1"
	sum = 0
	do i=1,n
	sum = sum + t(i)
	enddo
	return
	end
	subroutine b ( t, n, sum )
	dimension t(n)
	write(*,*) " Entered: b"
	sum = 0
	do i=1,n
	sum = sum + t(i)
	enddo
	call b1
	return
	end
	subroutine b1
	write(*,*) " Entered: b1"
	call b2
	return
	end
	subroutine b2
	write(*,*) " Entered: b2"
	return
	end
	subroutine c ( t, n, sum )
	dimension t(n)
	write(*,*) " Entered: c"
	sum = 0
	do i=1,n
	sum = sum + t(i)
	enddo
	return
	end

We compile with GNU Fortran, and state that we wish to include profiling code:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate obtaining a Fortran execution profile.

pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
pe
# (Local utility version)
version gfortran gprof

FILE=one.f
rm -f a.out gmon.out

gfortran -pg $FILE
./a.out

gprof --brief

exit 0

Producing (excerpt):
Code:
gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
GNU gprof (GNU Binutils for Debian) 2.18.0.20080103
  Entered: a
  Entered: a1
  Entered: b
  Entered: b1
  Entered: b2
  Entered: c

...

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 45.63      0.10     0.10        1   100.38   100.38  c_
 41.06      0.19     0.09        1    90.34   220.83  MAIN__
  9.13      0.21     0.02        1    20.08    20.08  b_
  4.56      0.22     0.01        1    10.04    10.04  a1_
  0.00      0.22     0.00        1     0.00    10.04  a_
  0.00      0.22     0.00        1     0.00     0.00  b1_
  0.00      0.22     0.00        1     0.00     0.00  b2_

Which would suggest that c and MAIN be looked at.

See man pages for details. Good luck ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making a script secure to code injection

Heyas I've been told my scipts would be insecure, and to fix that. Figured i might rethink some parts of my coding style, meanwhile i tried to write an additional catcher. After reading: fail : Security Issues - didnt help too much, infact - it confused me even more. n/a:... (8 Replies)
Discussion started by: sea
8 Replies

2. Programming

Strange characters in FORTRAN code output

Hi guys, After compiling a .f90 code and executing it, i get strange characters in the output file like : ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ Are these windows characters? how can i get rid of this? Much appreciated. Paul (1 Reply)
Discussion started by: Paul Moghadam
1 Replies

3. Shell Programming and Scripting

Efficient shell script code

Hi all, I am working on an extremely large collection of text data (about 2 million XML files) in a directory. I have changed the extension from .xml to .dat. Right now I am using this code to remove the XML tags, but the code is way too slow. It seems that it is taking fore-ever: #ls -1 *.dat... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Programming

Removing goto statements in FORTRAN code

I have the code below and I want to remove the "go to" statements. Any idea how I can do it? if (iorder == 0) then tmincurrent = 1.0e11 if(ireverse == 0 .or. istop /= 1) then do i = 1, 6 if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then ... (1 Reply)
Discussion started by: kristinu
1 Replies

5. Shell Programming and Scripting

Efficient rewrite of code?

egrep -v "#" ${SERVERS} | while read shosts do grep -Pi "|" ${LOGFILE} | egrep "${snhosts}" | egrep "NOTIFICATION:" | awk -F";" '{print $3}' | sort -n | uniq | while read CEXIST do ... (6 Replies)
Discussion started by: SkySmart
6 Replies

6. Programming

Using Doxygen on Fortran code

I am using doxygen for documenting my fortran code. I want to write some notes after the header in different parts of the subroutine. Any idea what the tags should be as anything I write after the header is not displayed ... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Making use of PWD command in the code

Hi all, Need some help in the following code. (Running this code at cygwin in windows vista) cat /home/ebanpan/Input_Logs/*.log > /home/ebanpan/Input_Logs/input.log sed '/^Total/d;/^Bye/d;/^Output has been logged/d' /home/ebanpan/Input_Logs/input.log > /home/ebanpan/output.log this code... (6 Replies)
Discussion started by: bansalpankaj88
6 Replies

8. Programming

Help with make this Fortran code more efficient (in HPC manner)

Hi there, I had run into some fortran code to modify. Obviously, it was written without thinking of high performance computing and not parallelized... Now I would like to make the code "on track" and parallel. After a whole afternoon thinking, I still cannot find where to start. Can any one... (3 Replies)
Discussion started by: P_E_M_Lee
3 Replies

9. Programming

Error running FORTRAN code

Hi, I am new to this forum and do not know whether this is the appropriate place to post this question. Anyway am trying my luck. I have a fortran program swanhcat.ftn, which is part of a wave modelling system. There is also a file hcat.nml which is required to run this program. The program's... (9 Replies)
Discussion started by: sandhyakg
9 Replies
Login or Register to Ask a Question