- #1
EliotHijano
- 18
- 0
Hello.
I am trying to translate a program written in MATLAB to a fortran code and I have found out that the fortran code is slower. I couldn't believe it so I decided to do a simple program in fortran 90 and MATLAB in order to be sure. The code in MATLAB is:
function D2D()
Nx=2^11;
Ny=2^9;
Yr=ones(Ny,Nx);
for i=1:3000
Yr=Yr.*Yr;
end
'done'
end
and the code in fortran 90 is:
program D2D
IMPLICIT NONE
integer, parameter::NxL=11
integer, parameter::NyL=9
integer, parameter::Nx=(2**NxL) ! Grid size X
integer, parameter::Ny=(2**NyL) ! Grid size Y
INTEGER::i,IC,JC
complex*8, dimension(Ny,Nx):: Yr
DO i=1,3000
FORALL(IC=1:Ny,JC=1:Nx) Yr(IC,JC)=Yr(IC,JC)*Yr(IC,JC)
ENDDO
WRITE(*,*) 'done'
end program D2D
The fortran code is twice slower. Any idea why? What am I coding wrong in fortran?
thx.
I am trying to translate a program written in MATLAB to a fortran code and I have found out that the fortran code is slower. I couldn't believe it so I decided to do a simple program in fortran 90 and MATLAB in order to be sure. The code in MATLAB is:
function D2D()
Nx=2^11;
Ny=2^9;
Yr=ones(Ny,Nx);
for i=1:3000
Yr=Yr.*Yr;
end
'done'
end
and the code in fortran 90 is:
program D2D
IMPLICIT NONE
integer, parameter::NxL=11
integer, parameter::NyL=9
integer, parameter::Nx=(2**NxL) ! Grid size X
integer, parameter::Ny=(2**NyL) ! Grid size Y
INTEGER::i,IC,JC
complex*8, dimension(Ny,Nx):: Yr
DO i=1,3000
FORALL(IC=1:Ny,JC=1:Nx) Yr(IC,JC)=Yr(IC,JC)*Yr(IC,JC)
ENDDO
WRITE(*,*) 'done'
end program D2D
The fortran code is twice slower. Any idea why? What am I coding wrong in fortran?
thx.