Hi,
When I tried the following Fortran routine (abc.f), it worked using the
following shared file and ccall.
But when I tried after changing DOUBLE PRECISION with REAL, it did not
work. How should it be fixed.
This is what I saw on the Internet and worked:
abc.f file I saw on the Internet
SUBROUTINE MULTIPLY(A,B,C)
DOUBLE PRECISION A,B,C
C = A*B
RETURN
END
gfortran abc.f -o abc.so -shared -fPIC
a = 2.0
b = 4.2
n = Float64[1.0]
ccall((:multiply_, "abc.so"), Void,
(Ptr{Float64},Ptr{Float64},Ptr{Float64}),&a,&b, n)
julia> n
1-element Array{Float64,1}:
8.4
Again ccall worked with DOUBLE PRECISION.
When I used REAL like the following:
SUBROUTINE MULTIPLY(A,B,C)
DOUBLE PRECISION A,B,C
C = A*B
RETURN
END
and used the same procedure like
gfortran abc.f -o abc.so -shared -fPIC
a = 2.0
b = 4.2
julia> n = Array(Float64)
0-dimensional Array{Float64,0}:
0.0
julia> ccall((:multiply_, "/fullPathTo/abc.so"), Void,
(Ptr{Float64},Ptr{Float64},Ptr{Float64}), &a, &b, n)
julia> n
0-dimensional Array{Float64,0}:
1.061e-314
The default value of 0.0 changed to 1.061e-314, which is not the correct
answer.
When I assigned a specific number to n:
julia> n = Float64[1.0]
1-element Array{Float64,1}:
1.0
julia> ccall((:multiply_, "/fullPathTo/abc.so"), Void,
(Ptr{Float64},Ptr{Float64},Ptr{Float64}), &a, &b, n)
Then the array element value was not changed.
julia> n
1-element Array{Float64,1}:
1.0
I am wondering why it does not work with REAL variables.
I tried Logical, Int, and Character variables, along with Double Precision.
All worked, except for REAL.
Thanks,
Byung Lee
On Friday, November 14, 2014 at 4:08:50 PM UTC-5, Andre Bieler wrote:
>
> tried calling a simple fortran function from julia but did not succeed:
> this is the fortran code:
>
> !fileName = simplemodule.f95
> module simpleModule
>
> contains
> function foo(x)
> integer :: foo, x
> foo = x * 2
> end function foo
>
>
> end module simplemodule
>
>
> which is then compiled with:
>
> *gfortran simplemodule.f95 -o simplemodule.so -shared -fPIC*
>
> and finally the julia call is:
>
>
> ccall((:foo, "/fullPathTo/simpleMod.so"), Int32, (Int32,), 3)
>
>
> which then leads to the following error:
>
> ERROR: ccall: could not find function foo in library
> /fullPathTo/simpleMod.so
> in anonymous at no file
>
>
>
> when compiling with:
>
> gfortran -c simplemodule.f95 -o simplemodule.so -shared -fPIC
>
> i get a different error:
>
> *ERROR: error compiling anonymous: could not load module
> /fullPathTo/simplemodule.so: /fullPathTo/simplemodule.so:*
> *only ET_DYN and ET_EXEC can be loaded*
>
>
>
> Can anyone tell me what I am missing?
> I do realize I would not need to call fortran to multiply a variable by 2,
> but its a starting point..
>
>
> Thanks!
> Andre
>