 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
joemezni
Joined: 14 Jan 2013 Posts: 8
|
Posted: Wed Jan 16, 2013 8:25 pm Post subject: question on the speed of the excution |
|
|
Hi all,
I am new to fortran programming. actually i have written a program that reads FEM nodes coordinates and computes the distance between them then i use that matrix of distances to do other stuff.
I tryied this program for only 9 nodes , it is realyvery slow compared to matlab (I can not imagine that i can use it for 100 nodes).
PLease help finding away to speed it up or may be find me some fundatmental mistakes in my code. is it the question of bound check ??? or something else ......
please help me
program test21
! 8
! 7 - - - - - - 9
! | | |
! | | |
! | |5 |
! 4 - - - - - - - 6
! | | |
! | | |
! | | |
! - - - - - - -
! 1 2 3
!
! this program compute
! 1- the distance for each node to all others and place these distances in the matrix DDIST
! 2- out of DDIST, 2 other matrices of the same size DSIN and DCOS are computed
! 3- and then assembled to get finally the matrix RADMAT
!
implicit none
real,dimension(27)::a=(/0.,0.,0.,0.,1.,0.,0.,2.,0.,1.,0.,0.,1.,1.,0.,1.,2.,0.,2.,0.,0.,2.,1.,0.,2.,2.,0./)
real,dimension(9,3)::dcoor
integer :: Nnodes=9,dfreq=5,fj,i,j,indexij
real,dimension(5)::freqlines=(/1.,2.,3.,4.,5./)
complex,dimension(9,9,5)::radmat
real :: dsx=1.,dsy=1.,ka,ks,freq
real,dimension(9,9) :: dsin,dcos,ddist,d0,zetha,index
real,dimension(10000001)::y0ij
real,parameter :: pi=3.14159265
real,parameter :: c=341.
!
dcoor=transpose(reshape(a,(/3,9/)))
!---------------------------------------------------------
! compute the distance between all nodes
!---------------------------------------------------------
do i=1,Nnodes
ddist(:,i)=sqrt(sum((dcoor - spread(dcoor(i, ,1,Nnodes))**2,2))
end do
!
do fj=1,dfreq
freq = freqLines(fj)
ka=(2*pi*freq)/c
!----------------------------------------------------------
! compute dsin: 'the real part of radmat'
!---------------------------------------------------------
d0=ddist
forall(i=1:Nnodes) d0(i,i)=1.
dsin=(sin(ka*d0))/(ka*d0)
forall(i=1:Nnodes) dsin(i,i)=1.
ks=sqrt(2*(pi**2)/(dsx*dsy))
!----------------------------------------------------------
! compute dcos: 'the imaginary part of the radmat'
!----------------------------------------------------------
dcos=cos(ka*ddist)-1.
open(unit=25,file='j0tab.dat',status='old',action='read')
index=int(ceiling(1000.*ks*ddist) + 1.)
do i=1,Nnodes
do j=1,Nnodes
indexij=index(i,j)
read(25,'(10000001F10.4)')y0ij
zetha(i,j)=y0ij(indexij)
end do
end do
close(25)
dcos=dcos + zetha
forall(i=1:Nnodes) dcos(i,i)=1.
dcos=dcos/(ka*ddist)
forall(i=1:Nnodes) dcos(i,i)=ks/ka
!----------------------------------------------------------
!
radmat(:,:,fj)=8*pi*((ka**2)/(ks**4))*(cmplx(dsin,dcos))
!
!-----------------------------------------------------------
end do
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(1,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(2,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(3,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(4,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(5,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(6,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(7,:,1)
write(*,*) '-------------------------'
write(*,'(9F10.4)') radmat(8,:,1)
write(*,*) '--------------------------'
write(*,'(9F10.4)') radmat(9,:,1)
write(*,*) '-------------------------'
end program test21 |
|
Back to top |
|
 |
brucebowler Guest
|
Posted: Wed Jan 16, 2013 9:00 pm Post subject: Re: question on the speed of the excution |
|
|
The first thing I see is that in this set of loops
joemezni wrote: | Code: |
do i=1,Nnodes
do j=1,Nnodes
indexij=index(i,j)
read(25,'(10000001F10.4)')y0ij
zetha(i,j)=y0ij(indexij)
end do
end do
|
|
you're reading a 10,000,001 element array 81 times! That's going to take some time. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Jan 17, 2013 8:46 pm Post subject: Re: question on the speed of the excution |
|
|
brucebowler wrote: |
you're reading a 10,000,001 element array 81 times! That's going to take some time. |
Agreed. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Sun Jan 20, 2013 1:55 pm Post subject: |
|
|
I'd be interested if this was the intended read statement.
If so, why did you create the file 'j0tab.dat' with a single record which is 100,000,010 characters long.
Did you intend to write :
read (25,'(F10.4)') y0ij(indexij) ! read one value per line
John |
|
Back to top |
|
 |
joemezni
Joined: 14 Jan 2013 Posts: 8
|
Posted: Tue Jan 22, 2013 7:31 pm Post subject: |
|
|
HI john
yes exactly this is what i want to read. you should know that computing the terme yij(indexij) needing also 2 loops, that is why i did that once (file jotab.dat) supposing that i should be faster .
Actually the programm is very fast because i read the file one and out of the loops. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|