Sponsored Content
Top Forums Programming Making FORTRAN code more efficient Post 302443979 by drl on Tuesday 10th of August 2010 02:51:12 PM
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
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
SUM(1)								   User Commands							    SUM(1)

NAME
sum - checksum and count the blocks in a file SYNOPSIS
sum [OPTION]... [FILE]... DESCRIPTION
Print checksum and block counts for each FILE. -r use BSD sum algorithm, use 1K blocks -s, --sysv use System V sum algorithm, use 512 bytes blocks --help display this help and exit --version output version information and exit With no FILE, or when FILE is -, read standard input. AUTHOR
Written by Kayvan Aghaiepour and David MacKenzie. REPORTING BUGS
Report sum bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> Report sum translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for sum is maintained as a Texinfo manual. If the info and sum programs are properly installed at your site, the command info coreutils 'sum invocation' should give you access to the complete manual. GNU coreutils 8.5 February 2011 SUM(1)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy