PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

parameter used to specify kind in function definition fails

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



Joined: 24 Apr 2006
Posts: 2

PostPosted: Mon Apr 24, 2006 8:10 pm    Post subject: parameter used to specify kind in function definition fails Reply with quote

This code

program testcode

integer, parameter :: rl = 8

real(rl) mumble
mumble = blah(4.4)

stop
end

real(rl) function blah(x)
blah = 4.4
stop
end

fails to compile with PG version 6.1 on Fedora Core 4

pgf90 testcode.f -o testcode

with the following error message:

PGF90-S-0087-Non-constant expression where constant expression required (testcode.f: 11)
PGF90-S-0081-Illegal selector - KIND parameter has unknown value for data type (testcode.f: 11)
0 inform, 0 warnings, 2 severes, 0 fatal for blah

Which, at the very least, is a poor error message since clearly rl is a constant.

I'm not a Fortran90 programmer and the PG Fortran Reference manual doesn't specify what type-spec can be in a function definition but it seems like if variable definitions allow parameters to be used then function definitions ought to allow it.
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Apr 27, 2006 5:12 pm    Post subject: Reply with quote

Hi jdk,

You are correct that the first "rl" is constant, however it's scope is only within the main subroutine testcode. The second "rl" which you use in the blah function's prefix is in a different scope and hence is implicitly declared as a real variable, not a constant. In order for "rl" be in blah's scope, you need to have blah contained within testcode.

Example:
Code:

program testcode
  implicit none
  integer, parameter :: rl = 8
  real(rl) mumble
  mumble = blah(4.4_rl)
  print *, mumble
  stop

contains
  real(rl) function blah(x)
    real(rl) x
    blah = x
  end function blah

end program testcode


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



Joined: 24 Apr 2006
Posts: 2

PostPosted: Sun Apr 30, 2006 4:25 pm    Post subject: Reply with quote

Thanks for the clarification...I see now that the mistake in my example is just a programming error and it makes sense to me.

I was attempting to boil down the problem I was having with another code into an example appropriate for reporting. I will check to see if there is a similar problem in that code.

In the actual code (zeusmp), the parameter is declared in a module which is used to contain program-wide definitions. The parameter definition seems to work for variable declarations in files which use the module but not for function declarations.

For now I just replaced rl in the function definitions with the actual value which allowed the code to compile and run.
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 © phpBB Group