fortran - why move_alloc is not working in gfortran (4.6.3), but it is in ifort? -


i've read here move_alloc works since gfortran 4.2. i'm gfortran 4.6 installed in ubuntu 12.04 move_alloc not working! move_alloc used 5 times inside loop runs 10 times. after compiled (without error or warning) gfrotran, program runs 1 step (some prints verify mistake) of loop , shows "segmentation fault(kernel image recorded)'. however, when ifort used, program runs , works correctly. have tried use gfortran 4.4.6 in centos. both computers x86_64.

other important information: piece of code in subroutine, inside module, once don't know size of vector allocated move_alloc. these vector attribute intent (out) in subroutine. xray_all, yray_all , elem_all double precision , other integer. main , module in different files. here piece of code use move_alloc:

program main double precision,allocatable,dimension(:)::xrayall,yrayall (...)other allocatable variables call yyyy(....,ray_indent,xray_all,...) end program main   module xxxx subroutine yyyy j=1,10   <lots of calculation>       allocate( vec_aux( 1:(i+size(ray_indent) ) ) )      vec_aux(1:size(ray_indent))=ray_indent      vec_aux(size(ray_indent)+1:)=j         call move_alloc(vec_aux,ray_indent)       allocate( vec_auxreal( 1:(i+size(xray_all) ) ) )     vec_auxreal(1:size(xray_all))=xray_all     vec_auxreal(size(xray_all)+1:)=xray     call move_alloc(vec_auxreal,xray_all)                allocate( vec_auxreal( 1:(i+size(yray_all) ) ) )     vec_auxreal(1:size(yray_all))=yray_all     vec_auxreal(size(yray_all)+1:)=yray     call move_alloc(vec_auxreal,yray_all)                   elemsize=count(icol/=0);       allocate( vec_auxreal( 1:(elemsize+size(elem_all) ) ) )      vec_auxreal(1:size(elem_all))=elem_all      vec_auxreal(size(elem_all)+1:)=elem(1:elemsize)      call move_alloc(vec_auxreal,elem_all)                allocate( vec_aux( 1:(elemsize+size(icol_all) ) ) )      vec_aux(1:size(icol_all))=icol_all      vec_aux(size(icol_all)+1:)=icol(1:elemsize)      call move_alloc(vec_aux,icol_all)      allocate( vec_aux( 1:(elemsize+size(irow_all) ) ) )     vec_aux(1:size(irow_all))=irow_all     vec_aux(size(irow_all)+1:)=j+control           !     call move_alloc(vec_aux,irow_all) end end module xxxx end subroutine yyyy 

i have found solution! in gfortran necessary add following if statement in 5 expressions:

 allocate( vec_auxreal( 1:(elemsize+size(elem_all) ) ) )  if (j/=1) vec_auxreal(1:size(elem_all))=elem_all   vec_auxreal(size(elem_all)+1:)=elem(1:elemsize)   call move_alloc(vec_auxreal,elem_all) 

this happens because, in gfortran if vector still empty, not recognized nothing added. in ifort (tested in version 12.0), if statement not necessary program work.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -