-
Notifications
You must be signed in to change notification settings - Fork 53
/
engine_maketasks.c
4460 lines (3770 loc) · 172 KB
/
engine_maketasks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
* Matthieu Schaller (matthieu.schaller@durham.ac.uk)
* 2015 Peter W. Draper (p.w.draper@durham.ac.uk)
* Angus Lepper (angus.lepper@ed.ac.uk)
* 2016 John A. Regan (john.a.regan@durham.ac.uk)
* Tom Theuns (tom.theuns@durham.ac.uk)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdlib.h>
#include <unistd.h>
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
#endif
/* Load the profiler header, if needed. */
#ifdef WITH_PROFILER
#include <gperftools/profiler.h>
#endif
/* This object's header. */
#include "engine.h"
/* Local headers. */
#include "atomic.h"
#include "cell.h"
#include "clocks.h"
#include "cycle.h"
#include "debug.h"
#include "error.h"
#include "feedback.h"
#include "neutrino_properties.h"
#include "proxy.h"
#include "rt_properties.h"
#include "timers.h"
extern int engine_max_parts_per_ghost;
extern int engine_max_sparts_per_ghost;
extern int engine_star_resort_task_depth;
extern int engine_max_parts_per_cooling;
/**
* @brief Add send tasks for the gravity pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param ci The sending #cell.
* @param cj Dummy cell containing the nodeID of the receiving node.
* @param t_grav The send_grav #task, if it has already been created.
*/
void engine_addtasks_send_gravity(struct engine *e, struct cell *ci,
struct cell *cj, struct task *t_grav) {
#ifdef WITH_MPI
struct link *l = NULL;
struct scheduler *s = &e->sched;
const int nodeID = cj->nodeID;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(ci, cell_flag_has_tasks)) return;
/* Check if any of the gravity tasks are for the target node. */
for (l = ci->grav.grav; l != NULL; l = l->next)
if (l->t->ci->nodeID == nodeID ||
(l->t->cj != NULL && l->t->cj->nodeID == nodeID))
break;
/* If so, attach send tasks. */
if (l != NULL) {
/* Create the tasks and their dependencies? */
if (t_grav == NULL) {
/* Make sure this cell is tagged. */
cell_ensure_tagged(ci);
t_grav = scheduler_addtask(s, task_type_send, task_subtype_gpart,
ci->mpi.tag, 0, ci, cj);
/* The sends should unlock the down pass. */
scheduler_addunlock(s, t_grav, ci->grav.super->grav.down);
/* Drift before you send */
scheduler_addunlock(s, ci->grav.super->grav.drift, t_grav);
}
/* Add them to the local cell. */
engine_addlink(e, &ci->mpi.send, t_grav);
}
/* Recurse? */
if (ci->split)
for (int k = 0; k < 8; k++)
if (ci->progeny[k] != NULL)
engine_addtasks_send_gravity(e, ci->progeny[k], cj, t_grav);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add send tasks for the hydro pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param ci The sending #cell.
* @param cj Dummy cell containing the nodeID of the receiving node.
* @param t_xv The send_xv #task, if it has already been created.
* @param t_rho The send_rho #task, if it has already been created.
* @param t_gradient The send_gradient #task, if already created.
* @param t_prep1 The send_prep1 #task, if it has already been created.
* @param t_limiter The send_limiter #task, if it has already been created.
* @param with_feedback Are we running with stellar feedback?
* @param with_limiter Are we running with the time-step limiter?
* @param with_sync Are we running with time-step synchronization?
*/
void engine_addtasks_send_hydro(struct engine *e, struct cell *ci,
struct cell *cj, struct task *t_xv,
struct task *t_rho, struct task *t_gradient,
struct task *t_prep1, struct task *t_limiter,
struct task *t_pack_limiter,
const int with_feedback, const int with_limiter,
const int with_sync) {
#ifdef WITH_MPI
struct link *l = NULL;
struct scheduler *s = &e->sched;
const int nodeID = cj->nodeID;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(ci, cell_flag_has_tasks)) return;
/* Check if any of the density tasks are for the target node. */
for (l = ci->hydro.density; l != NULL; l = l->next)
if (l->t->ci->nodeID == nodeID ||
(l->t->cj != NULL && l->t->cj->nodeID == nodeID))
break;
/* If so, attach send tasks. */
if (l != NULL) {
/* Create the tasks and their dependencies? */
if (t_xv == NULL) {
/* Make sure this cell is tagged. */
cell_ensure_tagged(ci);
t_xv = scheduler_addtask(s, task_type_send, task_subtype_xv, ci->mpi.tag,
0, ci, cj);
t_rho = scheduler_addtask(s, task_type_send, task_subtype_rho,
ci->mpi.tag, 0, ci, cj);
#ifdef EXTRA_HYDRO_LOOP
t_gradient = scheduler_addtask(s, task_type_send, task_subtype_gradient,
ci->mpi.tag, 0, ci, cj);
#endif
if (with_limiter) {
t_limiter = scheduler_addtask(s, task_type_send, task_subtype_limiter,
ci->mpi.tag, 0, ci, cj);
t_pack_limiter = scheduler_addtask(s, task_type_pack,
task_subtype_limiter, 0, 0, ci, cj);
scheduler_addunlock(s, t_pack_limiter, t_limiter);
}
#ifdef EXTRA_STAR_LOOPS
if (with_feedback) {
t_prep1 = scheduler_addtask(s, task_type_send, task_subtype_part_prep1,
ci->mpi.tag, 0, ci, cj);
}
#endif
#ifdef EXTRA_HYDRO_LOOP
scheduler_addunlock(s, t_gradient, ci->hydro.super->hydro.end_force);
scheduler_addunlock(s, ci->hydro.super->hydro.extra_ghost, t_gradient);
/* The send_rho task should unlock the super_hydro-cell's extra_ghost
* task. */
scheduler_addunlock(s, t_rho, ci->hydro.super->hydro.extra_ghost);
/* The send_rho task depends on the cell's ghost task. */
scheduler_addunlock(s, ci->hydro.super->hydro.ghost_out, t_rho);
/* The send_xv task should unlock the super_hydro-cell's ghost task. */
scheduler_addunlock(s, t_xv, ci->hydro.super->hydro.ghost_in);
#else
/* The send_rho task should unlock the super_hydro-cell's kick task. */
scheduler_addunlock(s, t_rho, ci->hydro.super->hydro.end_force);
/* The send_rho task depends on the cell's ghost task. */
scheduler_addunlock(s, ci->hydro.super->hydro.ghost_out, t_rho);
/* The send_xv task should unlock the super_hydro-cell's ghost task. */
scheduler_addunlock(s, t_xv, ci->hydro.super->hydro.ghost_in);
#endif
scheduler_addunlock(s, ci->hydro.super->hydro.drift, t_rho);
/* Drift before you send */
scheduler_addunlock(s, ci->hydro.super->hydro.drift, t_xv);
if (with_limiter)
scheduler_addunlock(s, ci->super->timestep, t_pack_limiter);
#ifdef EXTRA_STAR_LOOPS
/* In stellar feedback, send gas parts only after they have finished their
* hydro ghosts */
if (with_feedback) {
scheduler_addunlock(s, ci->hydro.super->hydro.prep1_ghost, t_prep1);
scheduler_addunlock(s, t_prep1, ci->hydro.super->stars.prep2_ghost);
}
#endif
}
/* Add them to the local cell. */
engine_addlink(e, &ci->mpi.send, t_xv);
engine_addlink(e, &ci->mpi.send, t_rho);
#ifdef EXTRA_HYDRO_LOOP
engine_addlink(e, &ci->mpi.send, t_gradient);
#endif
if (with_limiter) {
engine_addlink(e, &ci->mpi.send, t_limiter);
engine_addlink(e, &ci->mpi.pack, t_pack_limiter);
}
#ifdef EXTRA_STAR_LOOPS
if (with_feedback) engine_addlink(e, &ci->mpi.send, t_prep1);
#endif
}
/* Recurse? */
if (ci->split)
for (int k = 0; k < 8; k++)
if (ci->progeny[k] != NULL)
engine_addtasks_send_hydro(
e, ci->progeny[k], cj, t_xv, t_rho, t_gradient, t_prep1, t_limiter,
t_pack_limiter, with_feedback, with_limiter, with_sync);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add send tasks for the stars pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param ci The sending #cell.
* @param cj Dummy cell containing the nodeID of the receiving node.
* @param t_density The send_density #task, if it has already been created.
* @param t_prep2 The send_prep2 #task, if it has already been created.
* @param t_sf_counts The send_sf_counts, if it has been created.
* @param with_star_formation Are we running with star formation on?
*/
void engine_addtasks_send_stars(struct engine *e, struct cell *ci,
struct cell *cj, struct task *t_density,
struct task *t_prep2, struct task *t_sf_counts,
const int with_star_formation) {
#ifdef SWIFT_DEBUG_CHECKS
if (e->policy & engine_policy_sinks && e->policy & engine_policy_stars) {
error("TODO");
}
#endif
#ifdef WITH_MPI
struct link *l = NULL;
struct scheduler *s = &e->sched;
const int nodeID = cj->nodeID;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(ci, cell_flag_has_tasks)) return;
if (t_sf_counts == NULL && with_star_formation && ci->hydro.count > 0) {
#ifdef SWIFT_DEBUG_CHECKS
if (ci->depth != 0)
error(
"Attaching a sf_count task at a non-top level c->depth=%d "
"c->count=%d",
ci->depth, ci->hydro.count);
#endif
t_sf_counts = scheduler_addtask(s, task_type_send, task_subtype_sf_counts,
ci->mpi.tag, 0, ci, cj);
scheduler_addunlock(s, ci->hydro.star_formation, t_sf_counts);
}
/* Check if any of the density tasks are for the target node. */
for (l = ci->stars.density; l != NULL; l = l->next)
if (l->t->ci->nodeID == nodeID ||
(l->t->cj != NULL && l->t->cj->nodeID == nodeID))
break;
/* If so, attach send tasks. */
if (l != NULL) {
if (t_density == NULL) {
/* Make sure this cell is tagged. */
cell_ensure_tagged(ci);
/* Create the tasks and their dependencies? */
t_density =
scheduler_addtask(s, task_type_send, task_subtype_spart_density,
ci->mpi.tag, 0, ci, cj);
#ifdef EXTRA_STAR_LOOPS
t_prep2 = scheduler_addtask(s, task_type_send, task_subtype_spart_prep2,
ci->mpi.tag, 0, ci, cj);
#endif
#ifdef EXTRA_STAR_LOOPS
/* The first send_stars task should unlock prep1 ghost */
scheduler_addunlock(s, t_density, ci->hydro.super->stars.prep1_ghost);
/* Prep2 ghost before second send */
scheduler_addunlock(s, ci->hydro.super->stars.prep2_ghost, t_prep2);
/* The second send_stars task should unlock the super_cell's "end of star
* block" task. */
scheduler_addunlock(s, t_prep2, ci->hydro.super->stars.stars_out);
#else
/* The send_stars task should unlock the super_cell's "end of star block"
* task. */
scheduler_addunlock(s, t_density, ci->hydro.super->stars.stars_out);
#endif
/* Density ghost before first send */
scheduler_addunlock(s, ci->hydro.super->stars.density_ghost, t_density);
/* Drift before first send */
scheduler_addunlock(s, ci->hydro.super->stars.drift, t_density);
if (with_star_formation && ci->hydro.count > 0) {
scheduler_addunlock(s, t_sf_counts, t_density);
#ifdef EXTRA_STAR_LOOPS
scheduler_addunlock(s, t_sf_counts, t_prep2);
#endif
}
}
engine_addlink(e, &ci->mpi.send, t_density);
#ifdef EXTRA_STAR_LOOPS
engine_addlink(e, &ci->mpi.send, t_prep2);
#endif
if (with_star_formation && ci->hydro.count > 0) {
engine_addlink(e, &ci->mpi.send, t_sf_counts);
}
}
/* Recurse? */
if (ci->split)
for (int k = 0; k < 8; k++)
if (ci->progeny[k] != NULL)
engine_addtasks_send_stars(e, ci->progeny[k], cj, t_density, t_prep2,
t_sf_counts, with_star_formation);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add send tasks for the black holes pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param ci The sending #cell.
* @param cj Dummy cell containing the nodeID of the receiving node.
* @param t_rho The density comm. task, if it has already been created.
* @param t_bh_merger The BH swallow comm. task, if it has already been created.
* @param t_gas_swallow The gas swallow comm. task, if it has already been
* created.
* @param t_feedback The send_feed #task, if it has already been created.
*/
void engine_addtasks_send_black_holes(struct engine *e, struct cell *ci,
struct cell *cj, struct task *t_rho,
struct task *t_bh_merger,
struct task *t_gas_swallow,
struct task *t_feedback) {
#ifdef WITH_MPI
struct link *l = NULL;
struct scheduler *s = &e->sched;
const int nodeID = cj->nodeID;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(ci, cell_flag_has_tasks)) return;
/* Check if any of the density tasks are for the target node. */
for (l = ci->black_holes.density; l != NULL; l = l->next)
if (l->t->ci->nodeID == nodeID ||
(l->t->cj != NULL && l->t->cj->nodeID == nodeID))
break;
/* If so, attach send tasks. */
if (l != NULL) {
if (t_rho == NULL) {
/* Make sure this cell is tagged. */
cell_ensure_tagged(ci);
/* Create the tasks and their dependencies? */
t_rho = scheduler_addtask(s, task_type_send, task_subtype_bpart_rho,
ci->mpi.tag, 0, ci, cj);
t_bh_merger = scheduler_addtask(
s, task_type_send, task_subtype_bpart_merger, ci->mpi.tag, 0, ci, cj);
t_gas_swallow = scheduler_addtask(
s, task_type_send, task_subtype_part_swallow, ci->mpi.tag, 0, ci, cj);
t_feedback =
scheduler_addtask(s, task_type_send, task_subtype_bpart_feedback,
ci->mpi.tag, 0, ci, cj);
/* The send_black_holes task should unlock the super_cell's BH exit point
* task. */
scheduler_addunlock(s, t_feedback,
ci->hydro.super->black_holes.black_holes_out);
scheduler_addunlock(s, ci->hydro.super->black_holes.swallow_ghost_2,
t_feedback);
/* Ghost before you send */
scheduler_addunlock(s, ci->hydro.super->black_holes.drift, t_rho);
scheduler_addunlock(s, ci->hydro.super->black_holes.density_ghost, t_rho);
scheduler_addunlock(s, t_rho,
ci->hydro.super->black_holes.swallow_ghost_0);
scheduler_addunlock(s, ci->hydro.super->black_holes.swallow_ghost_0,
t_bh_merger);
scheduler_addunlock(s, t_bh_merger,
ci->hydro.super->black_holes.swallow_ghost_2);
scheduler_addunlock(s, ci->hydro.super->black_holes.swallow_ghost_0,
t_gas_swallow);
scheduler_addunlock(s, t_gas_swallow,
ci->hydro.super->black_holes.swallow_ghost_1);
}
engine_addlink(e, &ci->mpi.send, t_rho);
engine_addlink(e, &ci->mpi.send, t_bh_merger);
engine_addlink(e, &ci->mpi.send, t_gas_swallow);
engine_addlink(e, &ci->mpi.send, t_feedback);
}
/* Recurse? */
if (ci->split)
for (int k = 0; k < 8; k++)
if (ci->progeny[k] != NULL)
engine_addtasks_send_black_holes(e, ci->progeny[k], cj, t_rho,
t_bh_merger, t_gas_swallow,
t_feedback);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add recv tasks for hydro pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param c The foreign #cell.
* @param t_xv The recv_xv #task, if it has already been created.
* @param t_rho The recv_rho #task, if it has already been created.
* @param t_gradient The recv_gradient #task, if it has already been created.
* @param t_prep1 The recv_prep1 #task, if it has already been created.
* @param t_limiter The recv_limiter #task, if it has already been created.
* @param t_unpack_limiter The unpack_limiter #task, if it has already been
* created.
* @param tend The top-level time-step communication #task.
* @param with_feedback Are we running with stellar feedback?
* @param with_black_holes Are we running with black holes?
* @param with_limiter Are we running with the time-step limiter?
* @param with_sync Are we running with time-step synchronization?
*/
void engine_addtasks_recv_hydro(
struct engine *e, struct cell *c, struct task *t_xv, struct task *t_rho,
struct task *t_gradient, struct task *t_prep1, struct task *t_limiter,
struct task *t_unpack_limiter, struct task *const tend,
const int with_feedback, const int with_black_holes, const int with_limiter,
const int with_sync) {
#ifdef WITH_MPI
struct scheduler *s = &e->sched;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(c, cell_flag_has_tasks)) return;
/* Have we reached a level where there are any hydro tasks ? */
if (t_xv == NULL && c->hydro.density != NULL) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure this cell has a valid tag. */
if (c->mpi.tag < 0) error("Trying to receive from untagged cell.");
#endif /* SWIFT_DEBUG_CHECKS */
/* Create the tasks. */
t_xv = scheduler_addtask(s, task_type_recv, task_subtype_xv, c->mpi.tag, 0,
c, NULL);
t_rho = scheduler_addtask(s, task_type_recv, task_subtype_rho, c->mpi.tag,
0, c, NULL);
scheduler_addunlock(s, t_xv, t_rho);
#ifdef EXTRA_HYDRO_LOOP
t_gradient = scheduler_addtask(s, task_type_recv, task_subtype_gradient,
c->mpi.tag, 0, c, NULL);
#endif
if (with_limiter) {
t_limiter = scheduler_addtask(s, task_type_recv, task_subtype_limiter,
c->mpi.tag, 0, c, NULL);
t_unpack_limiter = scheduler_addtask(s, task_type_unpack,
task_subtype_limiter, 0, 0, c, NULL);
scheduler_addunlock(s, t_limiter, t_unpack_limiter);
}
#ifdef EXTRA_STAR_LOOPS
if (with_feedback) {
t_prep1 = scheduler_addtask(s, task_type_recv, task_subtype_part_prep1,
c->mpi.tag, 0, c, NULL);
}
#endif
}
if (t_xv != NULL) {
engine_addlink(e, &c->mpi.recv, t_xv);
engine_addlink(e, &c->mpi.recv, t_rho);
#ifdef EXTRA_HYDRO_LOOP
engine_addlink(e, &c->mpi.recv, t_gradient);
#endif
if (with_limiter) {
engine_addlink(e, &c->mpi.recv, t_limiter);
engine_addlink(e, &c->mpi.unpack, t_unpack_limiter);
}
#ifdef EXTRA_STAR_LOOPS
if (with_feedback) engine_addlink(e, &c->mpi.recv, t_prep1);
#endif
/* Add dependencies. */
if (c->hydro.sorts != NULL) {
scheduler_addunlock(s, t_xv, c->hydro.sorts);
scheduler_addunlock(s, c->hydro.sorts, t_rho);
}
for (struct link *l = c->hydro.density; l != NULL; l = l->next) {
scheduler_addunlock(s, t_xv, l->t);
scheduler_addunlock(s, l->t, t_rho);
}
#ifdef EXTRA_HYDRO_LOOP
for (struct link *l = c->hydro.gradient; l != NULL; l = l->next) {
scheduler_addunlock(s, t_rho, l->t);
scheduler_addunlock(s, l->t, t_gradient);
}
for (struct link *l = c->hydro.force; l != NULL; l = l->next) {
scheduler_addunlock(s, t_gradient, l->t);
scheduler_addunlock(s, l->t, tend);
}
#else
for (struct link *l = c->hydro.force; l != NULL; l = l->next) {
scheduler_addunlock(s, t_rho, l->t);
scheduler_addunlock(s, l->t, tend);
}
#endif
if (with_limiter) {
for (struct link *l = c->hydro.limiter; l != NULL; l = l->next) {
scheduler_addunlock(s, t_unpack_limiter, l->t);
}
}
/* Make sure the gas density has been computed before the
* stars compute theirs. */
if (with_feedback) {
for (struct link *l = c->stars.density; l != NULL; l = l->next) {
scheduler_addunlock(s, t_rho, l->t);
}
}
#ifdef EXTRA_STAR_LOOPS
if (with_feedback) {
/* Receive gas parts after everything is finished in prep1 loop */
for (struct link *l = c->stars.prepare1; l != NULL; l = l->next) {
scheduler_addunlock(s, l->t, t_prep1);
}
/* Start updating stars in prep2 only after the updated gas parts have
* been received */
for (struct link *l = c->stars.prepare2; l != NULL; l = l->next) {
scheduler_addunlock(s, t_prep1, l->t);
}
}
#endif
/* Make sure the part have been received before the BHs compute their
* accretion rates (depends on particles' rho). */
if (with_black_holes) {
for (struct link *l = c->black_holes.density; l != NULL; l = l->next) {
/* t_rho is not activated for cells with no active hydro, so we need
to add an additional dependency on t_xv for these cells */
scheduler_addunlock(s, t_xv, l->t);
scheduler_addunlock(s, t_rho, l->t);
}
}
}
/* Recurse? */
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_addtasks_recv_hydro(e, c->progeny[k], t_xv, t_rho, t_gradient,
t_prep1, t_limiter, t_unpack_limiter, tend,
with_feedback, with_black_holes,
with_limiter, with_sync);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add recv tasks for stars pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param c The foreign #cell.
* @param t_density The recv_density #task, if it has already been created.
* @param t_prep2 The recv_prep2 #task, if it has already been created.
* @param t_sf_counts The recv_sf_counts, if it has been created.
* @param tend The top-level time-step communication #task.
* @param with_star_formation Are we running with star formation on?
*/
void engine_addtasks_recv_stars(struct engine *e, struct cell *c,
struct task *t_density, struct task *t_prep2,
struct task *t_sf_counts,
struct task *const tend,
const int with_star_formation) {
#ifdef SWIFT_DEBUG_CHECKS
if (e->policy & engine_policy_sinks && e->policy & engine_policy_stars) {
error("TODO");
}
#endif
#ifdef WITH_MPI
struct scheduler *s = &e->sched;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(c, cell_flag_has_tasks)) return;
if (t_sf_counts == NULL && with_star_formation && c->hydro.count > 0) {
#ifdef SWIFT_DEBUG_CHECKS
if (c->depth != 0)
error(
"Attaching a sf_count task at a non-top level c->depth=%d "
"c->count=%d",
c->depth, c->hydro.count);
#endif
t_sf_counts = scheduler_addtask(s, task_type_recv, task_subtype_sf_counts,
c->mpi.tag, 0, c, NULL);
}
/* Have we reached a level where there are any stars tasks ? */
if (t_density == NULL && c->stars.density != NULL) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure this cell has a valid tag. */
if (c->mpi.tag < 0) error("Trying to receive from untagged cell.");
#endif // SWIFT_DEBUG_CHECKS
/* Create the tasks. */
t_density = scheduler_addtask(s, task_type_recv, task_subtype_spart_density,
c->mpi.tag, 0, c, NULL);
#ifdef EXTRA_STAR_LOOPS
t_prep2 = scheduler_addtask(s, task_type_recv, task_subtype_spart_prep2,
c->mpi.tag, 0, c, NULL);
#endif
if (with_star_formation && c->hydro.count > 0) {
/* Receive the stars only once the counts have been received */
scheduler_addunlock(s, t_sf_counts, c->stars.sorts);
scheduler_addunlock(s, t_sf_counts, t_density);
#ifdef EXTRA_STAR_LOOPS
scheduler_addunlock(s, t_sf_counts, t_prep2);
#endif
}
}
if (t_density != NULL) {
engine_addlink(e, &c->mpi.recv, t_density);
#ifdef EXTRA_STAR_LOOPS
engine_addlink(e, &c->mpi.recv, t_prep2);
#endif
if (with_star_formation && c->hydro.count > 0) {
engine_addlink(e, &c->mpi.recv, t_sf_counts);
}
#ifdef SWIFT_DEBUG_CHECKS
if (c->nodeID == e->nodeID) error("Local cell!");
#endif
if (c->stars.sorts != NULL) {
scheduler_addunlock(s, t_density, c->stars.sorts);
#ifdef EXTRA_STAR_LOOPS
scheduler_addunlock(s, c->stars.sorts, t_prep2);
#endif
}
/* Receive stars after the density loop */
for (struct link *l = c->stars.density; l != NULL; l = l->next) {
scheduler_addunlock(s, l->t, t_density);
}
#ifdef EXTRA_STAR_LOOPS
/* Start updating local gas only after sparts have been received */
for (struct link *l = c->stars.prepare1; l != NULL; l = l->next) {
scheduler_addunlock(s, t_density, l->t);
scheduler_addunlock(s, l->t, t_prep2);
}
/* Receive stars for the second time after the prep2 loop */
for (struct link *l = c->stars.prepare2; l != NULL; l = l->next) {
scheduler_addunlock(s, l->t, t_prep2);
}
/* Start updating local gas only after sparts have been received */
for (struct link *l = c->stars.feedback; l != NULL; l = l->next) {
scheduler_addunlock(s, t_prep2, l->t);
scheduler_addunlock(s, l->t, tend);
}
#else
/* Start updating local gas only after sparts have been received */
for (struct link *l = c->stars.feedback; l != NULL; l = l->next) {
scheduler_addunlock(s, t_density, l->t);
scheduler_addunlock(s, l->t, tend);
}
#endif
}
/* Recurse? */
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_addtasks_recv_stars(e, c->progeny[k], t_density, t_prep2,
t_sf_counts, tend, with_star_formation);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add recv tasks for black_holes pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param c The foreign #cell.
* @param t_rho The density comm. task, if it has already been created.
* @param t_bh_merger The BH swallow comm. task, if it has already been created.
* @param t_gas_swallow The gas swallow comm. task, if it has already been
* created.
* @param t_feedback The recv_feed #task, if it has already been created.
* @param tend The top-level time-step communication #task.
*/
void engine_addtasks_recv_black_holes(struct engine *e, struct cell *c,
struct task *t_rho,
struct task *t_bh_merger,
struct task *t_gas_swallow,
struct task *t_feedback,
struct task *const tend) {
#ifdef WITH_MPI
struct scheduler *s = &e->sched;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(c, cell_flag_has_tasks)) return;
/* Have we reached a level where there are any black_holes tasks ? */
if (t_rho == NULL && c->black_holes.density != NULL) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure this cell has a valid tag. */
if (c->mpi.tag < 0) error("Trying to receive from untagged cell.");
#endif // SWIFT_DEBUG_CHECKS
/* Create the tasks. */
t_rho = scheduler_addtask(s, task_type_recv, task_subtype_bpart_rho,
c->mpi.tag, 0, c, NULL);
t_bh_merger = scheduler_addtask(
s, task_type_recv, task_subtype_bpart_merger, c->mpi.tag, 0, c, NULL);
t_gas_swallow = scheduler_addtask(
s, task_type_recv, task_subtype_part_swallow, c->mpi.tag, 0, c, NULL);
t_feedback = scheduler_addtask(
s, task_type_recv, task_subtype_bpart_feedback, c->mpi.tag, 0, c, NULL);
}
if (t_rho != NULL) {
engine_addlink(e, &c->mpi.recv, t_rho);
engine_addlink(e, &c->mpi.recv, t_bh_merger);
engine_addlink(e, &c->mpi.recv, t_gas_swallow);
engine_addlink(e, &c->mpi.recv, t_feedback);
#ifdef SWIFT_DEBUG_CHECKS
if (c->nodeID == e->nodeID) error("Local cell!");
#endif
for (struct link *l = c->black_holes.density; l != NULL; l = l->next) {
scheduler_addunlock(s, l->t, t_rho);
}
for (struct link *l = c->hydro.force; l != NULL; l = l->next) {
scheduler_addunlock(s, l->t, t_gas_swallow);
}
for (struct link *l = c->black_holes.swallow; l != NULL; l = l->next) {
scheduler_addunlock(s, t_rho, l->t);
scheduler_addunlock(s, l->t, t_gas_swallow);
scheduler_addunlock(s, l->t, t_bh_merger);
}
for (struct link *l = c->black_holes.do_gas_swallow; l != NULL;
l = l->next) {
scheduler_addunlock(s, t_gas_swallow, l->t);
}
for (struct link *l = c->black_holes.do_bh_swallow; l != NULL;
l = l->next) {
scheduler_addunlock(s, t_bh_merger, l->t);
scheduler_addunlock(s, l->t, t_feedback);
}
for (struct link *l = c->black_holes.feedback; l != NULL; l = l->next) {
scheduler_addunlock(s, t_feedback, l->t);
scheduler_addunlock(s, l->t, tend);
}
}
/* Recurse? */
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_addtasks_recv_black_holes(e, c->progeny[k], t_rho, t_bh_merger,
t_gas_swallow, t_feedback, tend);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Add recv tasks for gravity pairs to a hierarchy of cells.
*
* @param e The #engine.
* @param c The foreign #cell.
* @param t_grav The recv_gpart #task, if it has already been created.
* @param tend The top-level time-step communication #task.
*/
void engine_addtasks_recv_gravity(struct engine *e, struct cell *c,
struct task *t_grav,
struct task *const tend) {
#ifdef WITH_MPI
struct scheduler *s = &e->sched;
/* Early abort (are we below the level where tasks are)? */
if (!cell_get_flag(c, cell_flag_has_tasks)) return;
/* Have we reached a level where there are any gravity tasks ? */
if (t_grav == NULL && c->grav.grav != NULL) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure this cell has a valid tag. */
if (c->mpi.tag < 0) error("Trying to receive from untagged cell.");
#endif // SWIFT_DEBUG_CHECKS
/* Create the tasks. */
t_grav = scheduler_addtask(s, task_type_recv, task_subtype_gpart,
c->mpi.tag, 0, c, NULL);
}
/* If we have tasks, link them. */
if (t_grav != NULL) {
engine_addlink(e, &c->mpi.recv, t_grav);
for (struct link *l = c->grav.grav; l != NULL; l = l->next) {
scheduler_addunlock(s, t_grav, l->t);
scheduler_addunlock(s, l->t, tend);
}
}
/* Recurse? */
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
engine_addtasks_recv_gravity(e, c->progeny[k], t_grav, tend);
#else
error("SWIFT was not compiled with MPI support.");
#endif
}
/**
* @brief Generate the hydro hierarchical tasks for a hierarchy of cells -
* i.e. all the O(Npart) tasks -- timestep version
*
* Tasks are only created here. The dependencies will be added later on.
*
* Note that there is no need to recurse below the super-cell. Note also
* that we only add tasks if the relevant particles are present in the cell.
*
* @param e The #engine.
* @param c The #cell.
*/
void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
struct scheduler *s = &e->sched;
const int with_sinks = (e->policy & engine_policy_sinks);
const int with_stars = (e->policy & engine_policy_stars);
const int with_star_formation = (e->policy & engine_policy_star_formation);
const int with_star_formation_sink = with_sinks && with_stars;
const int with_timestep_limiter =
(e->policy & engine_policy_timestep_limiter);
const int with_timestep_sync = (e->policy & engine_policy_timestep_sync);
#ifdef WITH_CSDS
const int with_csds = e->policy & engine_policy_csds;
#endif
/* Are we at the top-level? */
if (c->top == c && c->nodeID == e->nodeID) {
if (c->hydro.count > 0 || c->grav.count > 0 || c->stars.count > 0 ||
c->black_holes.count > 0 || c->sinks.count > 0) {
c->timestep_collect = scheduler_addtask(s, task_type_collect,
task_subtype_none, 0, 0, c, NULL);
}
if (with_star_formation && c->hydro.count > 0) {
c->hydro.star_formation = scheduler_addtask(
s, task_type_star_formation, task_subtype_none, 0, 0, c, NULL);
}
if (with_star_formation_sink &&
(c->hydro.count > 0 || c->sinks.count > 0)) {
c->hydro.star_formation_sink = scheduler_addtask(
s, task_type_star_formation_sink, task_subtype_none, 0, 0, c, NULL);
}
if (with_sinks) {
/* hydro.sink_formation plays the role of a ghost => always created when
* playing with sinks*/
c->hydro.sink_formation = scheduler_addtask(
s, task_type_sink_formation, task_subtype_none, 0, 0, c, NULL);
}
}
/* Are we in a super-cell ? */
if (c->super == c) {
/* Local tasks only... */
if (c->nodeID == e->nodeID) {
/* Add the two half kicks */
c->kick1 = scheduler_addtask(s, task_type_kick1, task_subtype_none, 0, 0,
c, NULL);
c->kick2 = scheduler_addtask(s, task_type_kick2, task_subtype_none, 0, 0,
c, NULL);
/* Weighting task for neutrinos after the last kick */
if (e->neutrino_properties->use_delta_f) {
c->grav.neutrino_weight = scheduler_addtask(
s, task_type_neutrino_weight, task_subtype_none, 0, 0, c, NULL);
scheduler_addunlock(s, c->kick1, c->grav.neutrino_weight);
}
#if defined(WITH_CSDS)
struct task *kick2_or_csds;