MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Typedefs | Functions
domain.h File Reference
#include <mpi.h>
#include "utils/peano.h"
#include "utils/paramset.h"
#include "drift.h"
Include dependency graph for domain.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  topnode_data
 
struct  topleaf_data
 
struct  task_data
 
struct  DomainDecomp
 
struct  DomainParams
 

Typedefs

typedef struct DomainDecomp DomainDecomp
 
typedef struct DomainParams DomainParams
 

Functions

void set_domain_params (ParameterSet *ps)
 
void set_domain_par (DomainParams dp)
 
void domain_decompose_full (DomainDecomp *ddecomp)
 
void domain_maintain (DomainDecomp *ddecomp, struct DriftData *drift)
 
static int domain_get_topleaf (const peano_t key, const DomainDecomp *ddecomp)
 
void domain_free (DomainDecomp *ddecomp)
 

Typedef Documentation

◆ DomainDecomp

typedef struct DomainDecomp DomainDecomp

◆ DomainParams

typedef struct DomainParams DomainParams

Function Documentation

◆ domain_decompose_full()

void domain_decompose_full ( DomainDecomp ddecomp)

This is the main routine for the domain decomposition. It acts as a driver routine that allocates various temporary buffers, maps the particles back onto the periodic box if needed, and then does the domain decomposition, and a final Peano-Hilbert order of all particles as a tuning measure.

Definition at line 155 of file domain.c.

