MP-Gadget
5.0.1.dev1-76bc7d4726-dirty
|
code for domain decomposition More...
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <omp.h>
#include "utils.h"
#include "domain.h"
#include "timestep.h"
#include "timebinmgr.h"
#include "exchange.h"
#include "slotsmanager.h"
#include "partmanager.h"
#include "walltime.h"
#include "utils/paramset.h"
#include "utils/peano.h"
#include "utils/mpsort.h"
Go to the source code of this file.
Classes | |
struct | DomainDecompositionPolicy |
struct | local_topnode_data |
struct | local_particle_data |
struct | topleaf_extdata |
Macros | |
#define | TAG_GRAV_A 18 |
#define | TAG_GRAV_B 19 |
Functions | |
void | set_domain_par (DomainParams dp) |
void | set_domain_params (ParameterSet *ps) |
static int | order_by_key (const void *a, const void *b) |
static void | mp_order_by_key (const void *data, void *radix, void *arg) |
static void | domain_assign_balanced (DomainDecomp *ddecomp, int64_t *cost, const int NsegmentPerTask) |
static int | domain_allocate (DomainDecomp *ddecomp, DomainDecompositionPolicy *policy) |
static int | domain_check_memory_bound (const DomainDecomp *ddecomp, int64_t *TopLeafWork, int64_t *TopLeafCount) |
static int | domain_attempt_decompose (DomainDecomp *ddecomp, DomainDecompositionPolicy *policy, const int MaxTopNodes) |
static int | domain_balance (DomainDecomp *ddecomp) |
static int | domain_determine_global_toptree (DomainDecompositionPolicy *policy, struct local_topnode_data *topTree, int *topTreeSize, const int MaxTopNodes, MPI_Comm DomainComm) |
static void | domain_compute_costs (const DomainDecomp *ddecomp, int64_t *TopLeafWork, int64_t *TopLeafCount) |
static void | domain_toptree_merge (struct local_topnode_data *treeA, struct local_topnode_data *treeB, int noA, int noB, int *treeASize, const int MaxTopNodes) |
static int | domain_check_for_local_refine_subsample (DomainDecompositionPolicy *policy, struct local_topnode_data *topTree, int *topTreeSize, const int MaxTopNodes) |
static int | domain_global_refine (struct local_topnode_data *topTree, int *topTreeSize, const int MaxTopNodes, int64_t countlimit, int64_t costlimit) |
static void | domain_create_topleaves (DomainDecomp *ddecomp, int no, int *next) |
static int | domain_layoutfunc (int n, const void *userdata) |
static int | domain_policies_init (DomainDecompositionPolicy policies[], const int NincreaseAlloc, const int SwitchToGlobal) |
void | domain_decompose_full (DomainDecomp *ddecomp) |
void | domain_maintain (DomainDecomp *ddecomp, struct DriftData *drift) |
void | domain_free (DomainDecomp *ddecomp) |
static int | topleaf_ext_order_by_task_and_key (const void *c1, const void *c2) |
static int | topleaf_ext_order_by_key (const void *c1, const void *c2) |
static int | domain_toptree_get_subnode (struct local_topnode_data *topTree, peano_t key) |
static int | domain_toptree_insert (struct local_topnode_data *topTree, peano_t Key, int64_t cost) |
static int | domain_toptree_split (struct local_topnode_data *topTree, int *topTreeSize, const int MaxTopNodes, int i) |
static void | domain_toptree_update_cost (struct local_topnode_data *topTree, int start) |
static void | domain_toptree_truncate_r (struct local_topnode_data *topTree, int start, int64_t countlimit, int64_t costlimit) |
static void | domain_toptree_garbage_collection (struct local_topnode_data *topTree, int start, int *last_free) |
static void | domain_toptree_truncate (struct local_topnode_data *topTree, int *topTreeSize, int64_t countlimit, int64_t costlimit) |
static int | domain_nonrecursively_combine_topTree (struct local_topnode_data *topTree, int *topTreeSize, const int MaxTopNodes, MPI_Comm DomainComm) |
Variables | |
static DomainParams | domain_params |
code for domain decomposition
This file contains the code for the domain decomposition of the simulation volume. The domains are constructed from disjoint subsets of the leaves of a fiducial top-level tree that covers the full simulation volume. Domain boundaries hence run along tree-node divisions of a fiducial global BH tree. As a result of this method, the tree force are in principle strictly independent of the way the domains are cut. The domain decomposition can be carried out for an arbitrary number of CPUs. Individual domains are not cubical, but spatially coherent since the leaves are traversed in a Peano-Hilbert order and individual domains form segments along this order. This also ensures that each domain has a small surface to volume ratio, which minimizes communication.
Definition in file domain.c.
|
static |
This function allocates all the stuff that will be required for the tree-construction/walk later on
Definition at line 285 of file domain.c.
References DomainDecomp::domain_allocated_flag, DomainDecomp::DomainComm, part_manager_type::MaxPart, message(), mymalloc, mymalloc2, NTask, PartManager, DomainDecomp::Tasks, DomainDecomp::TopLeaves, DomainDecompositionPolicy::TopNodeAllocFactor, and DomainDecomp::TopNodes.
Referenced by domain_decompose_full().
|
static |
This function assigns TopLeaves to Segments, trying to ensure uniform cost by assigning TopLeaves (contiguously) until a Segment has a desired size. Then each Segment is assigned to a Task in a round-robin fashion starting from the largest Segment until all Segments are assigned. At the moment the Segment/Task distinction is not used: we call this with NSegmentPerTask = 1, because we are able to create Segments of roughly equal cost from the TopLeaves.
This creates the index in Tasks[Task].StartLeaf and Tasks[Task].EndLeaf cost is the cost per TopLeaves
Definition at line 533 of file domain.c.
References topleaf_extdata::cost, DomainDecomp::DomainComm, task_data::EndLeaf, endrun(), topleaf_extdata::Key, topnode_data::Leaf, message(), myfree, mymalloc, NTask, DomainDecomp::NTopLeaves, qsort_openmp, topnode_data::StartKey, task_data::StartLeaf, topleaf_extdata::Task, topleaf_data::Task, DomainDecomp::Tasks, topleaf_ext_order_by_key(), topleaf_ext_order_by_task_and_key(), DomainDecomp::TopLeaves, topleaf_extdata::topnode, topleaf_data::topnode, and DomainDecomp::TopNodes.
Referenced by domain_balance().
|
static |
This function carries out the actual domain decomposition for all particle types. It will try to balance the work-load for each ddecomp, as estimated based on the P[i]-GravCost values. The decomposition will respect the maximum allowed memory-imbalance given by the value of PartAllocFactor.
Definition at line 338 of file domain.c.
References local_topnode_data::Daughter, topnode_data::Daughter, domain_create_topleaves(), domain_determine_global_toptree(), DomainDecomp::DomainComm, endrun(), topnode_data::Leaf, message(), myfree, mymalloc, mymalloc_usedbytes, NTask, DomainDecompositionPolicy::NTopLeaves, DomainDecomp::NTopLeaves, DomainDecomp::NTopNodes, report_memory_usage, local_topnode_data::Shift, topnode_data::Shift, local_topnode_data::StartKey, topnode_data::StartKey, DomainDecomp::TopNodes, and walltime_measure.
Referenced by domain_decompose_full().
|
static |
attempt to assign segments to tasks such that the load or work is balanced.
< a table that gives the total number of particles held by each processor
Definition at line 400 of file domain.c.
References domain_assign_balanced(), domain_check_memory_bound(), domain_compute_costs(), message(), myfree, mymalloc, DomainDecomp::NTopLeaves, and walltime_measure.
Referenced by domain_decompose_full().
|
static |
This function performs local refinement of the topTree.
It creates the local refinement by quickly going through a skeleton tree of a fraction (subsample) of all local particles.
Next, we add flesh to the skeleton: all particles are deposited to the tree.
Finally, in _truncation(), we chop off the cheap branches from the skeleton, terminating the branches when the cost and count are both sufficiently small.
We do not use the full particle data. Sufficient to use LP, which contains the peano key and cost of each particle, and sorted by the peano key.
Definition at line 895 of file domain.c.
References BITS_PER_DIMENSION, local_topnode_data::Cost, local_particle_data::Cost, local_topnode_data::Count, local_topnode_data::Daughter, domain_toptree_get_subnode(), domain_toptree_insert(), domain_toptree_split(), domain_toptree_update_cost(), endrun(), DomainDecompositionPolicy::GlobalSortComm, local_particle_data::Key, mp_order_by_key(), mpsort_mpi, myfree, mymalloc, part_manager_type::NumPart, order_by_key(), P, local_topnode_data::Parent, PartManager, DomainDecompositionPolicy::PreSort, qsort_openmp, local_topnode_data::Shift, local_topnode_data::StartKey, DomainDecompositionPolicy::SubSampleDistance, DomainDecompositionPolicy::UseGlobalSort, and walltime_measure.
Referenced by domain_determine_global_toptree().
|
static |
Definition at line 426 of file domain.c.
References domain_params, DomainDecomp::DomainComm, part_manager_type::MaxPart, message(), NTask, PartManager, DomainParams::SetAsideFactor, task_data::StartLeaf, ta_free, ta_malloc, and DomainDecomp::Tasks.
Referenced by domain_balance().
|
static |
Definition at line 1280 of file domain.c.
References domain_get_topleaf(), DomainDecomp::DomainComm, MPI_INT64, myfree, mymalloc, DomainDecomp::NTopLeaves, part_manager_type::NumPart, P, and PartManager.
Referenced by domain_balance().
|
static |
This function walks the global top tree in order to establish the number of leaves it has. These leaves are then distributed to different processors.
the pointer next points to the next free item on TopLeaves array.
Definition at line 721 of file domain.c.
References topnode_data::Daughter, topnode_data::Leaf, DomainDecomp::TopLeaves, topleaf_data::topnode, and DomainDecomp::TopNodes.
Referenced by domain_attempt_decompose().
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.
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().
|
static |
This function constructs the global top-level tree node that is used for the domain decomposition. This is done by considering the string of Peano-Hilbert keys for all particles, which is recursively chopped off in pieces of eight segments until each segment holds at most a certain number of particles.
Definition at line 1147 of file domain.c.
References local_topnode_data::Cost, local_topnode_data::Count, domain_check_for_local_refine_subsample(), domain_global_refine(), domain_nonrecursively_combine_topTree(), domain_toptree_truncate(), message(), MPI_INT64, MPIU_Any(), DomainDecompositionPolicy::NTopLeaves, ThisTask, and walltime_measure.
Referenced by domain_attempt_decompose().
void domain_free | ( | DomainDecomp * | ddecomp | ) |
Definition at line 320 of file domain.c.
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().
|
static |
Definition at line 1224 of file domain.c.
References local_topnode_data::Cost, local_topnode_data::Count, local_topnode_data::Daughter, message(), local_topnode_data::Parent, local_topnode_data::Shift, and local_topnode_data::StartKey.
Referenced by domain_determine_global_toptree().
|
static |
This function determines which particles that are currently stored on the local CPU have to be moved off according to the domain decomposition.
layoutfunc decides the target Task of particle p (used by subfind_distribute).
Definition at line 707 of file domain.c.
References domain_get_topleaf(), P, topleaf_data::Task, and DomainDecomp::TopLeaves.
Referenced by domain_decompose_full(), and domain_maintain().
void domain_maintain | ( | DomainDecomp * | ddecomp, |
struct DriftData * | drift | ||
) |
Definition at line 234 of file domain.c.
References domain_decompose_full(), domain_exchange(), domain_layoutfunc(), DomainDecomp::DomainComm, message(), PartManager, SlotsManager, and walltime_measure.
Referenced by run().
|
static |
Definition at line 1056 of file domain.c.
References domain_toptree_merge(), endrun(), local_particle_data::Key, MPIU_Any(), myfree, mymalloc, NTask, TAG_GRAV_A, TAG_GRAV_B, and ThisTask.
Referenced by domain_determine_global_toptree().
|
static |
Definition at line 252 of file domain.c.
References domain_params, DomainParams::DomainOverDecompositionFactor, DomainParams::DomainUseGlobalSorting, DomainDecompositionPolicy::GlobalSortComm, NTask, DomainDecompositionPolicy::NTopLeaves, DomainDecompositionPolicy::PreSort, DomainDecompositionPolicy::SubSampleDistance, DomainDecompositionPolicy::TopNodeAllocFactor, DomainParams::TopNodeAllocFactor, and DomainDecompositionPolicy::UseGlobalSort.
Referenced by domain_decompose_full().
|
static |
Definition at line 839 of file domain.c.
References local_topnode_data::Daughter, and local_topnode_data::Parent.
Referenced by domain_toptree_truncate().
|
static |
Definition at line 738 of file domain.c.
References local_topnode_data::Daughter, and local_topnode_data::StartKey.
Referenced by domain_check_for_local_refine_subsample(), and domain_toptree_insert().
|
static |
Definition at line 749 of file domain.c.
References local_topnode_data::Cost, topleaf_extdata::cost, local_topnode_data::Count, domain_toptree_get_subnode(), and topleaf_extdata::Key.
Referenced by domain_check_for_local_refine_subsample().
|
static |
Merge treeB into treeA.
The function recursively merge the cost and refinement of treeB into treeA.
At the initial call, noA and noB must both be the root node.
When the structure is mismatched, e.g. a leaf in A meets a branch in B or a leaf in B meets a branch in A, the cost of the leaf is splitted evenly. This is only an approximation then the leaf is not empty.
We therefore have an incentive to minimize overlaps between treeB and treeA. local_refinement does a global sorting of keys to help that.
Definition at line 1353 of file domain.c.
References local_topnode_data::Cost, local_topnode_data::Count, local_topnode_data::Daughter, endrun(), message(), local_topnode_data::Parent, local_topnode_data::Shift, and local_topnode_data::StartKey.
Referenced by domain_nonrecursively_combine_topTree().
|
static |
Definition at line 760 of file domain.c.
References local_topnode_data::Cost, local_topnode_data::Count, local_topnode_data::Daughter, endrun(), local_topnode_data::Parent, local_topnode_data::Shift, and local_topnode_data::StartKey.
Referenced by domain_check_for_local_refine_subsample().
|
static |
Definition at line 865 of file domain.c.
References domain_toptree_garbage_collection(), and domain_toptree_truncate_r().
Referenced by domain_determine_global_toptree().
|
static |
Definition at line 811 of file domain.c.
References local_topnode_data::Daughter.
Referenced by domain_toptree_truncate().
|
static |
Definition at line 796 of file domain.c.
References local_topnode_data::Cost, local_topnode_data::Count, and local_topnode_data::Daughter.
Referenced by domain_check_for_local_refine_subsample().
|
static |
Definition at line 1472 of file domain.c.
References local_particle_data::Key.
Referenced by domain_check_for_local_refine_subsample().
|
static |
Definition at line 1458 of file domain.c.
References local_particle_data::Key.
Referenced by domain_check_for_local_refine_subsample().
void set_domain_par | ( | DomainParams | dp | ) |
Definition at line 78 of file domain.c.
References domain_params.
Referenced by setup_tree(), and test_fof().
void set_domain_params | ( | ParameterSet * | ps | ) |
Definition at line 84 of file domain.c.
References domain_params, DomainParams::DomainOverDecompositionFactor, DomainParams::DomainUseGlobalSorting, param_get_double(), param_get_int(), DomainParams::SetAsideFactor, ThisTask, and DomainParams::TopNodeAllocFactor.
Referenced by read_parameter_file().
|
static |
Definition at line 510 of file domain.c.
References topleaf_extdata::Key.
Referenced by domain_assign_balanced().
|
static |
Definition at line 498 of file domain.c.
References topleaf_extdata::Key, and topleaf_extdata::Task.
Referenced by domain_assign_balanced().
|
static |
Definition at line 43 of file domain.c.
Referenced by domain_check_memory_bound(), domain_policies_init(), set_domain_par(), and set_domain_params().