EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
minimal_model_comms.f90
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 ! minimal_model_comms just sets up communicators for empire for
3 ! testing purposes
4 !
5 !The MIT License (MIT)
6 !
7 !Copyright (c) 2015 Philip A. Browne
8 !
9 !Permission is hereby granted, free of charge, to any person obtaining a copy
10 !of this software and associated documentation files (the "Software"), to deal
11 !in the Software without restriction, including without limitation the rights
12 !to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 !copies of the Software, and to permit persons to whom the Software is
14 !furnished to do so, subject to the following conditions:
15 !
16 !The above copyright notice and this permission notice shall be included in all
17 !copies or substantial portions of the Software.
18 !
19 !THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 !IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 !FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 !AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 !LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 !OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 !SOFTWARE.
26 !
27 !Email: p.browne@reading.ac.uk
28 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 
31 implicit none
32 include 'mpif.h'
33 integer :: mpi_err,mdl_id,cpl_root,cpl_mpi_comm
34 call initialise_mpi(mdl_id,cpl_root,cpl_mpi_comm)
35 call mpi_finalize(mpi_err)
36 contains
37  subroutine initialise_mpi(mdl_id,cpl_root,cpl_mpi_comm)
38  implicit none
39  include 'mpif.h'
40  integer, intent(out) :: mdl_id,cpl_root,cpl_mpi_comm
41  integer :: mdl_num_proc=1
42  integer :: mpi_err,world_size,world_id
43  integer :: cpl_colour
44  integer :: particle_id,nens, da, nda
45  integer :: mdl_mpi_comm,mdlcolour
46  integer :: tmp_mdls_comm,models_id,models_size
47  call mpi_init(mpi_err)
48  if(mpi_err .eq. 0) then
49  print*,'mpi_init successful'
50  else
51  print*,'mpi_init unsuccessful'
52  end if
53 
54  da = 0
55  call mpi_comm_rank(mpi_comm_world,world_id,mpi_err)
56  if(mpi_err .eq. 0) then
57  print*,'mpi_comm_rank successful'
58  print*,'world_id = ',world_id
59  else
60  print*,'mpi_comm_rank unsuccessful'
61  end if
62 
63 
64  call mpi_comm_size(mpi_comm_world,world_size,mpi_err)
65  if(mpi_err .eq. 0) then
66  print*,'mpi_comm_size successful'
67  print*,'world_size = ',world_size
68  else
69  print*,'mpi_comm_size unsuccessful'
70  end if
71 
72 
73  call mpi_comm_split(mpi_comm_world,da,world_id,tmp_mdls_comm,mpi_err)
74  if(mpi_err .eq. 0) then
75  print*,'mpi_comm_split successful'
76  else
77  print*,'mpi_comm_split unsuccessful'
78  end if
79 
80 
81  call mpi_comm_size(tmp_mdls_comm,models_size,mpi_err)
82  if(mpi_err .eq. 0) then
83  print*,'mpi_comm_size successful'
84  print*,'models_size = ',models_size
85  else
86  print*,'mpi_comm_size unsuccessful'
87  end if
88 
89 
90  call mpi_comm_rank(tmp_mdls_comm,models_id, mpi_err)
91  if(mpi_err .eq. 0) then
92  print*,'mpi_comm_rank successful'
93  print*,'models_id = ',models_id
94  else
95  print*,'mpi_comm_rank unsuccessful'
96  end if
97 
98  mdlcolour = models_id/mdl_num_proc
99  call mpi_comm_split(tmp_mdls_comm,mdlcolour,models_id,mdl_mpi_comm,mpi_err)
100  if(mpi_err .eq. 0) then
101  print*,'mpi_comm_split successful'
102  else
103  print*,'mpi_comm_split unsuccessful'
104  end if
105 
106 
107  call mpi_comm_rank(mdl_mpi_comm,mdl_id,mpi_err)
108  if(mpi_err .eq. 0) then
109  print*,'mpi_comm_rank successful'
110  print*,'mdl_id = ',mdl_id
111  else
112  print*,'mpi_comm_rank unsuccessful'
113  end if
114 
115  if(mdl_id .eq. 0) then
116  cpl_colour = 9999
117  else
118  cpl_colour = mpi_undefined
119  end if
120  call mpi_comm_split(mpi_comm_world,cpl_colour,mdlcolour,cpl_mpi_comm,mpi_err)
121  if(mpi_err .eq. 0) then
122  print*,'mpi_comm_split successful'
123  else
124  print*,'mpi_comm_split unsuccessful'
125  end if
126 
127  if(mdl_id .eq. 0) then
128  call mpi_comm_size(cpl_mpi_comm,nens,mpi_err)
129  if(mpi_err .eq. 0) then
130  print*,'mpi_comm_size successful'
131  print*,'nens = ',nens
132  else
133  print*,'mpi_comm_size unsuccessful'
134  end if
135 
136  call mpi_comm_rank(cpl_mpi_comm,particle_id,mpi_err)
137  if(mpi_err .eq. 0) then
138  print*,'mpi_comm_rank successful'
139  print*,'particle_id = ',particle_id
140  else
141  print*,'mpi_comm_rank unsuccessful'
142  end if
143 
144  nda = world_size-models_size;nens = nens - nda
145  cpl_root = ((nda*particle_id)/nens)+nens
146  else
147  cpl_root = -1
148  end if
149  print*,'cpl_root = ',cpl_root
150  end subroutine initialise_mpi
151 end program minimal_model_comms
program minimal_model_comms
subroutine initialise_mpi(mdl_id, cpl_root, cpl_mpi_comm)