Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

Calling to RANDOM_NUMBER() from an ELEMENTAL FUNCTION

jorjani
Beginner
528 Views
Hi there,
For a while ago there were some posts about the RANDOM_NUMBER being a PURE procedure or not and so on. I wonder if there been any developments lately in this area or if somebody can give me an advice on the following:
I have the following simple code:
PROGRAM something
REAL :: a(10)
PRINT*, rd(a)
CONTAINS
ELEMENTAL FUNCTION rd(x) result(y)
REAL, INTENT(IN) :: x
REAL :: y
CALL RANDOM_NUMBER(y)
END FUNCTION
END PROGRAM something
And as you can guess my CVF6.6c tells me "Hit the road, Jack".
But the same code works in Lahey.
Can I make this work in CVF6.6c and if the answer is "yes", then how?
Best regards ... Hossein
0 Kudos
1 Reply
Steven_L_Intel1
Employee
528 Views
Nothing has changed - RANDOM_NUMBER, like all of the intrinsic subroutines other than MVBITS, is not PURE. The Lahey compiler you are using is simply not detecting this; earlier versions of CVF didn't either.

The definition of a PURE routine excludes side-effects and requires that every call with the same arguments return the same result. RANDOM_NUMBER fails on both counts.

You can cheat if you want - declare an explicit interface to MY_RANDOM_NUMBER that declares it as PURE, then write an external routine MY_RANDOM_NUMBER that calls RANDOM_NUMBER. But don't complain here if the compiler decides to do an optimization that is valid on PURE routines but not non-PURE routines.
0 Kudos
Reply