156 {
157  static DomainDecompositionPolicy policies[16];
158  static int Npolicies = 0;
159 
160  /* start from last successful policy to avoid retries */
161  static int LastSuccessfulPolicy = 0;
162 
163  if (Npolicies == 0) {
164  const int NincreaseAlloc = 16;
165  Npolicies = domain_policies_init(policies, NincreaseAlloc, 4);
166  }
167 
168  walltime_measure("/Misc");
169 
170  message(0, "domain decomposition... (presently allocated=%g MB)\n", mymalloc_usedbytes() / (1024.0 * 1024.0));
171 
172  int decompose_failed = 1;
173  int i;
174  for(i = LastSuccessfulPolicy; i < Npolicies; i ++)
175  {
176  domain_free(ddecomp);
177 
178 #ifdef DEBUG
180 #endif
181  int MaxTopNodes = domain_allocate(ddecomp, &policies[i]);
182 
183  message(0, "Attempting new domain decomposition policy: TopNodeAllocFactor=%g, UseglobalSort=%d, SubSampleDistance=%d UsePreSort=%d\n",
184  policies[i].TopNodeAllocFactor, policies[i].UseGlobalSort, policies[i].SubSampleDistance, policies[i].PreSort);
185 
186  decompose_failed = domain_attempt_decompose(ddecomp, &policies[i], MaxTopNodes);
187  decompose_failed = MPIU_Any(decompose_failed, ddecomp->DomainComm);
188 
189  if(decompose_failed)
190  continue;
191 
192  LastSuccessfulPolicy = i;
193  if(domain_balance(ddecomp) == 0)
194  break;
195  }
196 
197  if(decompose_failed) {
198  endrun(0, "No suitable domain decomposition policy worked for this particle distribution\n");
199  }
200 
201  /* copy the used nodes from temp to the true. */
202  struct topleaf_data * OldTopLeaves = ddecomp->TopLeaves;
203  struct topnode_data * OldTopNodes = ddecomp->TopNodes;
204 
205  ddecomp->TopNodes = (struct topnode_data *) mymalloc2("TopNodes", sizeof(ddecomp->TopNodes[0]) * ddecomp->NTopNodes);
206  /* add 1 extra to mark the end of TopLeaves; see assign */
207  ddecomp->TopLeaves = (struct topleaf_data *) mymalloc2("TopLeaves", sizeof(ddecomp->TopLeaves[0]) * (ddecomp->NTopLeaves + 1));
208 
209  memcpy(ddecomp->TopLeaves, OldTopLeaves, ddecomp->NTopLeaves* sizeof(ddecomp->TopLeaves[0]));
210  memcpy(ddecomp->TopNodes, OldTopNodes, ddecomp->NTopNodes * sizeof(ddecomp->TopNodes[0]));
211 
212  /* no longer useful */
213  myfree(OldTopLeaves);
214  myfree(OldTopNodes);
215 
216  if(domain_exchange(domain_layoutfunc, ddecomp, 0, NULL, PartManager, SlotsManager, 10000, ddecomp->DomainComm))
217  endrun(1929,"Could not exchange particles\n");
218 
219  /*Do a garbage collection so that the slots are ordered
220  *the same as the particles, garbage is at the end and all particles are in peano order.*/
222 
223  /*Ensure collective*/
224  MPIU_Barrier(ddecomp->DomainComm);
225  message(0, "Domain decomposition done.\n");
226 
227  report_memory_usage("DOMAIN");
228 
229  walltime_measure("/Domain/PeanoSort");
230 }
void domain_free(DomainDecomp *ddecomp)
Definition: domain.c:320
static int domain_balance(DomainDecomp *ddecomp)
Definition: domain.c:400
static int domain_attempt_decompose(DomainDecomp *ddecomp, DomainDecompositionPolicy *policy, const int MaxTopNodes)
Definition: domain.c:338
static int domain_layoutfunc(int n, const void *userdata)
Definition: domain.c:707
static int domain_allocate(DomainDecomp *ddecomp, DomainDecompositionPolicy *policy)
Definition: domain.c:285
static int domain_policies_init(DomainDecompositionPolicy policies[], const int NincreaseAlloc, const int SwitchToGlobal)
Definition: domain.c:252
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
void domain_test_id_uniqueness(struct part_manager_type *pman)
Definition: exchange.c:570
int domain_exchange(ExchangeLayoutFunc layoutfunc, const void *layout_userdata, int do_gc, struct DriftData *drift, struct part_manager_type *pman, struct slots_manager_type *sman, int maxiter, MPI_Comm Comm)
Definition: exchange.c:103
#define mymalloc2(name, size)
Definition: mymalloc.h:16
#define mymalloc_usedbytes()
Definition: mymalloc.h:32
#define myfree(x)
Definition: mymalloc.h:19
#define report_memory_usage(x)
Definition: mymalloc.h:30
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
void slots_gc_sorted(struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:442
struct topnode_data * TopNodes
Definition: domain.h:36
MPI_Comm DomainComm
Definition: domain.h:44
int NTopNodes
Definition: domain.h:39
struct topleaf_data * TopLeaves
Definition: domain.h:37
int NTopLeaves
Definition: domain.h:40
int MPIU_Any(int condition, MPI_Comm comm)
Definition: system.c:545
#define MPIU_Barrier(comm)
Definition: system.h:103
#define walltime_measure(name)
Definition: walltime.h:8

References domain_allocate(), domain_attempt_decompose(), domain_balance(), domain_exchange(), domain_free(), domain_layoutfunc(), domain_policies_init(), domain_test_id_uniqueness(), DomainDecomp::DomainComm, endrun(), message(), MPIU_Any(), MPIU_Barrier, myfree, mymalloc2, mymalloc_usedbytes, DomainDecomp::NTopLeaves, DomainDecomp::NTopNodes, PartManager, report_memory_usage, slots_gc_sorted(), SlotsManager, DomainDecomp::TopLeaves, DomainDecomp::TopNodes, and walltime_measure.

Referenced by begrun(), do_force_test(), domain_maintain(), run(), run_gravity_test(), runfof(), runpower(), and test_fof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ domain_free()

void domain_free ( DomainDecomp ddecomp)

Definition at line 320 of file domain.c.

321 {
322  if(ddecomp->domain_allocated_flag)
323  {
324  myfree(ddecomp->TopLeaves);
325  myfree(ddecomp->TopNodes);
326  myfree(ddecomp->Tasks);
327  ddecomp->domain_allocated_flag = 0;
328  }
329 }
struct task_data * Tasks
Definition: domain.h:41
int domain_allocated_flag
Definition: domain.h:34

References DomainDecomp::domain_allocated_flag, myfree, DomainDecomp::Tasks, DomainDecomp::TopLeaves, and DomainDecomp::TopNodes.

Referenced by begrun(), do_force_test(), domain_decompose_full(), and run_gravity_test().

Here is the caller graph for this function:

◆ domain_get_topleaf()

static int domain_get_topleaf ( const peano_t  key,
const DomainDecomp ddecomp 
)
inlinestatic

This function determines the TopLeaves entry for the given key.

Definition at line 74 of file domain.h.

74  {
75  int no=0;
76  while(ddecomp->TopNodes[no].Daughter >= 0)
77  no = ddecomp->TopNodes[no].Daughter + ((key - ddecomp->TopNodes[no].StartKey) >> (ddecomp->TopNodes[no].Shift - 3));
78  no = ddecomp->TopNodes[no].Leaf;
79  return no;
80 };
peano_t StartKey
Definition: domain.h:14
int Leaf
Definition: domain.h:17
int Daughter
Definition: domain.h:15
int Shift
Definition: domain.h:16

References topnode_data::Daughter, topnode_data::Leaf, topnode_data::Shift, topnode_data::StartKey, and DomainDecomp::TopNodes.

Referenced by domain_compute_costs(), domain_layoutfunc(), and force_tree_create_nodes().

Here is the caller graph for this function:

◆ domain_maintain()

void domain_maintain ( DomainDecomp ddecomp,
struct DriftData drift 
)

Definition at line 234 of file domain.c.

235 {
236  message(0, "Attempting a domain exchange\n");
237 
238  walltime_measure("/Misc");
239 
240  /* Try a domain exchange.
241  * If we have no memory for the particles,
242  * bail and do a full domain*/
243  if(0 != domain_exchange(domain_layoutfunc, ddecomp, 0, drift, PartManager, SlotsManager, 10000, ddecomp->DomainComm)) {
244  domain_decompose_full(ddecomp);
245  return;
246  }
247 }
void domain_decompose_full(DomainDecomp *ddecomp)
Definition: domain.c:155

References domain_decompose_full(), domain_exchange(), domain_layoutfunc(), DomainDecomp::DomainComm, message(), PartManager, SlotsManager, and walltime_measure.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_domain_par()

void set_domain_par ( DomainParams  dp)

Definition at line 78 of file domain.c.

79 {
80  domain_params = dp;
81 }
static DomainParams domain_params
Definition: domain.c:43

References domain_params.

Referenced by setup_tree(), and test_fof().

Here is the caller graph for this function:

◆ set_domain_params()

void set_domain_params ( ParameterSet ps)

Definition at line 84 of file domain.c.

85 {
86  int ThisTask;
87  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
88  if(ThisTask == 0) {
89  domain_params.DomainOverDecompositionFactor = param_get_int(ps, "DomainOverDecompositionFactor");
90  /* Create one domain per thread. This helps the balance and makes the treebuild merge faster*/
92  domain_params.DomainOverDecompositionFactor = omp_get_max_threads();
95  domain_params.TopNodeAllocFactor = param_get_double(ps, "TopNodeAllocFactor");
96  domain_params.DomainUseGlobalSorting = param_get_int(ps, "DomainUseGlobalSorting");
98  if((param_get_int(ps, "StarformationOn") && param_get_double(ps, "QuickLymanAlphaProbability") == 0.)
99  || param_get_int(ps, "BlackHoleOn"))
101  }
102  MPI_Bcast(&domain_params, sizeof(DomainParams), MPI_BYTE, 0, MPI_COMM_WORLD);
103 }
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
int DomainOverDecompositionFactor
Definition: domain.h:53
int DomainUseGlobalSorting
Definition: domain.h:55
double TopNodeAllocFactor
Definition: domain.h:57
double SetAsideFactor
Definition: domain.h:59
int ThisTask
Definition: test_exchange.c:23

References domain_params, DomainParams::DomainOverDecompositionFactor, DomainParams::DomainUseGlobalSorting, param_get_double(), param_get_int(), DomainParams::SetAsideFactor, ThisTask, and DomainParams::TopNodeAllocFactor.

Referenced by read_parameter_file().

Here is the call graph for this function:
Here is the caller graph for this function: