PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Accessing 3F routine rand in pgf77?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
dshelly



Joined: 08 Aug 2004
Posts: 3

PostPosted: Thu Feb 02, 2006 4:15 pm    Post subject: Accessing 3F routine rand in pgf77? Reply with quote

Hi,

I'm using pgf77 5.2-1 x86-64 on a linux AMD opteron system. I'm trying to access the function "rand", which according to the manual is a "3F subroutine". Supposedly, these functions are "automatically loaded from the PGI's Fortran run-time library if referenced by a Fortran program." However, when try to compile a program (testrand.f) containing rand, I get:

PGFTN-S-0038-Symbol, rand, has not been explicitly declared (testrand.f: 8)

How can I get it to "see" the rand function?

Thanks very much!
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Feb 02, 2006 4:39 pm    Post subject: Reply with quote

Hi dshelly,

How are you calling rand? It should be something like:

Code:
% cat testrand.f

        call srand(1)
        x = rand()
        print *, x
        x = rand()
        print *, x
        end
% pgf77 testrand.f
% a.out
  -1.0224130E-27
   3.9686591E+35


Granted, I'm using the 6.1 compiler, but I don't think this has changed since 5.2.

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



Joined: 08 Aug 2004
Posts: 3

PostPosted: Thu Feb 02, 2006 5:56 pm    Post subject: Reply with quote

Hi,

Isn't rand supposed to generate a number between 0 and 1???

Here's my test code:
________________________
program testrand

implicit none

integer i

do i=1,20
print*,'rand(0)',rand(0)
enddo

end
_______________________

If I remove the "implicit none" then it compiles and gives me the wild numbers like in the above example, as it seems to be accessing an unitialized "variable". G77 outputs values between 0 and 1 as expected.

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



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

PostPosted: Fri Feb 03, 2006 9:50 am    Post subject: Reply with quote

Hi David,

Ooops, yes your right. I forgot to declare 'x' and 'rand' as a double precision so they implicitly get defined as a REALs thus changing the value. In your case, the error "rand, has not been explicitly declared" is because you also need to declare 'rand' as a double precision. Example:
Code:
% cat testrand.f
      program testrand

      implicit none
      integer i
      double precision rand

      do i=1,20
        print *,'rand(0)', rand(0)
      enddo

      end

% pgf77 testrand.f
% a.out
 rand(0)  3.9079850466805510E-014
 rand(0)  9.8539467465030839E-004
 rand(0)  4.1631001594613082E-002
 rand(0)  0.1766426425429160
 rand(0)  0.3646022483906073
 rand(0)  9.1330612112294318E-002
 rand(0)  9.2297647698675434E-002
 rand(0)  0.4872172239468284
 rand(0)  0.5267502797621084
 rand(0)  0.4544334237382444
 rand(0)  0.2331784335639391
 rand(0)  0.8312917879809874
 rand(0)  0.9317314819799343
 rand(0)  0.5680596127871453
 rand(0)  0.5560943324712504
 rand(0)  5.0831914251432408E-002
 rand(0)  0.7670511597301406
 rand(0)  1.8914803475844622E-002
 rand(0)  0.2523597619584059
 rand(0)  0.2981971733712072


Sorry I missed this in your first post.

- Mat
Back to top
View user's profile
dshelly



Joined: 08 Aug 2004
Posts: 3

PostPosted: Fri Feb 03, 2006 11:26 am    Post subject: Reply with quote

Ok, thanks - seems to work right now. I guess this arises from rand being double-precision in pgf77 but real in g77? Current test code produces an error in g77. Is there an easy way to make it work right in both?

thanks,
David
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
Goto page 1, 2  Next
Page 1 of 2

 
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