task.h 6.54 KB
Newer Older
1
/*******************************************************************************
2
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
5
6
7
 *               2015 Peter W. Draper (p.w.draper@durham.ac.uk)
 *               2016 John A. Regan (john.a.regan@durham.ac.uk)
 *                    Tom Theuns (tom.theuns@durham.ac.uk)
8
 *
9
10
11
12
 * 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.
13
 *
14
15
16
17
 * 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.
18
 *
19
20
 * 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/>.
21
 *
22
 ******************************************************************************/
23
24
#ifndef SWIFT_TASK_H
#define SWIFT_TASK_H
25

26
27
#include "../config.h"

28
/* Includes. */
29
#include "align.h"
30
#include "cycle.h"
31
32
33
34
35
#include "timeline.h"

/* Forward declarations to avoid circular inclusion dependencies. */
struct cell;
struct engine;
36

37
#define task_align 128
38

39
40
/**
 * @brief The different task types.
Pedro Gonnet's avatar
Pedro Gonnet committed
41
42
 *
 * Be sure to update the taskID_names array in tasks.c if you modify this list!
43
 * Also update the python task plotting scripts!
44
 */
45
enum task_types {
46
47
48
49
  task_type_none = 0,
  task_type_sort,
  task_type_self,
  task_type_pair,
50
51
  task_type_sub_self,
  task_type_sub_pair,
52
  task_type_init_grav,
53
54
  task_type_init_grav_out, /* Implicit */
  task_type_ghost_in,      /* Implicit */
55
  task_type_ghost,
56
  task_type_ghost_out, /* Implicit */
57
  task_type_extra_ghost,
58
  task_type_drift_part,
59
  task_type_drift_spart,
60
  task_type_drift_bpart,
61
  task_type_drift_gpart,
62
  task_type_drift_gpart_out, /* Implicit */
63
  task_type_end_hydro_force,
64
65
  task_type_kick1,
  task_type_kick2,
66
  task_type_timestep,
67
  task_type_timestep_limiter,
68
  task_type_timestep_sync,
69
70
  task_type_send,
  task_type_recv,
71
  task_type_grav_long_range,
72
  task_type_grav_mm,
73
  task_type_grav_down_in, /* Implicit */
74
  task_type_grav_down,
75
  task_type_grav_mesh,
76
  task_type_end_grav_force,
77
  task_type_cooling,
Matthieu Schaller's avatar
Matthieu Schaller committed
78
  task_type_star_formation,
79
80
  task_type_star_formation_in,  /* Implicit */
  task_type_star_formation_out, /* Implicit */
81
  task_type_logger,
82
83
  task_type_stars_in,       /* Implicit */
  task_type_stars_out,      /* Implicit */
84
  task_type_stars_ghost_in, /* Implicit */
85
  task_type_stars_ghost,
86
  task_type_stars_ghost_out, /* Implicit */
Loic Hausammann's avatar
Loic Hausammann committed
87
  task_type_stars_sort,
88
  task_type_stars_resort,
89
90
  task_type_bh_in,  /* Implicit */
  task_type_bh_out, /* Implicit */
91
  task_type_bh_density_ghost,
92
  task_type_bh_swallow_ghost1, /* Implicit */
93
  task_type_bh_swallow_ghost2,
94
  task_type_bh_swallow_ghost3, /* Implicit */
James Willis's avatar
James Willis committed
95
96
  task_type_fof_self,
  task_type_fof_pair,
97
  task_type_count
98
} __attribute__((packed));
99

100
101
102
/**
 * @brief The different task sub-types (for pairs, selfs and sub-tasks).
 */
103
enum task_subtypes {
104
105
  task_subtype_none = 0,
  task_subtype_density,
106
  task_subtype_gradient,
107
  task_subtype_force,
108
  task_subtype_limiter,
109
  task_subtype_grav,
110
  task_subtype_external_grav,
111
112
113
  task_subtype_tend_part,
  task_subtype_tend_gpart,
  task_subtype_tend_spart,
114
  task_subtype_tend_bpart,
115
  task_subtype_xv,
116
  task_subtype_rho,
117
  task_subtype_part_swallow,
118
  task_subtype_bpart_merger,
119
  task_subtype_gpart,
120
  task_subtype_multipole,
121
  task_subtype_spart,
122
  task_subtype_stars_density,
Alexei Borissov's avatar
Alexei Borissov committed
123
  task_subtype_stars_feedback,
124
  task_subtype_sf_counts,
125
126
127
  task_subtype_bpart_rho,
  task_subtype_bpart_swallow,
  task_subtype_bpart_feedback,
128
  task_subtype_bh_density,
129
  task_subtype_bh_swallow,
130
131
  task_subtype_do_gas_swallow,
  task_subtype_do_bh_swallow,
132
  task_subtype_bh_feedback,
133
  task_subtype_count
134
} __attribute__((packed));
135

