FLASH-X
Doxygen Generated Documentation From Interface Source Code
nameValueLL_bcast.F90
Go to the documentation of this file.
1!! NOTICE
2!! Copyright 2022 UChicago Argonne, LLC and contributors
3!!
4!! Licensed under the Apache License, Version 2.0 (the "License");
5!! you may not use this file except in compliance with the License.
6!!
7!! Unless required by applicable law or agreed to in writing, software
8!! distributed under the License is distributed on an "AS IS" BASIS,
9!! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10!! See the License for the specific language governing permissions and
11!! limitations under the License.
12!!
29
30subroutine nameValueLL_bcast(context, myPE)
31
32 use nameValueLL_data !, ONLY: context_type, nameValueLL_add, &
33! & name_invalid, name_real, name_int, name_str, name_log, &
34! & real_list_type, int_list_type, str_list_type, log_list_type, TYPE_VAR
36
37
38#include "constants.h"
39#include "Flashx_mpi_implicitNone.fh"
40
41 type (context_type), intent(inout) :: context
42 integer, intent(in) :: myPE
43
44 type (real_list_type), pointer:: node_real
45 type (int_list_type), pointer :: node_int
46 type (str_list_type), pointer :: node_str
47 type (log_list_type), pointer :: node_log
48 integer :: istat, i, strtype
49 integer :: n_real, n_int, n_str, n_log
50 real, allocatable :: real_vals(:)
51 integer, allocatable :: int_vals(:)
52 logical, allocatable :: log_vals(:)
53 character(len=MAX_STRING_LENGTH), allocatable :: str_vals(:), &
54 & real_names(:), &
55 & int_names(:), &
56 & str_names(:), &
57 & log_names(:)
58
59
60 ! Create an MPI derived datatype to send character strings.
61
62 call MPI_Type_Contiguous (MAX_STRING_LENGTH, MPI_CHARACTER, strtype, istat)
63 call MPI_Type_Commit (strtype, istat)
64
65
66
67 ! Only the MASTER_PE processor has the parameters; it sends all of
68 ! the parameters of each type in turn to the rest of the
69 ! processors.
70
71
72 ! Send the real-valued parameters.
73
74 n_real = context%n_real
75 call MPI_Bcast (n_real, 1, MPI_INTEGER, MASTER_PE, &
76 & MPI_COMM_WORLD, istat)
77
78 if (n_real > 0) then
79
80 allocate (real_names(n_real), real_vals(n_real), stat=istat)
81 if (istat /= 0) then
82 write (*,*) 'nameValueLL_bcast : allocate failed in real bcast'
83 call Driver_abort("Error: nameValueLL_bcast : allocate failed in real bcast")
84 endif
85
86 if (myPE == MASTER_PE) then
87 i = 1
88 node_real => context%real_list
89 do while (associated(node_real))
90 real_names(i) = node_real%name
91 real_vals(i) = node_real%value
92 i = i + 1
93 node_real => node_real%next
94 enddo
95 endif
96
97 call MPI_Bcast (real_names, n_real, &
98 & strtype, MASTER_PE, MPI_COMM_WORLD, istat)
99 call MPI_Bcast (real_vals, n_real, &
100 & FLASH_REAL, MASTER_PE, &
101 & MPI_COMM_WORLD, istat)
102
103 if (myPE /= MASTER_PE) then
104 do i = 1, n_real
105 call nameValueLL_add(context, real_names(i), real_vals(i), TYPE_VAR)
106 enddo
107 endif
108
109 deallocate (real_names, real_vals)
110
111 endif
112
113
114 ! Send the integer-valued parameters.
115
116 n_int = context%n_int
117 call MPI_Bcast (n_int, 1, MPI_INTEGER, MASTER_PE, &
118 & MPI_COMM_WORLD, istat)
119
120 if (n_int > 0) then
121
122 allocate (int_names(n_int), int_vals(n_int), stat=istat)
123 if (istat /= 0) then
124 write (*,*) 'nameValueLL_bcast: allocate failed'
125 call Driver_abort("Error: nameValueLL_bcast : allocate failed")
126 endif
127
128 if (myPE == MASTER_PE) then
129 i = 1
130 node_int => context%int_list
131 do while (associated(node_int))
132 int_names(i) = node_int%name
133 int_vals(i) = node_int%value
134 i = i + 1
135 node_int => node_int%next
136 enddo
137 endif
138
139 call MPI_Bcast (int_names, n_int, &
140 & strtype, MASTER_PE, MPI_COMM_WORLD, istat)
141 call MPI_Bcast (int_vals, n_int, &
142 & MPI_INTEGER, MASTER_PE, &
143 & MPI_COMM_WORLD, istat)
144
145 if (myPE /= MASTER_PE) then
146 do i = 1, n_int
147 call nameValueLL_add(context, int_names(i), int_vals(i), TYPE_VAR)
148 enddo
149 endif
150
151 deallocate (int_names, int_vals)
152
153 endif
154
155 ! Send the string-valued parameters.
156
157 n_str = context%n_str
158 call MPI_Bcast (n_str, 1, MPI_INTEGER, MASTER_PE, &
159 & MPI_COMM_WORLD, istat)
160
161 if (n_str > 0) then
162
163 allocate (str_names(n_str), str_vals(n_str), stat=istat)
164 if (istat /= 0) then
165 write (*,*) 'nameValueLL_bcast : allocate failed'
166 call Driver_abort("Error: nameValueLL_bcast : allocate failed");
167 endif
168
169 if (myPE == MASTER_PE) then
170 i = 1
171 node_str => context%str_list
172 do while (associated(node_str))
173 str_names(i) = node_str%name
174 str_vals(i) = node_str%value
175 i = i + 1
176 node_str => node_str%next
177 enddo
178 endif
179
180 call MPI_Bcast (str_names, n_str, &
181 & strtype, MASTER_PE, MPI_COMM_WORLD, istat)
182 call MPI_Bcast (str_vals, n_str, &
183 & strtype, MASTER_PE, MPI_COMM_WORLD, istat)
184
185 if (myPE /= MASTER_PE) then
186 do i = 1, n_str
187 call nameValueLL_add(context, str_names(i), str_vals(i), TYPE_VAR)
188 enddo
189 endif
190
191 deallocate (str_names, str_vals)
192
193 endif
194
195 ! Send the logical-valued parameters.
196
197 n_log = context%n_log
198 call MPI_Bcast (n_log, 1, MPI_INTEGER, MASTER_PE, &
199 & MPI_COMM_WORLD, istat)
200
201 if (n_log > 0) then
202
203 allocate (log_names(n_log), log_vals(n_log), stat=istat)
204 if (istat /= 0) then
205 write (*,*) 'nameValueLL_bcast : allocate failed'
206 call Driver_abort("nameValueLL_bcast : allocate failed")
207 endif
208
209 if (myPE == MASTER_PE) then
210 i = 1
211 node_log => context%log_list
212 do while (associated(node_log))
213 log_names(i) = node_log%name
214 log_vals(i) = node_log%value
215 i = i + 1
216 node_log => node_log%next
217 enddo
218 endif
219
220 call MPI_Bcast (log_names, n_log, &
221 & strtype, MASTER_PE, MPI_COMM_WORLD, istat)
222 call MPI_Bcast (log_vals, n_log, &
223 & MPI_LOGICAL, MASTER_PE, &
224 & MPI_COMM_WORLD, istat)
225
226 if (myPE /= MASTER_PE) then
227 do i = 1, n_log
228 call nameValueLL_add(context, log_names(i), log_vals(i), TYPE_VAR)
229 enddo
230 endif
231
232 deallocate (log_names, log_vals)
233
234 endif
235
236 ! Free up the MPI derived datatype used to send strings.
237
238 call MPI_Type_Free (strtype, istat)
239
240 return
241end subroutine nameValueLL_bcast
#define MASTER_PE
Definition: constants.h:6
subroutine nameValueLL_bcast(context, myPE)
integer, parameter TYPE_VAR