[4775] | 1 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 2 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 3 | !----------------------------------------------------------------------- |
---|
| 4 | ! CVS m_mpout.F90,v 1.6 2007-01-02 23:00:42 jacob Exp |
---|
| 5 | ! CVS MCT_2_8_0 |
---|
| 6 | !----------------------------------------------------------------------- |
---|
| 7 | !BOP |
---|
| 8 | ! |
---|
| 9 | ! !MODULE: m_mpout - a multiple but mergable parallel output module |
---|
| 10 | ! |
---|
| 11 | ! !DESCRIPTION: |
---|
| 12 | ! |
---|
| 13 | ! !INTERFACE: |
---|
| 14 | |
---|
| 15 | module m_mpout |
---|
| 16 | use m_stdio, only : stdout,LEN_FILENAME |
---|
| 17 | implicit none |
---|
| 18 | private ! except |
---|
| 19 | |
---|
| 20 | public :: mpout ! The file handle as a Fortran logical unit |
---|
| 21 | |
---|
| 22 | public :: mpout_open ! open the multiple output streams |
---|
| 23 | public :: mpout_close ! close the multiple output streams |
---|
| 24 | public :: mpout_sync ! sync. the multiple output streams |
---|
| 25 | public :: mpout_flush ! flush the multople output streams |
---|
| 26 | public :: mpout_ison ! verify if mpout is proper defined |
---|
| 27 | public :: mpout_log ! write a message to mpout |
---|
| 28 | |
---|
| 29 | interface mpout_open; module procedure open_; end interface |
---|
| 30 | interface mpout_close; module procedure close_; end interface |
---|
| 31 | interface mpout_sync; module procedure sync_; end interface |
---|
| 32 | interface mpout_flush; module procedure flush_; end interface |
---|
| 33 | interface mpout_ison; module procedure ison_; end interface |
---|
| 34 | interface mpout_log |
---|
| 35 | module procedure log1_ |
---|
| 36 | module procedure log2_ |
---|
| 37 | end interface |
---|
| 38 | |
---|
| 39 | ! !REVISION HISTORY: |
---|
| 40 | ! 25Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 41 | ! 28Sep99 - Jing Guo <guo@thunder> |
---|
| 42 | ! - Added additional calls to support the "Violet" system |
---|
| 43 | ! development. |
---|
| 44 | ! |
---|
| 45 | ! !DESIGN ISSUES: |
---|
| 46 | ! \begin{itemize} |
---|
| 47 | ! |
---|
| 48 | ! \item It might be considered useful to implement this module to be |
---|
| 49 | ! applicable to a given {\sl communicator}. The argument |
---|
| 50 | ! taken now is to only have one multiple output stream handle |
---|
| 51 | ! per excution. This is consistent with \verb"stdout" in the |
---|
| 52 | ! traditional sense. (Jing Guo, 25Feb98) |
---|
| 53 | ! |
---|
| 54 | ! \item \verb"mpout_log()" is implemented in a way producing output |
---|
| 55 | ! only if \verb"mpout_ison()" (being \verb".true."). The reason |
---|
| 56 | ! of not implementing a default output such as \verb"stdout", is |
---|
| 57 | ! hoping to provent too many unexpected output when the system is |
---|
| 58 | ! switched to a multiple PE system. The design principle for |
---|
| 59 | ! this module is that \verb"mpout" is basically {\sl not} the same |
---|
| 60 | ! module as \verb"stdout". (Jing Guo, 28Sep99) |
---|
| 61 | ! |
---|
| 62 | ! \end{itemize} |
---|
| 63 | !EOP |
---|
| 64 | !_______________________________________________________________________ |
---|
| 65 | character(len=*),parameter :: myname='MCT(MPEU)::m_mpout' |
---|
| 66 | |
---|
| 67 | character(len=*),parameter :: def_pfix='mpout' |
---|
| 68 | |
---|
| 69 | integer,save :: isec=-1 |
---|
| 70 | integer,save :: mpout=stdout |
---|
| 71 | logical,save :: mpout_set=.false. |
---|
| 72 | character(len=LEN_FILENAME-4),save :: upfix=def_pfix |
---|
| 73 | integer,parameter :: mpout_MASK=3 ! every four PEs |
---|
| 74 | |
---|
| 75 | contains |
---|
| 76 | |
---|
| 77 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 78 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 79 | !----------------------------------------------------------------------- |
---|
| 80 | !BOP |
---|
| 81 | ! |
---|
| 82 | ! !IROUTINE: open_ - open a multiple files with the same name prefix |
---|
| 83 | ! |
---|
| 84 | ! !DESCRIPTION: |
---|
| 85 | ! |
---|
| 86 | ! !INTERFACE: |
---|
| 87 | |
---|
| 88 | subroutine open_(mask,pfix) |
---|
| 89 | use m_stdio, only : stderr,stdout |
---|
| 90 | use m_ioutil, only : luavail,opntext |
---|
| 91 | use m_dropdead, only : die |
---|
| 92 | use m_mpif90, only : MP_comm_WORLD |
---|
| 93 | use m_mpif90, only : MP_comm_rank |
---|
| 94 | use m_mpif90, only : MP_perr |
---|
| 95 | implicit none |
---|
| 96 | integer,optional,intent(in) :: mask |
---|
| 97 | character(len=*),optional,intent(in) :: pfix |
---|
| 98 | |
---|
| 99 | ! !EXAMPLES: |
---|
| 100 | ! |
---|
| 101 | ! Examples of using mpout_MASK or mask: |
---|
| 102 | ! |
---|
| 103 | ! If the mask has all "1" in every bit, there will be no output |
---|
| 104 | ! on every PE, except the PE of rank 0. |
---|
| 105 | ! |
---|
| 106 | ! If the mask is 3 or "11"b, any PE of rank with any "dirty" bit |
---|
| 107 | ! in its rank value will not have output. |
---|
| 108 | ! |
---|
| 109 | ! !REVISION HISTORY: |
---|
| 110 | ! 25Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 111 | !EOP |
---|
| 112 | !_______________________________________________________________________ |
---|
| 113 | character(len=*),parameter :: myname_=myname//'::open_' |
---|
| 114 | integer :: lu |
---|
| 115 | character(len=4) :: sfix |
---|
| 116 | integer :: irank |
---|
| 117 | integer :: ier |
---|
| 118 | integer :: umask |
---|
| 119 | |
---|
| 120 | ! Set the filename prefix |
---|
| 121 | |
---|
| 122 | upfix=def_pfix |
---|
| 123 | if(present(pfix)) upfix=pfix |
---|
| 124 | |
---|
| 125 | ! Set the mask of the PEs with mpout |
---|
| 126 | |
---|
| 127 | umask=mpout_MASK |
---|
| 128 | if(present(mask)) umask=mask |
---|
| 129 | |
---|
| 130 | ! If a check is not in place, sent the outputs to stdout |
---|
| 131 | |
---|
| 132 | mpout=stdout |
---|
| 133 | mpout_set=.false. |
---|
| 134 | |
---|
| 135 | call MP_comm_rank(MP_comm_world,irank,ier) |
---|
| 136 | if(ier /= 0) then |
---|
| 137 | call MP_perr(myname_,'MP_comm_rank()',ier) |
---|
| 138 | call die(myname_) |
---|
| 139 | endif |
---|
| 140 | |
---|
| 141 | if(iand(irank,umask) == 0) then |
---|
| 142 | |
---|
| 143 | lu=luavail() |
---|
| 144 | if(lu > 0) mpout=lu |
---|
| 145 | |
---|
| 146 | write(sfix,'(a,z3.3)') '.',irank |
---|
| 147 | call opntext(mpout,trim(upfix)//sfix,'unknown',ier) |
---|
| 148 | if(ier /= 0) then |
---|
| 149 | write(stderr,'(4a,i4)') myname_, & |
---|
| 150 | ': opntext("',trim(upfix)//sfix,'") error, ier =',ier |
---|
| 151 | call die(myname_) |
---|
| 152 | endif |
---|
| 153 | |
---|
| 154 | mpout_set=.true. |
---|
| 155 | |
---|
| 156 | isec=0 |
---|
| 157 | write(mpout,'(a,z8.8,2a)') '.BEGIN. ',isec,' ',trim(upfix) |
---|
| 158 | endif |
---|
| 159 | |
---|
| 160 | end subroutine open_ |
---|
| 161 | |
---|
| 162 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 163 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 164 | !----------------------------------------------------------------------- |
---|
| 165 | !BOP |
---|
| 166 | ! |
---|
| 167 | ! !IROUTINE: close_ - close the unit opened by open_ |
---|
| 168 | ! |
---|
| 169 | ! !DESCRIPTION: |
---|
| 170 | ! |
---|
| 171 | ! !INTERFACE: |
---|
| 172 | |
---|
| 173 | subroutine close_() |
---|
| 174 | use m_stdio, only : stderr |
---|
| 175 | use m_ioutil, only : clstext, luflush |
---|
| 176 | use m_dropdead, only : die |
---|
| 177 | implicit none |
---|
| 178 | |
---|
| 179 | ! !REVISION HISTORY: |
---|
| 180 | ! 25Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 181 | !EOP |
---|
| 182 | !_______________________________________________________________________ |
---|
| 183 | character(len=*),parameter :: myname_=myname//'::close_' |
---|
| 184 | integer :: ier |
---|
| 185 | |
---|
| 186 | if(mpout_set) then |
---|
| 187 | call luflush(mpout) |
---|
| 188 | |
---|
| 189 | isec=isec+1 |
---|
| 190 | write(mpout,'(a,z8.8,2a)') '.END. ',isec,' ',trim(upfix) |
---|
| 191 | endfile(mpout) |
---|
| 192 | |
---|
| 193 | call clstext(mpout,ier) |
---|
| 194 | if(ier /= 0) then |
---|
| 195 | write(stderr,'(2a,i3.3,a,i4)') myname_, & |
---|
| 196 | ': clstext("',mpout,'") error, ier =',ier |
---|
| 197 | call die(myname_) |
---|
| 198 | endif |
---|
| 199 | mpout=stdout |
---|
| 200 | mpout_set=.false. |
---|
| 201 | endif |
---|
| 202 | |
---|
| 203 | isec=-1 |
---|
| 204 | |
---|
| 205 | end subroutine close_ |
---|
| 206 | |
---|
| 207 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 208 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 209 | !----------------------------------------------------------------------- |
---|
| 210 | !BOP |
---|
| 211 | ! |
---|
| 212 | ! !IROUTINE: sync_ - write a mark for posible later file merging |
---|
| 213 | ! |
---|
| 214 | ! !DESCRIPTION: |
---|
| 215 | ! |
---|
| 216 | ! !INTERFACE: |
---|
| 217 | |
---|
| 218 | subroutine sync_(tag) |
---|
| 219 | use m_stdio, only : stderr |
---|
| 220 | use m_dropdead, only : die |
---|
| 221 | implicit none |
---|
| 222 | character(len=*),intent(in) :: tag |
---|
| 223 | |
---|
| 224 | ! !REVISION HISTORY: |
---|
| 225 | ! 25Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 226 | ! |
---|
| 227 | ! !DESIGN ISSUES: |
---|
| 228 | ! \begin{itemize} |
---|
| 229 | ! |
---|
| 230 | ! \item Should the variable \verb"tag" be implemented as an optional |
---|
| 231 | ! argument? Because the current implementation does not require |
---|
| 232 | ! actual synchronization between all threads of the multiple |
---|
| 233 | ! output streams, forcing the user to supply a unique \verb"tag" |
---|
| 234 | ! would make the final multi-stream merging verifiable. However, |
---|
| 235 | ! since the \verb"tag"s have not been forced to be unique, the |
---|
| 236 | ! synchronization operations are still symbolic. |
---|
| 237 | ! |
---|
| 238 | ! \{itemize} |
---|
| 239 | !EOP |
---|
| 240 | !_______________________________________________________________________ |
---|
| 241 | character(len=*),parameter :: myname_=myname//'::sync_' |
---|
| 242 | |
---|
| 243 | if(mpout_set) then |
---|
| 244 | isec=isec+1 |
---|
| 245 | write(mpout,'(a,z8.8,2a)') '.SYNC. ',isec,' ',trim(tag) |
---|
| 246 | endif |
---|
| 247 | |
---|
| 248 | end subroutine sync_ |
---|
| 249 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 250 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 251 | !----------------------------------------------------------------------- |
---|
| 252 | !BOP |
---|
| 253 | ! |
---|
| 254 | ! !IROUTINE: flush_ - flush the multiple output streams |
---|
| 255 | ! |
---|
| 256 | ! !DESCRIPTION: |
---|
| 257 | ! |
---|
| 258 | ! !INTERFACE: |
---|
| 259 | |
---|
| 260 | subroutine flush_() |
---|
| 261 | use m_stdio, only : stderr |
---|
| 262 | use m_ioutil, only : luflush |
---|
| 263 | use m_dropdead, only : die |
---|
| 264 | implicit none |
---|
| 265 | |
---|
| 266 | ! !REVISION HISTORY: |
---|
| 267 | ! 27Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code |
---|
| 268 | !EOP |
---|
| 269 | !_______________________________________________________________________ |
---|
| 270 | character(len=*),parameter :: myname_=myname//'::flush_' |
---|
| 271 | |
---|
| 272 | if(mpout_set) call luflush(mpout) |
---|
| 273 | |
---|
| 274 | end subroutine flush_ |
---|
| 275 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 276 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 277 | !BOP ------------------------------------------------------------------- |
---|
| 278 | ! |
---|
| 279 | ! !IROUTINE: ison_ - decide if the current PE has a defined mpout |
---|
| 280 | ! |
---|
| 281 | ! !DESCRIPTION: |
---|
| 282 | ! |
---|
| 283 | ! It needs to be checked to avoid undesired output. |
---|
| 284 | ! |
---|
| 285 | ! !INTERFACE: |
---|
| 286 | |
---|
| 287 | function ison_() |
---|
| 288 | implicit none |
---|
| 289 | logical :: ison_ |
---|
| 290 | |
---|
| 291 | ! !REVISION HISTORY: |
---|
| 292 | ! 14Sep99 - Jing Guo <guo@dao.gsfc.nasa.gov> |
---|
| 293 | ! - initial prototype/prolog/code |
---|
| 294 | !EOP ___________________________________________________________________ |
---|
| 295 | |
---|
| 296 | character(len=*),parameter :: myname_=myname//'::ison_' |
---|
| 297 | |
---|
| 298 | ison_=mpout_set |
---|
| 299 | |
---|
| 300 | end function ison_ |
---|
| 301 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 302 | ! ANL/MCS Mathematics and Computer Science Division ! |
---|
| 303 | !BOP ------------------------------------------------------------------- |
---|
| 304 | ! |
---|
| 305 | ! !IROUTINE: log1_ - write a message to mpout |
---|
| 306 | ! |
---|
| 307 | ! !DESCRIPTION: |
---|
| 308 | ! |
---|
| 309 | ! !INTERFACE: |
---|
| 310 | |
---|
| 311 | subroutine log1_(message) |
---|
| 312 | implicit none |
---|
| 313 | character(len=*),intent(in) :: message |
---|
| 314 | |
---|
| 315 | ! !REVISION HISTORY: |
---|
| 316 | ! 07Jan02 - R. Jacob (jacob@mcs.anl.gov) |
---|
| 317 | ! - based on log2_. |
---|
| 318 | !EOP ___________________________________________________________________ |
---|
| 319 | |
---|
| 320 | character(len=*),parameter :: myname_=myname//'::log1_' |
---|
| 321 | |
---|
| 322 | if(mpout_set) write(mpout,'(3a)') message |
---|
| 323 | |
---|
| 324 | end subroutine log1_ |
---|
| 325 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 326 | ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS ! |
---|
| 327 | !BOP ------------------------------------------------------------------- |
---|
| 328 | ! |
---|
| 329 | ! !IROUTINE: log2_ - write a message to mpout with a where |
---|
| 330 | ! |
---|
| 331 | ! !DESCRIPTION: |
---|
| 332 | ! |
---|
| 333 | ! !INTERFACE: |
---|
| 334 | |
---|
| 335 | subroutine log2_(where,message) |
---|
| 336 | implicit none |
---|
| 337 | character(len=*),intent(in) :: where |
---|
| 338 | character(len=*),intent(in) :: message |
---|
| 339 | |
---|
| 340 | ! !REVISION HISTORY: |
---|
| 341 | ! 14Sep99 - Jing Guo <guo@dao.gsfc.nasa.gov> |
---|
| 342 | ! - initial prototype/prolog/code |
---|
| 343 | ! 07Jan02 - R. Jacob (jacob@mcs.anl.gov) |
---|
| 344 | ! - change name to log2_ |
---|
| 345 | !EOP ___________________________________________________________________ |
---|
| 346 | |
---|
| 347 | character(len=*),parameter :: myname_=myname//'::log2_' |
---|
| 348 | |
---|
| 349 | if(mpout_set) write(mpout,'(3a)') where,': ',message |
---|
| 350 | |
---|
| 351 | end subroutine log2_ |
---|
| 352 | end module m_mpout |
---|
| 353 | !. |
---|