136
137
138
/**
 * @brief The type of particles/objects this task acts upon in a given cell.
 */
139
140
141
142
enum task_actions {
  task_action_none,
  task_action_part,
  task_action_gpart,
Loic Hausammann's avatar
Loic Hausammann committed
143
  task_action_spart,
144
  task_action_bpart,
145
146
147
148
149
  task_action_all,
  task_action_multipole,
  task_action_count
};

150
151
152
153
154
155
156
157
/**
 * @brief Names of the task types.
 */
extern const char *taskID_names[];

/**
 * @brief Names of the task sub-types.
 */
158
extern const char *subtaskID_names[];
159

160
161
162
163
164
165
166
/**
 *  @brief The MPI communicators for the different subtypes.
 */
#ifdef WITH_MPI
extern MPI_Comm subtaskMPI_comms[task_subtype_count];
#endif

167
168
169
/**
 * @brief A task to be run by the #scheduler.
 */
170
171
struct task {

172
173
  /*! Pointers to the cells this task acts upon */
  struct cell *ci, *cj;
174

175
176
177
  /*! List of tasks unlocked by this one */
  struct task **unlock_tasks;

178
179
180
  /*! Flags used to carry additional information (e.g. sort directions) */
  long long flags;

181
182
183
184
185
186
187
188
189
#ifdef WITH_MPI

  /*! Buffer for this task's communications */
  void *buff;

  /*! MPI request corresponding to this task */
  MPI_Request req;

#endif
190

191
192
193
194
  /*! Rank of a task in the order */
  int rank;

  /*! Weight of the task */
195
  float weight;
Pedro Gonnet's avatar
Pedro Gonnet committed
196

197
  /*! Number of tasks unlocked by this one */
198
  int nr_unlock_tasks;
199

200
  /*! Number of unsatisfied dependencies */
201
  int wait;
202

203
204
  /*! Type of the task */
  enum task_types type;
205

206
207
  /*! Sub-type of the task (for the tasks that have one */
  enum task_subtypes subtype;
208

209
210
211
212
213
  /*! Should the scheduler skip this task ? */
  char skip;

  /*! Is this task implicit (i.e. does not do anything) ? */
  char implicit;
Pedro Gonnet's avatar
Pedro Gonnet committed
214

215
#ifdef SWIFT_DEBUG_TASKS
216
217
218
  /*! ID of the queue or runner owning this task */
  short int rid;

219
220
  /*! Information about the direction of the pair task */
  short int sid;
221
#endif
222

223
224
  /*! Start and end time of this task */
  ticks tic, toc;
225

226
227
228
229
230
#ifdef SWIFT_DEBUG_CHECKS
  /* When was this task last run? */
  integertime_t ti_run;
#endif /* SWIFT_DEBUG_CHECKS */

231
} SWIFT_STRUCT_ALIGN;
232
233

/* Function prototypes. */
234
void task_unlock(struct task *t);
235
float task_overlap(const struct task *ta, const struct task *tb);
236
int task_lock(struct task *t);
237
void task_do_rewait(struct task *t);
238
void task_print(const struct task *t);
239
void task_dump_all(struct engine *e, int step);
Peter W. Draper's avatar
Peter W. Draper committed
240
241
void task_dump_stats(const char *dumpfile, struct engine *e, int header,
                     int allranks);
242
void task_dump_active(struct engine *e);
243
void task_get_full_name(int type, int subtype, char *name);
244
void task_get_group_name(int type, int subtype, char *cluster);
245

246
247
#ifdef WITH_MPI
void task_create_mpi_comms(void);
248
void task_free_mpi_comms(void);
249
#endif
250
#endif /* SWIFT_TASK_H */