小编Ger*_*tta的帖子

从Julia调用Fortran子程序.数组工作,但整数不工作

我有这个简单的Fortran 90程序:

subroutine apc_wrapper(i, j, k)
implicit none

integer*8, intent(in) :: i, j
integer*8, intent(out) :: k
double precision t

k = i + js 
end subroutine
Run Code Online (Sandbox Code Playgroud)

编译为共享库

gfortran -O2 -shared -fPIC apc_wrapper.f90 -o apc_wrapper.so
Run Code Online (Sandbox Code Playgroud)

现在,我想从Julia调用这个子例程,带有所有整数参数,就像这样

i = 2
j = 3
k = 0

ccall( (:apc_wrapper_, "./apc_wrapper.so"), Void, (Ptr{Int64}, Ptr{Int64}, Ptr{Int64}), &i, &j, &k)
Run Code Online (Sandbox Code Playgroud)

但它不会起作用.k不会改变它的值并继续评估为0.

但是,如果我这样做

 i = 2
 j = 3
 kk = [0]

 ccall( (:apc_wrapper_, "./apc_wrapper.so"), Void, (Ptr{Int64}, Ptr{Int64}, Ptr{Int64}), &i, &j, kk)
Run Code Online (Sandbox Code Playgroud)

也就是说,使用数组存储输出,它的工作原理!调用子例程后,kk …

fortran fortran90 julia

7
推荐指数
1
解决办法
402
查看次数

标签 统计

fortran ×1

fortran90 ×1

julia ×1