1 *CMZ : 08/23/94 15.20.00 by John Apostolakis CERN GP-MIMD 2
2 *FCA : 05/01/99 08:37:02 by Federico Carminati
3 * Inverted the position of #endif and END so the
4 * routine can be compiled even with the CERNLIB_PARA
7 subroutine GPSUMHR( idh, file, chopt )
9 c Saves histograms into a single RZ file, putting each
10 c process' histogram into a subdirectory, as well as saving the
11 c running total in the subdirectory 'totals'. At the end the
12 c directory 'totals' will contain the sum total of all
13 c contributions from all processes.
15 c ( A 'replacement' for hrput for parallel Geant.)
17 c. Implementation notes:
19 c. Currently chopt is ignored!
21 c-------------------------------------------------------------------------
22 #if defined(CERNLIB_PARA)
25 CHARACTER*(*) file, chopt
29 #include "geant321/mpifinc.inc"
30 #include "geant321/multiprox.inc"
32 INTEGER istat, icycle, lunhist
34 integer iquest(100), nrec, itag
35 integer npstat(MPI_STATUS_SIZE), ierr
36 integer idebgsvh, npnext, nfirst, indivout
45 c----------------------------------------------------------------------
46 c J. Apostolakis: Use a directory for each process and a
47 c a directory called 'totals' for totals,
48 c v0.1 February 9, 1994 using mvlock/mvunlock
49 c v0.2 August 4, 1994 using mpi_{send,recv}
51 c Node 0 creates the file, others wait their turn (a message goes
52 c around that each node receives, does its stuff and sends on)
53 c [ Older idea was to use a barrier: call mpi_barrier( MPI_COMM_WORLD ) ]
56 c x The current scheme is not robust, but has worked well.
57 c x The potential problem is if one node fails before getting to
58 c x this point or during its call to gpsumhr. The former could be
59 c x handled by replacing the current method with a robust scheme
60 c x capable of handling node failures, by using lockf/unlockf to
63 c x For file creation, having all nodes try to create a new hbook
64 c x file will not work, since one will overwrite another ...
66 if( nprank .eq. nfirst ) then
73 c Wait here until the previous node is finished !
75 call mpi_recv( istat, 1, MPI_INTEGER,
76 & nprank-1, itag, MPI_COMM_WORLD, npstat, ierr )
79 CALL HROPEN ( LUNHIST, 'OUTPUT', file, filemode, nrec, istat)
82 print *, ' HROPEN of ', file, ' on node ', nprank,
83 & ' failed in gpsumhr. Istat = ', istat
85 print *, ' HROPEN of ', file, ' on node ', nprank,
86 & ' succeeded and gave nrec=', nrec
90 if( myid.ge.10000 ) then
91 print *, 'Warning in gpsumhr: The id (',myid,
92 & ')is too big to be used in gpsumhr.f'
93 myid = mod(myid, 10000)
95 write (myname, '(a7,i6)') 'process',myid+10000
98 if( idebgsvh .eq. 1 ) then
99 call hldir ( '//PAWC', ' ' )
100 call hldir ( '//OUTPUT', 't' )
103 call hcdir ( '//OUTPUT', ' ' )
105 c Could make 'indivout' an option: it creates subdirectories with
106 c each node's output.
107 if( indivout .eq. 1 ) then
108 call hmdir ( myname, ' ' )
109 call hcdir ( myname, ' ' ) ! if it has been created already ...
110 CALL HROUT ( idh, icycle,' ')
113 if( nprank .eq. nfirst ) then
114 call hmdir ( '//OUTPUT/TOTALS','S')
116 call hcdir ( '//OUTPUT/TOTALS',' ')
117 CALL HRIN ( idh, 888888, 99999)
119 c ! 99999 is an undocumented feature => it adds
120 c the histograms to the ones in memory
121 c ------------------------------------------------------------------
122 call hrout ( idh, icycle, 'T')
124 CALL HREND ('OUTPUT')
127 c Send a message to the next node, which is waiting until this one
131 if ( npnext .ge. npsize ) npnext = npnext - npsize
132 call mpi_send( istat, 1, MPI_INTEGER,
133 & npnext, itag, MPI_COMM_WORLD, ierr )
136 c Finally have the first node receive the last node's message!
138 if( nprank .eq. nfirst ) then
139 call mpi_recv( istat, 1, MPI_INTEGER,
140 & npsize-1, itag, MPI_COMM_WORLD, npstat, ierr )
142 c-----------------------------------------------------------------------