SCALE-RM
scale_comm_ensemble.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
10 !-------------------------------------------------------------------------------
11 #include "scalelib.h"
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use mpi
18  use scale_precision
19  use scale_io
20  use scale_prof
21  !-----------------------------------------------------------------------------
22  implicit none
23  private
24  !-----------------------------------------------------------------------------
25  !
26  !++ Public procedure
27  !
28  public :: comm_ensemble_setup
29  public :: comm_ensemble_finalize
30 
31  !-----------------------------------------------------------------------------
32  !
33  !++ Public parameters & variables
34  !
35  integer, public :: comm_ensemble_world
36  integer, public :: comm_ensemble_myrank
37  integer, public :: comm_ensemble_nprocs
38 
39  !-----------------------------------------------------------------------------
40  !
41  !++ Private procedure
42  !
43  !-----------------------------------------------------------------------------
44  !
45  !++ Private parameters & variables
46  !
47  !-----------------------------------------------------------------------------
48 contains
49  !-----------------------------------------------------------------------------
51  subroutine comm_ensemble_setup
52  use scale_prc, only: &
57  prc_nprocs, &
58  prc_myrank, &
59  prc_abort
60  implicit none
61 
62  integer, allocatable :: ensemble2color(:)
63  integer, allocatable :: ensemble2key (:)
64 
65  integer :: n
66  integer :: myrank, nprocs
67  integer :: ierr
68  !---------------------------------------------------------------------------
69 
70  log_newline
71  log_info("COMM_ENSEMBLE_setup",*) 'Setup'
72 
73  !!--- read namelist
74  !rewind(IO_FID_CONF)
75  !read(IO_FID_CONF,nml=PARAM_COMM_ENSEMBLE,iostat=ierr)
76  !if( ierr < 0 ) then !--- missing
77  ! LOG_INFO("COMM_ENSEMBLE_setup",*) 'Not found namelist. Default used.'
78  !elseif( ierr > 0 ) then !--- fatal error
79  ! LOG_ERROR("COMM_ENSEMBLE_setup",*) 'Not appropriate names in namelist PARAM_COMM_ENSEMBLE. Check!'
80  ! call PRC_abort
81  !endif
82  !LOG_NML(PARAM_COMM_ENSEMBLE)
83 
84  ! [global] -> [ensemble]
85  if( prc_global_nprocs < 2 ) then
86  log_error("COMM_ENSEMBLE_setup",*) 'PRC_GLOBAL_nprocs must be greater than or equal to 2:', prc_global_nprocs
87  call prc_abort
88  end if
89 
90  allocate( ensemble2color(0:prc_global_nprocs-1) )
91  allocate( ensemble2key(0:prc_global_nprocs-1) )
92 
93  do n = 0, prc_global_nprocs-1
94  ensemble2color(n) = n
95  ensemble2key(n) = n
96  end do
97 
98  call mpi_comm_split( prc_universal_comm_world, & ! [IN]
99  ensemble2color(prc_global_myrank), & ! [IN]
100  ensemble2key(prc_global_myrank), & ! [IN]
101  comm_ensemble_world, & ! [OUT]
102  ierr ) ! [OUT]
103 
104  call mpi_comm_rank( comm_ensemble_world, comm_ensemble_myrank, ierr )
105  call mpi_comm_size( comm_ensemble_world, comm_ensemble_nprocs, ierr )
106 
107  deallocate( ensemble2color )
108  deallocate( ensemble2key )
109 
110  return
111  end subroutine comm_ensemble_setup
112 
113  !-----------------------------------------------------------------------------
115  subroutine comm_ensemble_finalize
116  implicit none
117 
118  integer :: ierr
119  !---------------------------------------------------------------------------
120 
121  call mpi_comm_free( comm_ensemble_world, ierr )
122 
123  return
124  end subroutine comm_ensemble_finalize
125 
126 end module scale_comm_ensemble
scale_comm_ensemble::comm_ensemble_world
integer, public comm_ensemble_world
Definition: scale_comm_ensemble.F90:35
scale_prc::prc_abort
subroutine, public prc_abort
Abort Process.
Definition: scale_prc.F90:350
scale_comm_ensemble
module Communication for Ensemble system
Definition: scale_comm_ensemble.F90:12
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_prc::prc_local_comm_world
integer, public prc_local_comm_world
local communicator
Definition: scale_prc.F90:89
scale_comm_ensemble::comm_ensemble_setup
subroutine, public comm_ensemble_setup
Setup.
Definition: scale_comm_ensemble.F90:52
scale_prc::prc_myrank
integer, public prc_myrank
process num in local communicator
Definition: scale_prc.F90:91
scale_prc
module PROCESS
Definition: scale_prc.F90:11
scale_io
module STDIO
Definition: scale_io.F90:10
scale_comm_ensemble::comm_ensemble_nprocs
integer, public comm_ensemble_nprocs
Definition: scale_comm_ensemble.F90:37
scale_comm_ensemble::comm_ensemble_finalize
subroutine, public comm_ensemble_finalize
finalize
Definition: scale_comm_ensemble.F90:116
scale_prc::prc_global_myrank
integer, public prc_global_myrank
myrank in global communicator
Definition: scale_prc.F90:81
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_prc::prc_universal_comm_world
integer, public prc_universal_comm_world
original communicator
Definition: scale_prc.F90:72
scale_prc::prc_nprocs
integer, public prc_nprocs
myrank in local communicator
Definition: scale_prc.F90:90
scale_comm_ensemble::comm_ensemble_myrank
integer, public comm_ensemble_myrank
Definition: scale_comm_ensemble.F90:36
scale_prc::prc_global_nprocs
integer, public prc_global_nprocs
process num in global communicator
Definition: scale_prc.F90:82