33 integer :: mpi_err,mdl_id,cpl_root,cpl_mpi_comm
34 integer :: total_timesteps,i
35 integer,
dimension(MPI_STATUS_SIZE) :: mpi_status
36 real(kind=kind(1.0d0)),
dimension(3) :: x
39 print*,
'Reading total_timesteps from file timesteps: '
40 open(11,file=
'timesteps',action=
'read',status=
'old')
41 read(11,*) total_timesteps
47 if(mdl_id .eq. 0)
then
48 call mpi_send(x,3,mpi_double_precision,cpl_root&
49 &,1,cpl_mpi_comm,mpi_err)
52 call mpi_recv(x,3,mpi_double_precision,cpl_root&
53 &,mpi_any_tag,cpl_mpi_comm,mpi_status,mpi_err)
54 print*,
'Received tag = ',mpi_status(mpi_tag)
57 do i = 1,total_timesteps
58 print*,
'Timestep = ',i
60 if(mdl_id .eq. 0)
then
62 call mpi_send(x,3,mpi_double_precision,cpl_root&
63 &,1,cpl_mpi_comm,mpi_err)
66 call mpi_recv(x,3,mpi_double_precision,cpl_root&
67 &,mpi_any_tag,cpl_mpi_comm,mpi_status,mpi_err)
68 print*,
'Received tag = ',mpi_status(mpi_tag)
76 call mpi_finalize(mpi_err)
81 integer,
intent(out) :: mdl_id,cpl_root,cpl_mpi_comm
82 integer :: mdl_num_proc=1
83 integer :: mpi_err,world_size,world_id
85 integer :: particle_id,nens, da, nda
86 integer :: mdl_mpi_comm,mdlcolour
87 integer :: tmp_mdls_comm,models_id,models_size
88 call mpi_init(mpi_err)
89 if(mpi_err .eq. 0)
then
90 print*,
'mpi_init successful'
92 print*,
'mpi_init unsuccessful'
96 call mpi_comm_rank(mpi_comm_world,world_id,mpi_err)
97 if(mpi_err .eq. 0)
then
98 print*,
'mpi_comm_rank successful'
99 print*,
'world_id = ',world_id
101 print*,
'mpi_comm_rank unsuccessful'
105 call mpi_comm_size(mpi_comm_world,world_size,mpi_err)
106 if(mpi_err .eq. 0)
then
107 print*,
'mpi_comm_size successful'
108 print*,
'world_size = ',world_size
110 print*,
'mpi_comm_size unsuccessful'
114 call mpi_comm_split(mpi_comm_world,da,world_id,tmp_mdls_comm,mpi_err)
115 if(mpi_err .eq. 0)
then
116 print*,
'mpi_comm_split successful'
118 print*,
'mpi_comm_split unsuccessful'
122 call mpi_comm_size(tmp_mdls_comm,models_size,mpi_err)
123 if(mpi_err .eq. 0)
then
124 print*,
'mpi_comm_size successful'
125 print*,
'models_size = ',models_size
127 print*,
'mpi_comm_size unsuccessful'
131 call mpi_comm_rank(tmp_mdls_comm,models_id, mpi_err)
132 if(mpi_err .eq. 0)
then
133 print*,
'mpi_comm_rank successful'
134 print*,
'models_id = ',models_id
136 print*,
'mpi_comm_rank unsuccessful'
139 mdlcolour = models_id/mdl_num_proc
140 call mpi_comm_split(tmp_mdls_comm,mdlcolour,models_id,mdl_mpi_comm,mpi_err)
141 if(mpi_err .eq. 0)
then
142 print*,
'mpi_comm_split successful'
144 print*,
'mpi_comm_split unsuccessful'
148 call mpi_comm_rank(mdl_mpi_comm,mdl_id,mpi_err)
149 if(mpi_err .eq. 0)
then
150 print*,
'mpi_comm_rank successful'
151 print*,
'mdl_id = ',mdl_id
153 print*,
'mpi_comm_rank unsuccessful'
156 if(mdl_id .eq. 0)
then
159 cpl_colour = mpi_undefined
161 call mpi_comm_split(mpi_comm_world,cpl_colour,mdlcolour,cpl_mpi_comm,mpi_err)
162 if(mpi_err .eq. 0)
then
163 print*,
'mpi_comm_split successful'
165 print*,
'mpi_comm_split unsuccessful'
168 if(mdl_id .eq. 0)
then
169 call mpi_comm_size(cpl_mpi_comm,nens,mpi_err)
170 if(mpi_err .eq. 0)
then
171 print*,
'mpi_comm_size successful'
172 print*,
'nens = ',nens
174 print*,
'mpi_comm_size unsuccessful'
177 call mpi_comm_rank(cpl_mpi_comm,particle_id,mpi_err)
178 if(mpi_err .eq. 0)
then
179 print*,
'mpi_comm_rank successful'
180 print*,
'particle_id = ',particle_id
182 print*,
'mpi_comm_rank unsuccessful'
185 nda = world_size-models_size;nens = nens - nda
186 cpl_root = ((nda*particle_id)/nens)+nens
190 print*,
'cpl_root = ',cpl_root
program minimal_model_comms
subroutine initialise_mpi(mdl_id, cpl_root, cpl_mpi_comm)