1 *CMZ : 26/02/96 11.38.47 by S.Ravndal
3 C------------------------------------------------------------------------
4 C SUBROUTINE gpreadrng( lunread, filename, ierr )
6 C Function: read a file containing a state of the pseudo random number
7 C generator on all the nodes and set the RNG seeds using it.
9 c A convention: if lunread is >= 0, use that unit.
10 c If not, read from the file called <filename>
12 C Possible error codes:
13 c ierr= -102 The number of seeds required for a subsequence of
14 c the RNG (numperseq) is more than allocated
15 c in the array iseedrng (SEEDS_PER_SEQ)
17 c called by: <USER> (if PARALLEL switch is used)
19 c Author: John Apostolakis, January 1996.
21 c Last Modified: February 22, 1996 J.A.
22 c------------------------------------------------------------------------
23 #if defined(CERNLIB_PARA)
24 subroutine gpreadrng( lunread, filename, ierr )
26 #if defined(CERNLIB_PARA_COMM)
27 #include "geant321/mpifinc.inc"
30 character filename*(*)
31 c Containes iseeda, iseedb, iseqnc
32 #include "geant321/multseeds.inc"
33 integer numprocs, nrank, nleader
34 integer MAXNODES, SEEDS_PER_SEQ
35 parameter (MAXNODES=4096)
37 parameter (SEEDS_PER_SEQ=103)
39 integer myseeds(SEEDS_PER_SEQ)
40 integer iseedrng( SEEDS_PER_SEQ, MAXNODES )
42 #include "geant321/gcunit.inc"
43 c version of the seed file format
44 real version, versionrd
45 integer nsubseq, numperseq, nperline, nsubseqexp, nsubseqrd
47 integer isubseq, inumb, imax, ino, ichkerr(4), iia, iseqrd
48 character*12 chSUBSEQ, chNOPERSEQ, chNPERLINE, chENDPROLOG,
49 $ chsubsequence , chVersion
50 character*12 chNameRng, chNameRead, chIdRng
55 if (lunread .lt. 0) then
56 lunrd= 74 !! Some number ...
57 open (unit=lunrd, file=filename, status='old')
62 c #if defined(CERNLIB_PARA_RANECU)
63 c if( ParaRng .eq. 'RANECU' )
64 c --------------------------------------------------------------------
65 c The RANECU pseudo random number generator, used by GEANT's GRNDM(Q).
66 c --------------------------------------------------------------------
67 #if !defined(CERNLIB_PARA_TASKRNG)
68 c Currently the number of sequences must be the number of processors!
69 call gprocs( numprocs, nrank, nleader )
72 if( numprocs .gt. MAXNODES )then
73 c write(lunerr, *) 'GPreadRng: ERROR Too many nodes ', numprocs
74 write(*, *) 'GPreadRng: ERROR Too many nodes ', numprocs
78 numperseq= 2 ! 2 "seed" integers per RANECU sequence
79 nperline= 2 ! 2 numbers per line
82 #if defined(CERNLIB_PARA_RANMAR)
85 read ( lunrd, 905 ) chVersion, versionrd
86 905 format( a8, f5.2, a )
87 write ( *, * ) ' Reading seedfile version ', version
89 read(lunrd, 910) chIdRng, chNameRead
91 read(lunrd, 920) chSUBSEQ, nsubseqrd
93 read(lunrd, 920) chNOPERSEQ, numperseq
94 read(lunrd, 920) chNPERLINE, nperline
95 read(lunrd, 930) chENDPROLOG
98 c Check that the strings before the values were correctly read in.
100 call checkstr( chSUBSEQ, 'SUBSEQ ', 7,
101 $ 'Number of subsequences ', ichkerr(1) )
102 call checkstr( chNOPERSEQ, 'NOPERSEQ ', 9,
103 $ ' Numbers per subsequence ', ichkerr(2) )
104 call checkstr( chNPERLINE, 'NPERLINE ', 9,
105 $ ' Numbers per line ', ichkerr(3) )
106 call checkstr( chENDPROLOG, 'ENDPROLOG', 9,
107 $ ' No variable to be read ', ichkerr(4) )
109 IF( ichkerr(iia) .ne. 0 ) then
110 write(*,*) ' GpReadRng : STOPping because of error ',
111 $ ' in reading overall header, part ', iia
116 C CHECK the VALUES read in
118 IF ( nsubseqexp .ne. nsubseqrd ) THEN
120 $ ' GpReadRng: Error: Mismatch in number of subsequences, ',
121 $ ' expected = ' , nsubseqexp, ' file = ', nsubseqrd
122 IF ( nsubseqexp .lt. nsubseqrd ) THEN
123 write(*,*) ' Enough seeds to work with, continuing '
126 write(*,*) ' Not enough subsequences, aborting '
133 c Now read in the values from each subsequence
135 DO isubseq= 1, nsubseq
136 read(lunrd, 970 ) chSubsequence, iseqrd
137 call checkstr( chSubsequence, ' Subsequence', 11,
138 $ ' Which of the Subsequences ', ichkerr(1) )
139 IF( (ichkerr(1).ne.0) .or. (iseqrd .ne. isubseq) ) then
140 write(*,*) ' GpReadRng : STOPping because of error ',
141 $ ' in reading subsequence header '
142 write(*,*) ' chSubsequence=/', chSubsequence, '/, iseqrd=',
143 $ iseqrd, ' iseq-expected= ', isubseq
146 DO inumb= 1, numperseq, nperline
147 imax=max(inumb+nperline-1,numperseq)
148 read( lunrd, 980 ) ( iseedrng( ino, isubseq ),
152 970 format( a14, i6 )
154 #if defined(CERNLIB_PARA_RANECU)
155 #if !defined(CERNLIB_PARA_TASKRNG)
157 #if defined(CERNLIB_PARA_COMM)
158 c Now "scatter" all seeds from node 0 to all the nodes
160 c if numperseq < SEEDS_PER_SEQ the following should still work.
162 call MPI_Scatter( iseedrng, SEEDS_PER_SEQ, MPI_INTEGER,
163 $ myseeds, numperseq, MPI_INTEGER,
164 $ 0, MPI_COMM_WORLD, ierr)
166 if ( ierr .gt. 0 ) then
167 write( lunerr, '(a,i,a)' ) 'GpDefRng: Error ', ierr,
171 c Else each node selects its seeds ...
173 DO inumb= 1, numperseq
174 myseeds( inumb )= iseedrng( inumb, nrank+1 )
178 c Set the pRNG seeds (In this version there is one sequence per node)
179 call grndmq( myseeds(1), myseeds(2), iseqnc, 'S' )
182 if (lunread .lt. 0) then
189 SUBROUTINE GPREADRNG_DUMMY