[Scilab-users] Interfacing fortran code with scilab

Pierre Vuillemin contact at pierre-vuillemin.fr
Wed Feb 5 09:56:01 CET 2014


Hello all,

I am currently learning fortran in order to speed up some part o my code
and I would like to interface it with Scilab.

To make some tests, I have used this fortran code :

subroutine matmul(C,A,B,m,n,p)
    integer ::m,n,p,i,j,k
    real(kind=8),dimension(m,n),intent(in)::A
    real(kind=8),dimension(n,p),intent(in)::B
    real(kind=8),dimension(m,p),intent(out)::C
    real(kind=8):: temp
    C = 0
    do j =1,p
      do k=1,n
        temp = B(k,j)
        do i=1,m
            C(i,j)=C(i,j) + A(i,k)*temp
        end do
      end do
    end do        
end subroutine matmul

which performs a matrix multiplication. Then I have used 'ilib_for_link'
to create the link.
It works but I have some questions : 

- I did the same thing in Python with f2py and the code is seemingly
faster in python, I was wondering why ? (the precision is the same)

- If I change the 'kind = 8' to 'kind = 4' in the fortran code, the
function returns a result which completely wrong.
I expected it to be wrong, but not that much : for instance, with A = 10
and B = 20, the call to the fortran function gives me '6.36D-314'  
What is the reason? (My comprehension of how fortran types work with the
kind parameter is still limited, I know that kind=8 and kind=4 is not a
very portable expression though)

- If I replace
    real(kind=8),dimension(m,p),intent(out)::C
by
    real(kind=8),dimension(:,:),intent(out)::C
I get a segfault in Scilab or it just closes. I was wondering why ? (I
thought it was something valid since gfortran still compiles)

- Is it possible to keep the upper case in the name of fortran functions
when linked to scilab ? (At the beginning, my function was called
'matMul' and it took me some time to figure out what the error message
'matMul is not an entry point' meant)

Best regards,

Pierre Vuillemin




More information about the users mailing list