Fortran - Segmentatation fault (core dumped) -
this kind of follow questions fortran array dynamic size, easy r function seq() , asked previoulsy, in sense still same error when run program:
program received signal sigsegv: segmentation fault - invalid memory reference. backtrace error: #0 0x7f13e6fd87d7 #1 0x7f13e6fd8dde #2 0x7f13e6929fef #3 0x4014b6 in fillmatrix_ #4 0x40270e in main__ @ dyn.f90:? segmentation fault (core dumped)
i made slight changes program:
program dyn implicit none real(kind=8), allocatable :: k(:), tt1(:), p(:) real(kind=8), allocatable :: fitness(:,:), k_opt(:,:) real(kind=8) :: dk = 0.1, dp = 0.1 integer :: j,l,m,lk,lp,lt external :: derivate, fillmatrix k = 0.1*dk*[(j,j=0,999)] ! vector of basal expression levels p = 0.4*dp*[(l,l=1,1000)] ! vector of period lengths tt1 = 0.1*dk*[(m,m=0,999)] ! vector of values t1/t lk = size(k) lp = size(p) lt = size(tt1) call fillmatrix(k,p,tt1,lk, lp, lt, fitness, k_opt) end program dyn subroutine fillmatrix(k,p,tt1,size_k, size_p, size_tt1, fitness, k_opt) implicit none integer, intent(in) :: size_k, size_p, size_tt1 real(kind=8) :: k(size_k), p(size_p), tt1(size_tt1) real(kind=8), allocatable :: results(:), t(:) real(kind=8) :: num = 10, t0,t1,t2,t3 real(kind=8) :: periode, laenge, basal, lenge real(kind=8) :: dt = 0.1 real(kind=8), dimension(6) :: q0, x_new, res real(kind=8), dimension(6) :: u0,f1,f2,f3,u1, k1,k2,k3,k4 real(kind=8), dimension(size_k,size_tt1), intent(out) :: fitness real(kind=8), dimension(size_p, size_tt1), intent(out) :: k_opt integer :: i,j,l,m,n,o,q,r,posi open(unit = 10,file = '3d.txt', status = 'unknown') ! save data in .txt file n=1, size(p) periode = p(n) ! set period length o=1,size(tt1) laenge = tt1(o) ! set turning point t1/t q=1,size(k) basal = k(q) ! set level of basal expression lenge = 10*num*periode t = 0.1*dt*[(i,i=0,int(lenge))] ! initial conditions vector q0 q0(1) = 0 ! x q0(2) = basal ! y q0(3) = 0 ! z q0(4) = 0 ! q0(5) = 1 ! b q0(6) = 0 ! w x_new = q0 ! set initial conditions r = 1, size(t) call derivate(basal,periode,laenge,t(r),x_new,k1) t1 = t(o) + dt/2 f1 = x_new + (dt*k1)/2 call derivate(basal,periode,laenge,t1,f1,k2) t2 = t(o) + dt/2 f2 = x_new + (dt*k2)/2 call derivate(basal,periode,laenge,t2,f2,k3) t3 = t(o) + dt f3 = x_new + (dt*k3)/2 call derivate(basal,periode,laenge,t3,f3,k4) res = x_new + (dt*(k1+2*k2+2*k3+k4))/6 if (res(2) < basal) res(2) = basal endif results = res(6) fitness(q,o) = maxval(results)/lenge end end posi = maxloc(fitness(o,:),1) k_opt(o,n) = k(posi) end end write(10,*) k_opt end subroutine fillmatrix
i have tried find cause of error several hours now, no closer finding it.
at call fillmatrix
not of arrays allocated. not legal because explicit size arguments , not have right shape (or shape in fact). case of array fitness
, k_opt
.
because beginner, couple of advices:
use debugging options. example,
gfortran -wall -fcheck=all -g -fbacktrace
.for program gfortran writes:
at line 18 of file test.f90 fortran runtime error: allocatable actual argument 'fitness' not allocated
when run program.
put subroutines module, enable better passing options , checks.
after did that, use assumed shape arrays
(:,:,:)
dummy arguments, avoid copies may encounter explicit size.do not use
real(kind=8)
, not portable, there many examples here on how that. use named constant, , kind valueselected_real_kind()
oriso_fortran_env
modules constantsreal32
,real64
.
Comments
Post a Comment