Peano
Loading...
Searching...
No Matches
MultisweepTaskGraph.py
Go to the documentation of this file.
1# This file is part of the ExaParty project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from exaparty.api.particle.AlgorithmStep import AlgorithmStep
4from exaparty.api.actionsets.UpdateParticleMarker import UpdateParticleMarker
5
6import peano4.api
7import exaparty
8
9
10from .AMRLogic import add_dynamic_mesh_refinement_and_particle_resorting
11from .ParticleSortingAndStorage import (
12 ParticleSortingAndStorage,
13 AddAdditionalDummySweep,
14)
15from .SpeciesStepOrdering import concatenate_steps_of_species
16from .Utils import (
17 does_one_species_require_gather,
18 get_species_set,
19 get_observer_prefix,
20 StepType,
21)
22from .Sequential import (
23 map_onto_separate_mesh_traversals,
24 map_onto_separate_mesh_traversals_with_generic_mapper,
25)
26from .TaskGraph import add_clear_task_number_to_very_first_initialisation_step
27
28
30 step,
31 current_species_set,
32 mesh_traversals,
33 alter_particle_position,
34 use_continuous_particles_sequences,
35 step_type: StepType,
36 verbose,
37):
38 """!
39
40 Actual translation of one step per particle species onto a task graph construction
41
42 We basically forward to exaparty.api.graphcompiler.TaskGraph.translate_one_step_of_species_into_mesh_traversal()
43 but we set the flag synchronise_task_graph_after_each_mesh_sweep() to
44 false. This does not mean that the arising task graph is bare of all
45 synchronisation. It just means that we don't immediately synchronise
46 after each step.
47
48 All the wrappers have implicitly built in some synchronisation: A vertex
49 issues a task with a number. If this number is already tied to an existing
50 task, this creates an in-out dependency. However, we have three types of
51 task numbers per species:
52
53 - touch vertex first task numbers
54 - touch cell first task numbers
55 - touch vertex last task numbers
56
57 Each observer will create vertex first-vertex first-cell-vertex last chains
58 of tasks with an arbitrary number of first and last instances. The important thing
59 to keep things correct therefore is that we establish vertex last-vertex first
60 relations here which ensure that one chain does not mangle into the chain of the
61 predecessor.
62
63 This is the added thing here. Global syncs will automatically be added where
64 they are necessary (cmp. translate_one_step_of_species_into_mesh_traversal()
65 and the variable synchronise_after_each_mesh_traversal therein).
66
67 SynchroniseVerticesWithPreviousMeshSweep
68
69
70 - wrapper alles first
71 - nix in touch cell last
72
73 """
75 step,
76 current_species_set,
77 mesh_traversals,
78 alter_particle_position,
79 use_continuous_particles_sequences,
80 step_type,
81 verbose,
82 synchronise_task_graph_after_each_mesh_sweep=False,
83 )
84
85 assert (
86 len(mesh_traversals) > 0
87 ), "at least one step has to be added after translate_one_step_of_species_into_mesh_traversal() has terminated"
88
89 glue_two_mesh_sweeps_together = (
91 current_species_set
92 )
93 )
94 glue_two_mesh_sweeps_together.descend_invocation_order = (
95 mesh_traversals[-1].lowest_descend_invocation_order() - 1
96 )
97 glue_two_mesh_sweeps_together.parallel = False
98 mesh_traversals[-1].add_action_set(glue_two_mesh_sweeps_together)
99
100 if verbose:
101 print(
102 "GRAPH COMPILER DEBUG [translate_one_step_of_species_into_mesh_traversal]: step no {} ({}) on particle {} uses exaparty.api.actionsets.SynchroniseVerticesWithPreviousMeshSweep".format(
103 len(mesh_traversals),
104 step.name,
105 current_species_set.particle_model.name,
106 )
107 )
108
109
111 sequence_of_steps,
112 particle_sorting_and_storage: ParticleSortingAndStorage,
113 step_type: StepType,
114 verbose,
115):
116 """!
117
118 Forward to map_onto_separate_mesh_traversals_with_generic_mapper().
119 Consult implementation in TaskGraph.py for further information.
120
121 The bespoke logic here is injected by the functor
122 translate_one_step_of_species_into_mesh_traversal() pointing to
123 another routine in this file.
124
125 """
126 return map_onto_separate_mesh_traversals_with_generic_mapper(
127 sequence_of_steps,
128 particle_sorting_and_storage,
129 step_type,
130 verbose,
131 translate_one_step_of_species_into_mesh_traversal,
132 )
133
134
135# ====================================
136# Public API functions
137# ====================================
138#
139# These functions are made available through the __init__.py file. They are all
140# "just" wrappers around the generic map_onto_separate_mesh_traversals()
141# function calls, yet with different arguments.
142#
143
144
145def initialisation_steps_onto_multisweep_task_graph_multiscale_sort_scattered_memory(
146 species_sets,
147 verbose,
148):
149 """!
150
151 @see map_onto_separate_mesh_traversals()
152
153 @param concatenate_steps_of_species: [Species]
154 Sequence of particle species to be handled.
155
156 @param verbose: {True, False}
157
158 """
160 sequence_of_steps=concatenate_steps_of_species(species_sets, True),
161 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_SCATTERED_PARTICLE_STORAGE,
162 step_type=StepType.INITIALISATION,
163 verbose=verbose,
164 )
165 add_clear_task_number_to_very_first_initialisation_step(
166 result, species_sets, verbose
167 )
168 return result
169
170
171def initialisation_steps_onto_multisweep_task_graph_bucket_sort_scattered_memory(
172 species_sets,
173 verbose,
174):
175 """!
176
177 @see map_onto_separate_mesh_traversals()
178
179 @param concatenate_steps_of_species: [Species]
180 Sequence of particle species to be handled.
181
182 @param verbose: {True, False}
183
184 """
186 sequence_of_steps=concatenate_steps_of_species(species_sets, True),
187 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_ON_THE_FLY_SCATTERED_PARTICLE_STORAGE,
188 step_type=StepType.INITIALISATION,
189 verbose=verbose,
190 )
191 add_clear_task_number_to_very_first_initialisation_step(
192 result, species_sets, verbose
193 )
194 return result
195
196
197def initialisation_steps_onto_multisweep_task_graph_multiscale_sort_coalesced_memory(
198 species_sets,
199 verbose,
200):
201 """!
202
203 @see map_onto_separate_mesh_traversals()
204
205 @param concatenate_steps_of_species: [Species]
206 Sequence of particle species to be handled.
207
208 @param verbose: {True, False}
209
210 """
212 sequence_of_steps=concatenate_steps_of_species(species_sets, True),
213 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_COALESCED_PARTICLE_STORAGE,
214 step_type=StepType.INITIALISATION,
215 verbose=verbose,
216 )
217 add_clear_task_number_to_very_first_initialisation_step(
218 result, species_sets, verbose
219 )
220 return result
221
222
223def initialisation_steps_onto_multisweep_task_graph_bucket_sort_coalesced_memory(
224 species_sets,
225 verbose,
226):
227 """!
228
229 @see map_onto_separate_mesh_traversals()
230
231 @param concatenate_steps_of_species: [Species]
232 Sequence of particle species to be handled.
233
234 @param verbose: {True, False}
235
236 """
238 sequence_of_steps=concatenate_steps_of_species(species_sets, True),
239 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_ON_THE_FLY_COALESCED_PARTICLE_STORAGE,
240 step_type=StepType.INITIALISATION,
241 verbose=verbose,
242 )
243 add_clear_task_number_to_very_first_initialisation_step(
244 result, species_sets, verbose
245 )
246 return result
247
248
249def particle_steps_onto_multisweep_task_graph_multiscale_sort_scattered_memory(
250 species_sets,
251 verbose,
252):
253 """!
254
255 For a sequential ordering, i.e. 1:1 mapping of steps per species onto
256 traversals, it makes no real difference how we order the progress through
257 the individual steps. So I just concatenate the steps per species.
258
259 @see map_onto_separate_mesh_traversals()
260
261 @param concatenate_steps_of_species: [Species]
262 Sequence of particle species to be handled.
263
264 @param verbose: {True, False}
265
266 """
268 sequence_of_steps=concatenate_steps_of_species(species_sets, False),
269 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_SCATTERED_PARTICLE_STORAGE,
270 step_type=StepType.TIME_STEP,
271 verbose=verbose,
272 )
273
274
275def particle_steps_onto_multisweep_task_graph_bucket_sort_scattered_memory(
276 species_sets,
277 verbose,
278):
279 """!
280
281 For a sequential ordering, i.e. 1:1 mapping of steps per species onto
282 traversals, it makes no real difference how we order the progress through
283 the individual steps. So I just concatenate the steps per species.
284
285 @see map_onto_separate_mesh_traversals()
286
287 @param concatenate_steps_of_species: [Species]
288 Sequence of particle species to be handled.
289
290 @param verbose: {True, False}
291
292 """
294 sequence_of_steps=concatenate_steps_of_species(species_sets, False),
295 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_ON_THE_FLY_SCATTERED_PARTICLE_STORAGE,
296 step_type=StepType.TIME_STEP,
297 verbose=verbose,
298 )
299
300
301def particle_steps_onto_multisweep_task_graph_multiscale_sort_coalesced_memory(
302 species_sets,
303 verbose,
304):
305 """!
306
307 For a sequential ordering, i.e. 1:1 mapping of steps per species onto
308 traversals, it makes no real difference how we order the progress through
309 the individual steps. So I just concatenate the steps per species.
310
311 @see map_onto_separate_mesh_traversals()
312
313 @param concatenate_steps_of_species: [Species]
314 Sequence of particle species to be handled.
315
316 @param verbose: {True, False}
317
318 """
320 sequence_of_steps=concatenate_steps_of_species(species_sets, False),
321 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_COALESCED_PARTICLE_STORAGE,
322 step_type=StepType.TIME_STEP,
323 verbose=verbose,
324 )
325
326
327def particle_steps_onto_multisweep_task_graph_bucket_sort_coalesced_memory(
328 species_sets,
329 verbose,
330):
331 """!
332
333 For a sequential ordering, i.e. 1:1 mapping of steps per species onto
334 traversals, it makes no real difference how we order the progress through
335 the individual steps. So I just concatenate the steps per species.
336
337 @see map_onto_separate_mesh_traversals()
338
339 @param concatenate_steps_of_species: [Species]
340 Sequence of particle species to be handled.
341
342 @param verbose: {True, False}
343
344 """
346 sequence_of_steps=concatenate_steps_of_species(species_sets, False),
347 particle_sorting_and_storage=ParticleSortingAndStorage.SORT_ON_THE_FLY_COALESCED_PARTICLE_STORAGE,
348 step_type=StepType.TIME_STEP,
349 verbose=verbose,
350 )
map_onto_separate_mesh_traversals_constructing_task_graph(sequence_of_steps, ParticleSortingAndStorage particle_sorting_and_storage, StepType step_type, verbose)
Forward to map_onto_separate_mesh_traversals_with_generic_mapper().
translate_one_step_of_species_into_mesh_traversal(step, current_species_set, mesh_traversals, alter_particle_position, use_continuous_particles_sequences, StepType step_type, verbose)
Actual translation of one step per particle species onto a task graph construction.
translate_one_step_of_species_into_mesh_traversal(step, current_species_set, mesh_traversals, alter_particle_position, use_continuous_particles_sequences, StepType step_type, verbose, synchronise_task_graph_after_each_mesh_sweep=True)
Translate one step of species into mesh traversal.
Definition TaskGraph.py:37