fortran - Why does this code seg fault (during allocation) with pgi but not intel? -
this code works when run on intel compiler. when ran pgi, seg faults between * , ** in subroutine listed. i'm using pgi compiler -mcmodel-medium. need utilize pgi start using openacc code. ideas might wrong? in advance!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !reading in trajectories 'md.traj' file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine read_input(time_i,time_f,dt,ion_count,x,y,z,lf,l,nsteps) implicit none integer*4, intent(in) ::time_i,time_f,dt real*4,intent(out),dimension(:,:), allocatable ::x,y,z real*4 ::vx,vy,vz real*8, intent(out) ::lf,l integer*4 ::time,t,j,nsteps integer*4 ::ion_count character*100 ::filename character*5 ::timezone character*6 ::xfiletype character*8 ::xcode_version,date character*10 ::xcode_name,daytime character*20 ::xsim_type real*8 ::time_set,aspect(3),ev,ek,ppx,pp(9),rho write (*,*) '*' allocate(x(1:51200,0:nsteps)) allocate(y(1:51200,0:nsteps)) allocate(z(1:51200,0:nsteps)) write (*,*) '**' open(unit=20,file='md.traj.00007000000.xv4b',status='old',form='unformatted',convert='big_endian') 20, time=time_i, time_f, dt write (*,*) time write(*,1001) time 1001 format ('md.',1i11.11,'.x4b') write (filename,1001) time read(20) xfiletype read(20) xcode_name, xcode_version read(20) date,daytime,timezone read(20) xsim_type read(20) time_set,rho,aspect(1),aspect(2),aspect(3),ev, ek, ppx, pp, ion_count !rho=ion_count/(xl(1)*xl(2)*xl(3)) t=(time-time_i)/dt
!without allocating within subroutine code seg faults @ line
read (20) (x(j,t),y(j,t),z(j,t),vx,vy,vz, j=1,ion_count) l=(ion_count/(rho))**(1.0/3.0) !write (*,*) x(500,5),'in read input' lf=(2*3.1415)/l 20 go on homecoming end subroutine read_input !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
here's main code
programme sofq implicit none integer :: time,time_u,j,i,k,omp_num_threads integer :: t1,t3,t4,k2 integer :: dw,t,time1,time2 real*4 :: sumbin(0:50000) real*8 :: f(0:500,0:10000) integer :: q1,q2,q3,q4,q5,n1,n2,n3,n4,n5,qcur real*4 :: ci,co(0:6537673),si(0:6537673),b(0:6537673) real*8 :: dotprod,co_temp,si_temp real*4 :: qavg,zz,qmax,pfrac,nfrac complex*16,allocatable:: q(:,:) complex :: sumbin1(0:50000),sumbin2(0:50000) double precision :: yy character :: sofq_output,dumb parameter (ci=(0,-1)) real*8 ::rtemp1,rtemp2,rtemp3 character*5 :: simtype integer*4 ::p_start,p_end,nsteps !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! declarations read_input !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! integer*4 ::time_i,time_f,dt,ion_count real*4,dimension(:,:),allocatable ::x,y,z real*8 ::lf,l !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !declarations read_vectors !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! integer*4 ::vmax,lines,i_vmax integer*4, dimension(1:6537673) ::rx,ry,rz,mag,degen !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !declarations compute_sq !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! integer*4 ::ions,t2 real*8, allocatable ::s(:) complex*16,allocatable ::r(:,:) open (unit=11,file='sqt_n1_gpu.dat') write (*,*) 'begin' phone call system_clock(time1) dt=20 time_i= 7000000 time_f= 7000500 !7050000 nsteps=(time_f-time_i)/dt allocate(x(1:51200,0:nsteps)) allocate(y(1:51200,0:nsteps)) allocate(z(1:51200,0:nsteps)) ion_count=51200 qmax=0.6 simtype='pfrac' ! omp_num_threads=16 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!parallel test!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !$omp parallel ! write (*,*) 'parallel?' ! !$omp end parallel !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! phone call read_input(time_i,time_f,dt,ion_count,x,y,z,lf,l,nsteps) write (*,*) 'input'
so few commenters asked reallocation within subroutine. did because first tried without sec allocation , received segmentation fault in subroutine when read in first x() value. tried again, commenting out allocation in subroutine , found pgi seg faulted during read x() , intel compiler did same. line indicated bold above.
when utilize intent(out)
argument allocatable array, array variable (in case x, y , z), becomes "unallocated" @ entering subroutine. so, in case, have allocate within subroutine before starting utilize it.
when allocate allocatable array within subroutine, because associated dummy argument, not deallocated @ end of subroutine happen if array local one.
so, can declare x, y , z intent(inout)
(or nothing, in case "intent(inout)" have same impact not defining intent) , there no need allocate array 1 time again within subroutine. or can allocate within routine , avoid allocation outside it. think bad practice 1 time seems want utilize arrays outside subroutine.
the fact both compilers "seg fault" when utilize code without "allocating" within subroutine right behaviour, arrays unallocated @ entering subroutine (because of intent (out)). fact pgi "seg fault" in case allocate arrays "again" within subroutine seems kind of compiler bug. in case, allocating outside subroutine can available alternative if utilize pgi.
segmentation-fault fortran dynamic-memory-allocation pgi
No comments:
Post a Comment