To: J3 J3/14-184r4 From: David Muxworthy & Steve Lionel Subject: UK proposal UK-22 RANDOM_NUMBER intrinsic Date: 2014 June 27 Status: For Consideration Basic Functionality: Independent random number generators Rationale: In N2013, Van Snyder says: "It is processor dependent whether common or independent random number generators are used, and there's no way to detect which is the situation. Therefore taking action using one assumption or the other (e.g., calling or not calling RANDOM_SEED on each image with a hopefully-different value, maybe dependent on the image number) might be the wrong thing to do. It is preferable to provide a named constant in ISO_FORTRAN_ENV to indicate whether the processor uses a common random number generator on all images, or intrinsic procedures so to inquire or specify. References to the intrinsic subroutine that specifies whether common or independent random number generators are used should be image control statements. 13.5p4 should be adjusted so that the segment ordering requirement applies only if a common random number generator is used." Initial proposals to solve this problem by modifying the definition of calls to RANDOM_SEED without arguments were deemed unacceptable as it could result in the introduction of non-reproducibility to existing applications, even though the current standard says that such calls have processor-dependent behavior. This proposal introduces a new intrinsic subroutine RANDOM_INIT to specify the initial state of the random number generator without affecting existing codes. Specification: A new intrinsic subroutine RANDOM_INIT establishes the initial state of the pseudorandom number generator used by RANDOM_NUMBER. Syntax: Add new intrinsic procedure RANDOM_INIT. Edits to J3/14-007r1(= N2014): [xviii] Add to Introduction > Intrinsic procedures and modules, the sentence: "The new intrinsic subroutine RANDOM_INIT establishes the initial state of the pseudorandom number generator used by RANDOM_NUMBER." [324] In 13.5 Standard generic intrinsic procedures, Table 13.1, after the entry for RADIX add: "RANDOM_INIT (REPEATABLE, IMAGE_DISTINCT) S Initialize pseudorandom number generator". [325:4] Replace "If RANDOM SEED is called in a segment A, and either RANDOM SEED" with "If RANDOM_INIT or RANDOM_SEED is called in a segment A, and one of RANDOM_INIT, RANDOM_SEED,". [381:18+] In 13.7 Specifications of the standard intrinsic procedures, after the specification of RADIX, add: 13.7.134a RANDOM_INIT ( REPEATABLE, IMAGE_DISTINCT ) <> Initialize pseudorandom number generator <> Subroutine <> REPEATABLE shall be a logical scalar. It is an INTENT(IN) argument. If it has the value true, the seed value accessed by the pseudorandom number generator is set to a processor-dependent value that is the same each time RANDOM_INIT is called from the same image. If it has the value false, the seed is set to a processor-dependent, unpredictably different value on each call. IMAGE_DISTINCT shall be a logical scalar. It is an INTENT(IN) argument. If it has the value true, the seed value accessed by the pseudorandom number generator is set to a processor-dependent value that is distinct from the value set by calls to RANDOM_INIT in other images of the program. If it has the value false, the processor-dependent seed value set is not dependent on which image calls RANDOM_INIT. <> The following code initializes the pseudorandom number generator so that the seed is different on each call and that other images use distinct seeds: CALL RANDOM_INIT (REPEATABLE=.FALSE., IMAGE_DISTINCT=.TRUE.)