GADGET-4
domain.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef ALLVARS_H
13#include "../data/allvars.h"
14#endif
15#ifndef DOMAIN_H
16#define DOMAIN_H
17
18#include "../data/dtypes.h"
19#include "../mpi_utils/setcomm.h"
20
22{
26};
27
28template <typename partset> /* partset will either be the 'simparticles' or the 'lightconeparticles' class is the matching
29 particle_data struct */
30class domain : public setcomm
31{
32 private:
33 partset *Tp;
34
35 public:
36 domain(MPI_Comm comm, partset *Tp_ptr) : setcomm(comm) /* constructor */
37 {
38 Tp = Tp_ptr;
39
40 ListOfTopleaves = NULL;
41 TaskOfLeaf = NULL;
42 TopNodes = NULL;
43 NumTopleafOfTask = NULL;
44 FirstTopleafOfTask = NULL;
45 }
46
47 typedef typename partset::pdata pdata;
48
49 public:
51
54
56
62
64
69 {
71 int Leaf;
72 };
73
75
82 void domain_allocate(void);
83 void domain_allocate(int maxtopnodes);
84 void domain_free(void);
85 void domain_resize_storage(int count_get, int count_get_sph, int option_flag);
86
87 size_t domain_sizeof_topnode_data(void) { return sizeof(topnode_data); }
88
89 private:
90 struct local_topnode_data
91 {
92 double Cost;
93 long long CountTot;
94 peanokey StartKey;
95 int Count;
96 int Level;
97 int PIndex;
98 };
99
100 struct domain_peano_hilbert_data
101 {
102 peanokey key;
103 float cost;
104 } * mp;
105
106 struct domain_cost_data
107 {
108 double Cost;
109 };
110
111 struct domain_count_data
112 {
113 int task;
114 int count;
115 int origintask;
116 };
117
118 struct domain_segments_data
119 {
120 int task, start, end, used;
121 double bin_GravCost[TIMEBINS];
122 double bin_HydroCost[TIMEBINS];
123 double load;
124 double loadsph;
125 };
126
127 // domain_segments_data *domainAssign;
128
129 domain_cost_data *domain_leaf_cost;
130
131 local_topnode_data *topNodes;
132
133 peanokey *domain_key;
134
135 int NumTimeBinsToBeBalanced;
136 int ListOfTimeBinsToBeBalanced[TIMEBINS];
137 double GravCostPerListedTimeBin[TIMEBINS];
138 double MaxGravCostPerListedTimeBin[TIMEBINS];
139 double GravCostNormFactors[TIMEBINS];
140 double HydroCostPerListedTimeBin[TIMEBINS];
141 double HydroCostNormFactors[TIMEBINS];
142 double NormFactorLoad;
143 double NormFactorLoadSph;
144 double TotalCost;
145
146 int domain_grav_weight[TIMEBINS];
147 int domain_hydro_weight[TIMEBINS];
148 int domain_to_be_balanced[TIMEBINS];
149
150 void domain_find_total_cost(void);
151 void domain_report_balance(void);
152 void domain_combine_multipledomains(void);
153 void domain_init_sum_cost(void);
154 void domain_countToGo(int *toGoDM, int *toGoSph);
155 void domain_exchange(void);
156 void domain_determineTopTree(void);
157
158 void domain_printf(char *buf);
159 void domain_rearrange_particle_sequence(void);
160
161 void do_box_wrapping(void);
162 void domain_coll_subfind_prepare_exchange(void);
163 void domain_do_local_refine(int n, int *list);
164 void domain_walktoptree(int no);
165 double domain_get_cost_summed_over_timebins(int i);
166
167 /* note: static here needed to suppress the hidden 'this' argument so that we can use this in a call of sort */
168 static bool domain_compare_count(const domain_count_data &a, const domain_count_data &b) { return a.count > b.count; }
169
170 static bool domain_compare_key(const domain_peano_hilbert_data &a, const domain_peano_hilbert_data &b) { return a.key < b.key; }
171
172 static bool domain_sort_candidates(const int &a, const int &b) { return a < b; }
173
174 struct cost_queue_data
175 {
176 double value;
177#ifdef SIMPLE_DOMAIN_AGGREGATION
178 double aggregated_value;
179#endif
180 int index;
181 };
182
183 static bool domain_sort_cost_queue_data(const cost_queue_data &a, const cost_queue_data &b)
184 {
185#ifdef SIMPLE_DOMAIN_AGGREGATION
186 if(a.aggregated_value > b.aggregated_value)
187 return true;
188 else if(a.aggregated_value < b.aggregated_value)
189 return false;
190#endif
191 return a.value > b.value;
192 }
193
194 void domain_determinate_aggregated_value(cost_queue_data *data, int ndomains);
195
196 inline int n_to_no(int n)
197 {
198 int no = 0;
199 peanokey key = domain_key[n];
200
201 while(TopNodes[no].Daughter >= 0)
202 {
203 unsigned int off = ((key.hs & (~((~((MyIntPosType)0)) >> 3))) >> (BITS_FOR_POSITIONS - 3));
204
205 no = TopNodes[no].Daughter + off;
206
207 key.hs <<= 3;
208 key.hs |= (key.is & (~((~((MyIntPosType)0)) >> 3))) >> (BITS_FOR_POSITIONS - 3);
209
210 key.is <<= 3;
211 key.is |= (key.ls & (~((~((MyIntPosType)0)) >> 3))) >> (BITS_FOR_POSITIONS - 3);
212
213 key.ls <<= 3;
214 }
215
216 return TopNodes[no].Leaf;
217 }
218
219 struct peano_hilbert_data
220 {
221 peanokey key;
222 int index;
223 };
224
225 static bool compare_peano_hilbert_data(const peano_hilbert_data &a, const peano_hilbert_data &b) { return a.key < b.key; }
226
227 void peano_hilbert_order(peanokey *key);
228
229 struct balance_try_data
230 {
231 int nextra;
232 double try_balance;
233 };
234
235 static bool domain_compare_trybalance(const balance_try_data &a, const balance_try_data &b) { return a.try_balance < b.try_balance; }
236
237 public:
238 void reorder_particles(int *Id, int Nstart, int N);
239 void reorder_gas(int *Id);
240 void reorder_PS(int *Id, int Nstart, int N);
241 void reorder_P_and_PS(int *Id);
242 void reorder_P_PS(int NumGas, int NumPart);
243
245
246 private:
247 struct local_sort_data
248 {
249 int targetindex;
250 int index;
251 };
252
253 static inline bool compare_local_sort_data_targetindex(const local_sort_data &a, const local_sort_data &b)
254 {
255 return a.targetindex < b.targetindex;
256 }
257
258#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(RANDOMIZE_DOMAINCENTER)
259 MyIntPosType domainInnersize;
260 MyIntPosType domainReferenceIntPos[3];
261 MySignedIntPosType domainXmintot[3], domainXmaxtot[3];
262
263 void domain_find_type_extension(void);
264 int domain_type_extension_overlap(int j);
265#endif
266
267#ifdef DOMAIN_SPECIAL_CHECK
268 void domain_special_check(int mode, int ndomains);
269#endif
270
271 void domain_printf(const char *fmt, ...)
272 {
273 if((Mode == STANDARD && ThisTask == 0)) // || (Mode == COLL_SUBFIND))
274 {
275 va_list l;
276 va_start(l, fmt);
277 vprintf(fmt, l);
278 // myflush(stdout);
279 va_end(l);
280 }
281 }
282};
283
284#endif
Definition: domain.h:31
void reorder_gas(int *Id)
void domain_free(void)
Definition: domain.cc:179
void reorder_PS(int *Id, int Nstart, int N)
int NTopnodes
Definition: domain.h:52
int * TaskOfLeaf
Definition: domain.h:63
void reorder_particles(int *Id, int Nstart, int N)
void particle_exchange_based_on_PS(MPI_Comm Communicator)
partset::pdata pdata
Definition: domain.h:47
void reorder_P_and_PS(int *Id)
int MultipleDomains
Definition: domain.h:55
void domain_allocate(void)
Definition: domain.cc:172
int NTopleaves
Definition: domain.h:53
void reorder_P_PS(int NumGas, int NumPart)
size_t domain_sizeof_topnode_data(void)
Definition: domain.h:87
domain(MPI_Comm comm, partset *Tp_ptr)
Definition: domain.h:36
int MaxTopNodes
Definition: domain.h:57
int * ListOfTopleaves
Definition: domain.h:59
topnode_data * TopNodes
Definition: domain.h:74
void domain_resize_storage(int count_get, int count_get_sph, int option_flag)
int * NumTopleafOfTask
Definition: domain.h:60
domain_options Mode
Definition: domain.h:50
void domain_decomposition(domain_options mode)
Definition: domain.cc:51
int * FirstTopleafOfTask
Definition: domain.h:61
MyIntPosType hs
Definition: dtypes.h:210
MyIntPosType is
Definition: dtypes.h:210
MyIntPosType ls
Definition: dtypes.h:210
int ThisTask
Definition: setcomm.h:33
MPI_Comm Communicator
Definition: setcomm.h:31
#define TIMEBINS
Definition: constants.h:332
domain_options
Definition: domain.h:22
@ COLL_SUBFIND
Definition: domain.h:24
@ STANDARD
Definition: domain.h:23
@ SERIAL_SUBFIND
Definition: domain.h:25
uint32_t MyIntPosType
Definition: dtypes.h:35
int32_t MySignedIntPosType
Definition: dtypes.h:36
#define BITS_FOR_POSITIONS
Definition: dtypes.h:37