task.h 5.18 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 "cell.h"
31
#include "cycle.h"
32

33
#define task_align 128
34

35
36
/**
 * @brief The different task types.
Pedro Gonnet's avatar
Pedro Gonnet committed
37
38
 *
 * Be sure to update the taskID_names array in tasks.c if you modify this list!
39
 * Also update the python task plotting scripts!
40
 */
41
enum task_types {
42
43
44
45
  task_type_none = 0,
  task_type_sort,
  task_type_self,
  task_type_pair,
46
47
  task_type_sub_self,
  task_type_sub_pair,
48
  task_type_init_grav,
49
50
  task_type_init_grav_out, /* Implicit */
  task_type_ghost_in,      /* Implicit */
51
  task_type_ghost,
52
  task_type_ghost_out, /* Implicit */
53
  task_type_extra_ghost,
54
55
  task_type_drift_part,
  task_type_drift_gpart,
56
  task_type_drift_gpart_out, /* Implicit */
57
  task_type_end_force,
58
59
  task_type_kick1,
  task_type_kick2,
60
  task_type_timestep,
61
62
  task_type_send,
  task_type_recv,
63
  task_type_grav_long_range,
64
  task_type_grav_mm,
65
  task_type_grav_down_in, /* Implicit */
66
  task_type_grav_down,
67
  task_type_grav_mesh,
68
  task_type_cooling,
Matthieu Schaller's avatar
Matthieu Schaller committed
69
  task_type_star_formation,
70
  task_type_logger,
71
72
73
  task_type_stars_ghost_in,
  task_type_stars_ghost,
  task_type_stars_ghost_out,
Loic Hausammann's avatar
Loic Hausammann committed
74
  task_type_stars_sort,
75
  task_type_count
76
} __attribute__((packed));
77

78
79
80
/**
 * @brief The different task sub-types (for pairs, selfs and sub-tasks).
 */
81
enum task_subtypes {
82
83
  task_subtype_none = 0,
  task_subtype_density,
84
  task_subtype_gradient,
85
86
  task_subtype_force,
  task_subtype_grav,
87
  task_subtype_external_grav,
88
  task_subtype_tend,
89
  task_subtype_xv,
90
  task_subtype_rho,
91
  task_subtype_gpart,
92
  task_subtype_multipole,
93
  task_subtype_spart,
94
  task_subtype_stars_density,
Alexei Borissov's avatar
Alexei Borissov committed
95
  task_subtype_stars_feedback,
96
  task_subtype_count
97
} __attribute__((packed));
98

99
100
101
/**
 * @brief The type of particles/objects this task acts upon in a given cell.
 */
102
103
104
105
enum task_actions {
  task_action_none,
  task_action_part,
  task_action_gpart,
Loic Hausammann's avatar
Loic Hausammann committed
106
  task_action_spart,
107
108
109
110
111
  task_action_all,
  task_action_multipole,
  task_action_count
};

112
113
114
115
116
117
118
119
/**
 * @brief Names of the task types.
 */
extern const char *taskID_names[];

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

122
123
124
125
126
127
128
/**
 *  @brief The MPI communicators for the different subtypes.
 */
#ifdef WITH_MPI
extern MPI_Comm subtaskMPI_comms[task_subtype_count];
#endif

129
130
131
/**
 * @brief A task to be run by the #scheduler.
 */
132
133
struct task {

134
135
  /*! Pointers to the cells this task acts upon */
  struct cell *ci, *cj;
136

137
138
139
  /*! List of tasks unlocked by this one */
  struct task **unlock_tasks;

140
141
142
  /*! Flags used to carry additional information (e.g. sort directions) */
  long long flags;

143
144
145
146
147
148
149
150
151
#ifdef WITH_MPI

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

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

#endif
152

153
154
155
156
  /*! Rank of a task in the order */
  int rank;

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

159
#if defined(WITH_MPI) && (defined(HAVE_METIS) || defined(HAVE_PARMETIS))
160
  /*! Individual cost estimate for this task. */
161
  float cost;
162
#endif
163
164

  /*! Number of tasks unlocked by this one */
165
  short int nr_unlock_tasks;
166

167
168
  /*! Number of unsatisfied dependencies */
  short int wait;
169

170
171
  /*! Type of the task */
  enum task_types type;
172

173
174
  /*! Sub-type of the task (for the tasks that have one */
  enum task_subtypes subtype;
175

176
177
178
179
180
  /*! 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
181

182
#ifdef SWIFT_DEBUG_TASKS
183
184
185
  /*! ID of the queue or runner owning this task */
  short int rid;

186
187
188
  /*! Information about the direction of the pair task */
  short int sid;

189
190
191
  /*! Start and end time of this task */
  ticks tic, toc;
#endif
192

193
194
195
196
197
#ifdef SWIFT_DEBUG_CHECKS
  /* When was this task last run? */
  integertime_t ti_run;
#endif /* SWIFT_DEBUG_CHECKS */

198
} SWIFT_STRUCT_ALIGN;
199
200

/* Function prototypes. */
201
void task_unlock(struct task *t);
202
float task_overlap(const struct task *ta, const struct task *tb);
203
int task_lock(struct task *t);
204
void task_do_rewait(struct task *t);
205
void task_print(const struct task *t);
206
207
208
#ifdef WITH_MPI
void task_create_mpi_comms(void);
#endif
209
#endif /* SWIFT_TASK_H */