我在Fortran中使用了非常大的代码。它被称为sapick6.f90
。如果我编译这段代码:
gfortran -O3 -o sapick6 sapick6.f90
并运行它:
./sapick6
我总是得到完全相同的结果(如预期的那样)。它具有随机数子例程,但是种子在开头始终是相同的,因为它从文件中读取输入参数。
结果是:
Mean window energy: 1.84019
Final window energy: 19.98531
Qe: SNR (Ursin): 18.53402
Rc: c_mean/c_mean_noise: -53.57054
e_tmean: 0.00000
Mean weighted az. (r>0.5): 19.71334
总是
现在,我从
更改此代码的初始行 PROGRAM sapick6
USE nrtype
IMPLICIT NONE
INTEGER :: i,ii,iii,j,jj,ijk,k,n
INTEGER, PARAMETER :: mp = 5, np = 10
INTEGER, PARAMETER :: imax = 5001,jmax = 8,kmax = 251
INTEGER :: NTRACES, NSAMP
...code....
...code...
end PROGRAM
简单地说:
SUBROUTINE sapick6
USE nrtype
IMPLICIT NONE
INTEGER :: i,ii,iii,j,jj,ijk,k,n
INTEGER, PARAMETER :: mp = 5, np = 10
INTEGER, PARAMETER :: imax = 5001,jmax = 8,kmax = 251
INTEGER :: NTRACES, NSAMP
...code....
...code...
end SUBROUTINE
请注意,我只将program
更改为subroutine
。编译为库时:
gfortran -shared -fPIC sapick6.f90 -o sapick6.so
用julia(第一次)运行:
julia> function callsapick()
t=ccall((:sapick6_,"./sapick6.so"),Void,(),)
return
end
callsapick (generic function with 1 method)
julia> callsapick()
Mean window energy: 1.84019
Final window energy: 19.98531
Qe: SNR (Ursin): 18.53402
Rc: c_mean/c_mean_noise: -53.57054
e_tmean: 0.00000
Mean weighted az. (r>0.5): 19.71334
并在朱莉娅(第二次)上运行:
julia> callsapick()
signal (11): Violación de segmento
while loading no file, in expression starting on line 0
sapick6_ at ./sapick6.so (unknown line)
callsapick at ./REPL[1]:2
unknown function (ip: 0x7f8ec525e4af)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:75
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:34
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:577
jl_toplevel_eval_in at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:496
eval at ./boot.jl:235
unknown function (ip: 0x7f8ed988439f)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7f8ed98f21cf)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7f8ec52572af)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1424 [inlined]
start_task at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:267
unknown function (ip: 0xffffffffffffffff)
Allocations: 1178414 (Pool: 1177210; Big: 1204); GC: 0
Mean window energy: 1.20471
Final window energy: 20.11686
Qe: SNR (Ursin): 2.15156
Rc: c_mean/c_mean_noise: -32.36376
e_tmean: 0.00000
Mean weighted az. (r>0.5): 6.55283
所以我得到了不同的结果,甚至最糟糕的是,分段错误!
发生了什么事?