37 integer,
parameter :: mdl_num_proc=5
38 integer :: mdl_mpi_comm
39 integer :: temp_mdls_comm
40 integer :: temp_mdls_rank
43 integer,
parameter :: rk = kind(1.0d0)
44 real(kind=rk),
allocatable,
dimension(:) :: state_vector
48 integer :: particle_rank
51 integer :: temp_mdls_size
52 integer :: temp_cpl_comm
55 integer :: cpl_mpi_comm
56 integer :: null_mpi_comm
57 integer :: tmp_colour_2
58 integer :: tmp_cpl_comm2
59 integer :: tmp_cpl_rank
61 print*,
'RUNNING MINIMAL_MODEL_COMMS_V3'
63 call mpi_init(mpi_err)
64 if(mpi_err .eq. 0)
then
65 print*,
'mpi_init successful'
67 print*,
'mpi_init unsuccessful'
71 call mpi_comm_rank(mpi_comm_world,world_rank,mpi_err)
72 if(mpi_err .eq. 0)
then
73 print*,
'mpi_comm_rank successful'
74 print*,
'world_rank = ',world_rank
76 print*,
'mpi_comm_rank unsuccessful'
80 call mpi_comm_size(mpi_comm_world,world_size,mpi_err)
81 if(mpi_err .eq. 0)
then
82 print*,
'mpi_comm_size successful'
83 print*,
'world_size = ',world_size
85 print*,
'mpi_comm_size unsuccessful'
89 cpl_root = world_size-1
90 print*,
'rank = ',world_rank,
' on mpi_comm_world which has size ',world_size
94 call mpi_allreduce(mdl_num_proc,i,1,mpi_integer,mpi_max&
95 &,mpi_comm_world,mpi_err)
96 if(mpi_err .eq. 0)
then
97 print*,
'mpi_allreduce successful'
100 print*,
'mpi_allreduce unsuccessful'
107 call mpi_comm_split(mpi_comm_world,da,world_rank,temp_mdls_comm&
109 if(mpi_err .eq. 0)
then
110 print*,
'mpi_comm_split successful: temp_mdls_comm created'
112 print*,
'mpi_comm_split unsuccessful: temp_mdls_comm not created'
115 call mpi_comm_size(temp_mdls_comm,temp_mdls_size,mpi_err)
116 if(mpi_err .eq. 0)
then
117 print*,
'mpi_comm_size successful'
118 print*,
'temp_mdls_size = ',temp_mdls_size
120 print*,
'mpi_comm_size unsuccessful'
124 if(mod(temp_mdls_size,mdl_num_proc) .ne. 0)
then
125 print*,
'MINIMAL MODEL LAUNCH ERROR.'
126 print*,
'MUST LAUNCH A MULTIPLE OF ',mdl_num_proc,
' copies of the &
132 nda = (world_size-temp_mdls_size)/mdl_num_proc
134 print*,
'MINIMAL MODEL COMMS v3 ERROR: nda is less than 1.'
135 print*,
'Make sure you launch with a DA CODE'
144 nens = temp_mdls_size/mdl_num_proc
145 call mpi_comm_rank(temp_mdls_comm,temp_mdls_rank,mpi_err)
146 if(mpi_err .eq. 0)
then
147 print*,
'mpi_comm_rank successful'
148 print*,
'temp_mdls_rank = ',temp_mdls_rank
150 print*,
'mpi_comm_rank unsuccessful'
154 particle_rank = temp_mdls_rank/mdl_num_proc
156 call mpi_comm_split(temp_mdls_comm,particle_rank,temp_mdls_rank&
157 &,mdl_mpi_comm,mpi_err)
158 if(mpi_err .eq. 0)
then
159 print*,
'mpi_comm_split successful: mdl_mpi_comm created'
161 print*,
'mpi_comm_split unsuccessful: mdl_mpi_comm not created'
166 call mpi_comm_rank(mdl_mpi_comm,mdl_rank,mpi_err)
167 if(mpi_err .eq. 0)
then
168 print*,
'mpi_comm_rank successful'
169 print*,
'mdl_rank = ',mdl_rank
171 print*,
'mpi_comm_rank unsuccessful'
180 cpl_root = nda*particle_rank/nens
181 print*,
'cpl_root = ',cpl_root
183 if(cpl_root .lt. 0)
then
184 print*,
'MINIMAL MODEL COMMS v3 ERROR: cpl_root is less than 0.'
185 print*,
'Make sure you launch with a DA CODE'
189 call mpi_comm_split(mpi_comm_world,cpl_root,temp_mdls_rank,temp_cpl_comm,mpi_err)
190 if(mpi_err .eq. 0)
then
191 print*,
'mpi_comm_split successful: temp_cpl_comm created'
193 print*,
'mpi_comm_split unsuccessful: temp_cpl_comm not created'
200 call mpi_comm_rank(temp_cpl_comm,tmp_cpl_rank,mpi_err)
201 if(mpi_err .eq. 0)
then
202 print*,
'mpi_comm_rank successful: tmp_cpl_rank = ',tmp_cpl_rank
204 print*,
'mpl_comm_rank unsuccessful: tmp_cpl_rank not detected'
207 tmp_colour_2 = mod(tmp_cpl_rank,mdl_num_proc)
208 print*,
'tmp_colour_2 = ',tmp_colour_2
209 call mpi_comm_split(temp_cpl_comm,tmp_colour_2,tmp_cpl_rank&
210 &,tmp_cpl_comm2,mpi_err)
211 if(mpi_err .eq. 0)
then
212 print*,
'mpi_comm_split successful: tmp_cpl_comm2 created'
214 print*,
'mpi_comm_split unsuccessful: tmp_cpl_comm2 not created'
222 first_ptcl = -((-cpl_root)*nens/nda)
223 final_ptcl = -((-cpl_root-1)*nens/nda)-1
225 first_ptcl = ceiling(
real(cpl_root)*
real(nens)/
real(nda))
226 final_ptcl = ceiling(
real(cpl_root+1)*
real(nens)/
real(nda))-1
229 print*,
'range of particles = ',first_ptcl,final_ptcl
233 do i = first_ptcl,final_ptcl
234 print*,
'i = ',i,
' particle_rank = ',particle_rank
235 if(i .eq. particle_rank)
then
236 call mpi_comm_split(tmp_cpl_comm2,1,temp_mdls_rank&
237 &,cpl_mpi_comm,mpi_err)
238 print*,
'created cpl_mpi_comm',cpl_mpi_comm
240 print*,
'doing null splitting'
241 call mpi_comm_split(tmp_cpl_comm2,0,temp_mdls_rank&
242 &,null_mpi_comm,mpi_err)
243 print*,
'created mpi_comm_null'
244 call mpi_comm_free(null_mpi_comm,mpi_err)
245 print*,
'freed up null_mpi_comm'
259 call mpi_comm_free(temp_cpl_comm ,mpi_err)
260 call mpi_comm_free(tmp_cpl_comm2,mpi_err)
264 select case(mdl_rank)
276 print*,
'it was at this point, model realised, he fucked up'
279 allocate(state_vector(state_dim))
284 state_vector = 10*mdl_rank + (/ (
real(i,rk), i = 1,state_dim) /)
286 print*,
'state_vector = '
289 print*,
'doing a send on cpl_mpi_comm'
291 call mpi_send(state_dim,1,mpi_integer,cpl_root,1,cpl_mpi_comm,mpi_err)
292 print*,
'finished the send on cpl_mpi_comm'
299 call mpi_finalize(mpi_err)
300 print*,
'MINIMAL_MODEL_COMMS_v3 finished nicely'
program minimal_model_comms_v3