32 real(kind=kind(1.0D0)) :: t,sigma,rho,beta,dt,tstart,tstop
33 real(kind=kind(1.0D0)),
dimension(3) :: x,k1,k2,k3,k4
34 integer :: mpi_err,mdl_rank,cpl_root,cpl_mpi_comm
36 real(kind=kind(1.0d0)),
dimension(0) :: send_null
38 tstart =0.0d0 ; dt = 0.01d0 ; tstop =
real(40*100)*dt
39 sigma = 10.0d0 ; rho = 28.0d0 ; beta = 8.0d0 /3.0d0
40 x = (/ 1.508870d0, -1.531271d0 , 25.46091d0 /)
45 call mpi_gatherv(x,3,mpi_double_precision,x&
46 &,3,3,mpi_double_precision,cpl_root&
47 &,cpl_mpi_comm,mpi_err)
51 call mpi_scatterv(send_null,0,0,mpi_double_precision,x&
52 &,3,mpi_double_precision,cpl_root,cpl_mpi_comm,mpi_err)
54 call mpi_bcast(tag,1,mpi_integer,cpl_root,cpl_mpi_comm,mpi_err)
57 do;
if ( t .ge. tstop -1.0d-10)
exit
58 k1 =
f(x , sigma , rho , beta )
59 k2 =
f(x +0.5d0 * dt * k1 , sigma , rho , beta )
60 k3 =
f(x +0.5d0 * dt * k2 , sigma , rho , beta )
61 k4 =
f(x + dt * k3 , sigma , rho , beta )
62 x = x + dt *( k1 + 2.0d0 *( k2 + k3 ) + k4 )/6.0d0
65 call mpi_gatherv(x,3,mpi_double_precision,x&
66 &,3,3,mpi_double_precision,cpl_root&
67 &,cpl_mpi_comm,mpi_err)
71 call mpi_scatterv(send_null,0,0,mpi_double_precision,x&
72 &,3,mpi_double_precision,cpl_root,cpl_mpi_comm,mpi_err)
74 call mpi_bcast(tag,1,mpi_integer,cpl_root,cpl_mpi_comm,mpi_err)
88 call mpi_finalize(mpi_err)
90 function f (x , sigma , rho , beta )
92 real(kind=kind(1.0D0)),
intent(in),
dimension (3) :: x
93 real(kind=kind(1.0D0)),
dimension(3) :: f
94 real(kind=kind(1.0D0)),
intent(in) :: sigma , rho , beta
95 f = (/sigma *(x(2)-x(1)),x(1)*(rho-x(3)) -x(2),x(1)*x(2)-beta*x(3)/)
104 integer,
intent(out) :: mdl_rank
105 integer,
intent(out) :: cpl_root
106 integer,
intent(out) :: cpl_mpi_comm
108 integer,
parameter :: mdl_num_proc=1
109 integer :: mdl_mpi_comm
112 integer :: world_rank
113 integer :: world_size
115 integer :: temp_mdls_size
116 integer :: temp_cpl_comm
117 integer :: temp_mdls_comm
118 integer :: temp_mdls_rank
121 integer :: particle_rank
124 integer :: first_ptcl
125 integer :: final_ptcl
126 integer :: null_mpi_comm
128 logical :: msg=.true.
131 call mpi_init(mpi_err)
132 if(mpi_err .eq. 0)
then
133 if(msg) print*,
'mpi_init successful'
135 print*,
'mpi_init unsuccessful'
139 call mpi_comm_rank(mpi_comm_world,world_rank,mpi_err)
140 if(mpi_err .eq. 0)
then
141 if(msg) print*,
'mpi_comm_rank successful'
142 if(msg) print*,
'world_rank = ',world_rank
144 print*,
'mpi_comm_rank unsuccessful'
148 call mpi_comm_size(mpi_comm_world,world_size,mpi_err)
149 if(mpi_err .eq. 0)
then
150 if(msg) print*,
'mpi_comm_size successful'
151 if(msg) print*,
'world_size = ',world_size
153 print*,
'mpi_comm_size unsuccessful'
157 cpl_root = world_size-1
159 print*,
'rank = ',world_rank,
' on mpi_comm_world which has &
166 call mpi_allreduce(mdl_num_proc,i,1,mpi_integer,mpi_max&
167 &,mpi_comm_world,mpi_err)
168 if(mpi_err .eq. 0)
then
169 if(msg) print*,
'mpi_allreduce successful'
170 if(msg) print*,
'i = ',i
172 print*,
'mpi_allreduce unsuccessful'
177 call mpi_comm_split(mpi_comm_world,da,world_rank,temp_mdls_comm&
179 if(mpi_err .eq. 0)
then
180 if(msg) print*,
'mpi_comm_split successful: temp_mdls_comm created'
182 print*,
'mpi_comm_split unsuccessful: temp_mdls_comm not created'
185 call mpi_comm_size(temp_mdls_comm,temp_mdls_size,mpi_err)
186 if(mpi_err .eq. 0)
then
187 if(msg) print*,
'mpi_comm_size successful'
188 if(msg) print*,
'temp_mdls_size = ',temp_mdls_size
190 print*,
'mpi_comm_size unsuccessful'
194 if(mod(temp_mdls_size,mdl_num_proc) .ne. 0)
then
195 print*,
'MINIMAL MODEL LAUNCH ERROR.'
196 print*,
'MUST LAUNCH A MULTIPLE OF ',mdl_num_proc,
' copies of the &
202 nda = world_size-temp_mdls_size
204 print*,
'MINIMAL MODEL COMMS v2 ERROR: nda is less than 1.'
205 print*,
'Make sure you launch with a DA CODE'
211 nens = temp_mdls_size/mdl_num_proc
212 call mpi_comm_rank(temp_mdls_comm,temp_mdls_rank,mpi_err)
213 if(mpi_err .eq. 0)
then
214 if(msg) print*,
'mpi_comm_rank successful'
215 if(msg) print*,
'temp_mdls_rank = ',temp_mdls_rank
217 print*,
'mpi_comm_rank unsuccessful'
221 particle_rank = temp_mdls_rank/mdl_num_proc
223 call mpi_comm_split(temp_mdls_comm,particle_rank,temp_mdls_rank&
224 &,mdl_mpi_comm,mpi_err)
225 if(mpi_err .eq. 0)
then
226 if(msg) print*,
'mpi_comm_split successful: mdl_mpi_comm created'
228 print*,
'mpi_comm_split unsuccessful: mdl_mpi_comm not created'
233 call mpi_comm_rank(mdl_mpi_comm,mdl_rank,mpi_err)
234 if(mpi_err .eq. 0)
then
235 if(msg) print*,
'mpi_comm_rank successful'
236 if(msg) print*,
'mdl_rank = ',mdl_rank
238 print*,
'mpi_comm_rank unsuccessful'
242 cpl_root = nda*particle_rank/nens
243 if(msg) print*,
'cpl_root = ',cpl_root
245 if(cpl_root .lt. 0)
then
246 print*,
'MINIMAL MODEL COMMS v2 ERROR: cpl_root is less than 0.'
247 print*,
'Make sure you launch with a DA CODE'
251 call mpi_comm_split(mpi_comm_world,cpl_root,temp_mdls_rank,temp_cpl_comm,mpi_err)
252 if(mpi_err .eq. 0)
then
253 if(msg) print*,
'mpi_comm_split successful: temp_cpl_comm created'
255 print*,
'mpi_comm_split unsuccessful: temp_cpl_comm not created'
263 first_ptcl = ceiling(
real(cpl_root)*
real(nens)/
real(nda))
264 final_ptcl = ceiling(
real(cpl_root+1)*
real(nens)/
real(nda))-1
267 if(msg) print*,
'range of particles = ',first_ptcl,final_ptcl
271 do i = first_ptcl,final_ptcl
272 if(msg) print*,
'i = ',i,
' particle_rank = ',particle_rank
273 if(i .eq. particle_rank)
then
274 call mpi_comm_split(temp_cpl_comm,1,temp_mdls_rank&
275 &,cpl_mpi_comm,mpi_err)
276 if(msg) print*,
'created cpl_mpi_comm'
278 if(msg) print*,
'doing null splitting'
279 call mpi_comm_split(temp_cpl_comm,0,temp_mdls_rank&
280 &,null_mpi_comm,mpi_err)
281 if(msg) print*,
'created mpi_comm_null'
282 call mpi_comm_free(null_mpi_comm,mpi_err)
283 if(msg) print*,
'freed up null_mpi_comm'
289 cpl_root = mdl_num_proc
301 integer,
intent(in) :: N
302 integer,
intent(in) :: cpl_root
303 integer,
intent(in) :: cpl_mpi_comm
305 logical :: msg = .true.
307 if(msg) print*,
'called empire_process_dimensions'
308 call mpi_gather(n,1,mpi_integer,n&
309 &,1,mpi_integer,cpl_root,cpl_mpi_comm,mpi_err)
310 if(msg) print*,
'finished the gather on cpl_mpi_comm for empire_process_dimensions'
subroutine empire_process_dimensions(N, cpl_root, cpl_mpi_comm)
subroutine initialise_mpi_v2(mdl_rank, cpl_root, cpl_mpi_comm)
real(kind=kind(1.0d0)) function, dimension(n) f(n, x)