Hi,

Mosè Giordano <[email protected]> writes:
> I'm working on a Fortran77 code, but I'd much prefer to translate it
> to Julia. However, I've the impression that when working with large
> arrays (of the order of tens of thousands elements) Julia is way
> slower than the equivalent Fortran code.

I'm late into the conversation, but I wanted to have a go at
this. First, I rewrote the Fortran77 code to use modern Fortran, so I
end up with:

JULIA:
,----
| function foo()
|  array1 = rand(70, 1000)
|  array2 = rand(70, 1000)
|  array3 = rand(2, 70, 20, 20)
|  bar = 0.0
|  @time @inbounds for l = 1:1000, k = 1:20, j = 1:20, i = 1:70
|         bar = bar +
|             (array1[i, l] - array3[1, i, j, k])^2 +
|             (array2[i, l] - array3[2, i, j, k])^2
|  end
| 
|  println("$bar")
| 
| end
| foo()
`----

FORTRAN:
,----
| PROGRAM main
|   IMPLICIT NONE
| 
|   DOUBLE PRECISION, DIMENSION(70,1000) :: array1, array2
|   DOUBLE PRECISION, DIMENSION(2,70,20,20) :: array3
|   DOUBLE PRECISION :: bar, start, finish
|   INTEGER :: i,j,k,l
| 
|   CALL RANDOM_NUMBER(array1) ; CALL RANDOM_NUMBER(array2) ; CALL  
RANDOM_NUMBER(array3)
| 
|   bar = 0.0D0
| 
|   CALL CPU_TIME(start)
|   DO CONCURRENT (l=1:1000,k=1:20,j=1:20,i=1:70)
|      bar = bar + (array1(i,l) - array3(1,i,j,k))**2 + &
|           (array2(i,l) - array3(2,i,j,k))**2
|   END DO
| 
|   CALL CPU_TIME(finish)
|   WRITE(*,'(f10.6,a)') finish-start, " seconds"
|   PRINT*, bar
| END PROGRAM main
`----

The timings in my laptop for the julia code and the Fortran code
compiled with gfortran are basically identical, but in a machine where I
have access to the Intel compiler, Fortran gets again the lead (though I
understand that it is not a very fair comparison). [Fortran code
compiled with -O3].


[angelv@duna TESTS]$ julia -f test.jl
elapsed time: 0.085587272 seconds (0 bytes allocated)
9.35894273977078e6

[angelv@duna TESTS]$ ./test_gfortran 
  0.131018 seconds
   9316684.8268513940

[angelv@duna TESTS]$ ./test_ifort 
  0.032021 seconds
   9363171.53179595
[angelv@duna TESTS]$ 

-- 
Ángel de Vicente
http://www.iac.es/galeria/angelv/          

Reply via email to