PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Segmentation error when passing functions as arguments

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling
View previous topic :: View next topic  
Author Message
gtokic



Joined: 26 Jun 2007
Posts: 3

PostPosted: Wed Dec 02, 2009 2:39 am    Post subject: Segmentation error when passing functions as arguments Reply with quote

Hi,

I'm having problems with pgf90 when running a code that often passes functions as arguments. The code compiles correctly but has a run-time error (sample code attached below). The same code works correctly when compiled with ifort.

Code:


module mod_util
 implicit none
 contains

   function do_something(n,func)
     implicit none
     integer,intent(in) :: n
     real               :: do_something(n+1)
     interface
       function func(x)
         implicit none
         real,intent(in) :: x(:)
         real            :: func(size(x))
       end function func
     end interface
     real                :: t(n+1)
     
     t = 1.0/(n+1)
     do_something = func(cos(t))/(n+1)
   end function do_something   
   
 end module mod_util

module module1
 implicit none
 contains
 
  function get_Am(Rn,N) result(Am_in)
    use mod_util,      only : do_something
    real,intent(in)          :: Rn(:)
    integer,intent(in)       :: N
    real                     :: Am_in(0:N)
    Am_in = 0.0
    Am_in = do_something(N,foo)
   
   contains
   
    function foo(x)
      real,intent(in)   :: x(:)
      real              :: foo(size(x))
      foo = 0.5*x*sum(Rn)
    end function foo
         
  end function  get_Am 

end module module1


program test
  use module1,    only : get_Am
  implicit none
  integer,parameter     :: N=5,NRn=2
  real                  :: Rn(0:NRn),Am(0:N)
 
  Rn = 0.1
  Am = get_Am(Rn,N)
  print *,' Am = ',Am

end program test



The problem appears to be that Rn isn't defined in foo, for reasons unknown to me. It seems to me that it is written according to the standard. If the sum(Rn) is commented out from foo, the program works. Any help on this matter would be greatly appreciated.

Thanks,
grgur
[/code]
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Dec 02, 2009 1:44 pm    Post subject: Reply with quote

Hi grgur,

In F2003, Internal procedures may only be called by their host. Hence it's illegal to pass "foo" to "do_something".

I came across the following post (http://software.intel.com/en-us/blogs/2009/09/02/doctor-fortran-in-think-thank-thunk/) where it appears that Intel added an extension which allow it.

Hope this helps,
Mat
Back to top
View user's profile
gtokic



Joined: 26 Jun 2007
Posts: 3

PostPosted: Wed Dec 02, 2009 4:44 pm    Post subject: Reply with quote

Hi Mat,

Thanks a lot for your hint. I wasn't aware that pgf90 would compile under F2003 standard. Was passing internal functions allowed under F95? If so, can some flags be specified to ensure f95 being used?

Thanks,
Grgur
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Dec 02, 2009 5:52 pm    Post subject: Reply with quote

Code:
Was passing internal functions allowed under F95?
Nope, the same restriction is in F95. I do believe that the restriction will be lifted in the next Fortran standard though.

- Mat
Back to top
View user's profile
gtokic



Joined: 26 Jun 2007
Posts: 3

PostPosted: Thu Dec 03, 2009 12:21 pm    Post subject: Reply with quote

Thanks Mat,

I better rewrite the code then. Thanks for all the info.

Grgur
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling 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 © phpBB Group