PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

issue with optional argument and assumed shaped array

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
xlapillonne



Joined: 16 Feb 2011
Posts: 69

PostPosted: Tue Mar 19, 2013 2:00 am    Post subject: issue with optional argument and assumed shaped array Reply with quote

Hi,

I am having some seg fault with a fortran code when compiled with pgf90 (I tried with pgi12.10). I find out, that the problem comes from a place where we use assumed shaped array and explicit array at different level of subroutine calls. Here is a reproducible small example (all array are contiguous):

Code:

program test_optional
  implicit none
  integer :: nargs, n
  real :: X_1d(2),M_1d(2), M_2d(2,2)
  character*10 arg

  nargs = command_argument_count()
  if( nargs == 1 ) then
     call getarg( 1, arg )
     read(arg,"(I8)") n
  else
     print*, 'usage ./test n'
     STOP
  endif

  X_1d(:)=real(n)
  M_1d(:)=real(n)
  M_2d(:,:)=real(n)

  if (n>1) then
     call my_print_1d(X_1d,M=M_1d)
     call my_print_2d(X_1d,M=M_2d)
  else
     call my_print_1d(X_1d)
     call my_print_2d(X_1d)
  end if

contains

subroutine my_print_1d(X,M)
  real, intent(in) :: X(:)
  REAL ,       INTENT(IN),    OPTIONAL :: M(:)
  INTEGER :: id

  id=SIZE(X,1)

  call my_print(X,id,1,M=M)

end subroutine my_print_1d

subroutine my_print_2d(X,M)
  REAL, INTENT(IN) :: X(:)
  REAL, INTENT(IN),    OPTIONAL :: M(:,:)
  INTEGER :: id
  id=SIZE(X,1)

  call my_print(X,id,id,M=M)

end subroutine my_print_2d

subroutine my_print(X,id1,id2,M)
  real, intent(in) :: X(id1)
  integer, intent(in) :: id1
  integer, intent(in) :: id2
  REAL ,  intent(IN),    OPTIONAL :: M(id1,id2)
  INTEGER :: i,j
 
  if(present(M)) then
     do j=1,id2
        do i=1,id1
           print*, 'M,i,j',i,j,M(i,j)
        end do
     end do
  end if

  print*, 'X', X(:)

end subroutine my_print


end program test_optional



The segfault only appears when the optional are not passed:

Code:


> pgf90 -o test_optional test_optional.f90
> ./test_optional 0
Segmentation fault
> ./test_optional 2
 M,i,j            1            1    2.000000   
 M,i,j            2            1    2.000000   
 X    2.000000        2.000000   
 M,i,j            1            1    2.000000   
 M,i,j            2            1    2.000000   
 M,i,j            1            2    2.000000   
 M,i,j            2            2    2.000000   
 X    2.000000        2.000000   


Is what I am doing illegal ? I've tried with gfortran, and there it is not an issue. Do you have any suggestion on how I should proceed (basically I would like to use the same routine my_print for array M of different dimensions)


Thanks,

Xavier
Back to top
View user's profile
toepfer



Joined: 04 Dec 2007
Posts: 45

PostPosted: Wed Mar 20, 2013 3:13 pm    Post subject: Reply with quote

Thanks Xavier. I have sent a report to our engineers(TPR#19220) who will investigate
further.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 4996
Location: The Portland Group Inc.

PostPosted: Mon Apr 15, 2013 2:09 pm    Post subject: Reply with quote

Hi Xavier,

I got word that TPR#19220 will be fixed in the 13.5 release.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group