Software Archive
Read-only legacy content
17060 Discussions

A 4 line program that crashes ! ! !

WSinc
New Contributor I
327 Views
program MAIN
z1=seed(2311)
z2=random(0)
end

I took an existing program and stripped it down to illustrate this problem with the run-time library, particularly the random number generator. It appears that I am using it exactly as they say in the writeup. It crashes with a run-time exception, perhaps an out-of bounds access.

How do I know if the version of the RTL I'm using is compatible with the compiler version? Does it check that before starting execution?
0 Kudos
5 Replies
Steven_L_Intel1
Employee
327 Views
The problem is that you passed a constant to RANDOM - its argument is an output argument and you got an access violation when RANDOM tried to store to it. Please read the documentation more closely. You should also have a USE DFLIB in there.

I would suggest instead the Fortran standard RANDOM_NUMBER intrinsic.

As for RTL compatibility - if the RTL is incompatible, you'll either get a link error or a run-time error "invalid argument to run-time library". That isn't the case here.

Steve
0 Kudos
WSinc
New Contributor I
327 Views
Dear Steve;

I used documentation that was on my CD-ROM. Here is what it says in the A to Z section under the letter R.
====================================================
RAND, RANDOM
Portability Functions: Return real random numbers in the range 0.0 through 1.0.

Module: USE DFLIB

Syntax

result = RAND ([ iflag ])
result = RANDOM (iflag)

iflag
(Input) INTEGER(4). Optional for RAND. Controls the way the random number is selected.

Results:

The result type is REAL(4). RAND and RANDOM return random numbers in the range 0.0 through 1.0.

Value of iflag Selection process
1 The generator is restarted and the first random value is selected.
0 The next random number in the sequence is selected.
Otherwise The generator is reseeded using iflag, restarted, and the first random value is selected.

When RAND is called without an argument, iflag is assumed
====================================================
According to what they say above, these are supposed to be used as function calls. I can try to make the changes you suggested, but I was still curious as to why the documentation appears to be wrong.
0 Kudos
Steven_L_Intel1
Employee
327 Views
There are two different RANDOM routines. The documentation you're looking at is for the one in the Portability Library - the one I described is in the "default" library. The documentation does say:

"Note: Because Visual Fortran offers an intrinsic subroutine also called RANDOM in the default library, the only way to access this portability function is with the USE DFPORT statement. Without it, you can only access the default subroutine. "

but I note that the page says USE DFLIB at the top, which is wrong - it should be USE DFPORT. I'll let the writers know about this.

Steve
0 Kudos
WSinc
New Contributor I
327 Views
OK, but I sincerely was not aware you had two different libraries.
I take it that the portability library is for other companies or older versions of FORTRAN.

Where would I find a discussion about that, in case this comes up again?
The search on HELP did not give me anything.
0 Kudos
Steven_L_Intel1
Employee
327 Views
I suggest you look through the Programmer's Guide. There's an entire chapter devoted to the Portability Library, which is mostly meant for people coming from UNIX.

Steve
0 Kudos
Reply