Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Some clarifications to the language shootout page
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Siegfried Gonzi <siegfried.gonzi@k...>
Subject: Re: [Caml-list] Some clarifications to the language shootout page
For the sake of completeness: An update to the Fortran 90/95 version. 
This version comes close to C and even surpasses it a bit after adding a 
few lines (the overal matrix matrix multiplication scheme just remains 
valid, though). The author (thanks to François BÉREUX) gave the okay for 
posting it here:


I reply to you privately about the F90 code of the benchmark you mention (because this
is only Fortran related and not Caml related, but you can quote my e-mail if you want):

there is a primitive in the F90 language called matmul which precisely does dense
matrix-matrix multiplication, and which is pretty well optimized.

I ran the test on a Sun Solaris Ultra SParc III 600 MHz , with the compiler suite
WorkShop 6.2, and I got the following timings :

1) your C version (compiled with the -fast option) :

2) your F90 version (compiled with the -fast option) :

3)a F90 version using matmul (compiled with the -fast option ):

I guess a similar conclusion will hold on your platform.

Now, if you do not want to use the matmul or dot_product primitives and would like to
program in a F77 way, the following code for mmult is better suited than yours:

subroutine mmult(m, n, a, b, c)
integer, intent(in) :: m,n
double precision, dimension(:,:), intent(in) :: a,b
double precision, dimension(:,:), intent(out) :: c
integer :: i,j,k
!! initialize c by 0.
do j = 1, n
   do i = 1, m
      c(i,j) = 0.0
do k = 1, n
   do j = 1, n
      do i =1, m
         c(i,j) = c(i,j) + a(i,k)*b(k,j)
end subroutine mmult

4)a F90 version with an improved mmult (compiled with the -fast option ):
which is faster than the C version.

Best regards,

F. Béreux

PS : please find enclosed the F90 code using matmul:

version using matmul
program main
  integer:: size=512
  double precision, POINTER,dimension(:,:):: m1, m2, mm

  call mkmatrix(size,size,m1)
  call mkmatrix(size,size,m2)
  call mkmatrix(size,size,mm)

  mm = matmul(m1,m2)

  print *, mm(1,1)



subroutine mkmatrix(rows, cols,m)
  integer, intent(in):: rows, cols
  double precision, POINTER, dimension(:,:):: m
  double precision:: counter
  integer:: i,j


  counter = 1.0
  do i=1,cols
     do j=1,rows
        counter = counter + 1.0
        m(j,i) = counter
     end do
  end do
end subroutine mkmatrix

end program main

S. Gonzi

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: