|
| View previous topic :: View next topic |
| Author |
Message |
gtokic
Joined: 26 Jun 2007 Posts: 3
|
Posted: Wed Dec 02, 2009 2:39 am Post subject: Segmentation error when passing functions as arguments |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 5001 Location: The Portland Group Inc.
|
|
| Back to top |
|
 |
gtokic
Joined: 26 Jun 2007 Posts: 3
|
Posted: Wed Dec 02, 2009 4:44 pm Post subject: |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 5001 Location: The Portland Group Inc.
|
Posted: Wed Dec 02, 2009 5:52 pm Post subject: |
|
|
| 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 |
|
 |
gtokic
Joined: 26 Jun 2007 Posts: 3
|
Posted: Thu Dec 03, 2009 12:21 pm Post subject: |
|
|
Thanks Mat,
I better rewrite the code then. Thanks for all the info.
Grgur |
|
| Back to top |
|
 |
|
|
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
|