MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
test_exchange.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <mpi.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <libgadget/exchange.h>
#include <libgadget/domain.h>
#include <libgadget/slotsmanager.h>
#include <libgadget/partmanager.h>
#include "stub.h"
#include <libgadget/walltime.h>
Include dependency graph for test_exchange.c:

Go to the source code of this file.

Macros

#define qsort_openmp   qsort
 
#define NUMPART1   8
 

Functions

static int setup_particles (int64_t NType[6])
 
static int teardown_particles (void **state)
 
static int test_exchange_layout_func (int i, const void *userdata)
 
static void test_exchange (void **state)
 
static void test_exchange_zero_slots (void **state)
 
static void test_exchange_with_garbage (void **state)
 
static int test_exchange_layout_func_uneven (int i, const void *userdata)
 
static void test_exchange_uneven (void **state)
 
int main (void)
 

Variables

int NTask
 
int ThisTask
 
int TotNumPart
 
static struct ClockTable Clocks
 

Macro Definition Documentation

◆ NUMPART1

#define NUMPART1   8

Definition at line 28 of file test_exchange.c.

◆ qsort_openmp

#define qsort_openmp   qsort

Definition at line 14 of file test_exchange.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 210 of file test_exchange.c.

210  {
211  const struct CMUnitTest tests[] = {
212  cmocka_unit_test(test_exchange_with_garbage),
213  cmocka_unit_test(test_exchange),
214  cmocka_unit_test(test_exchange_zero_slots),
215  cmocka_unit_test(test_exchange_uneven),
216  };
217  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
218 }
static void test_exchange_uneven(void **state)
static void test_exchange_with_garbage(void **state)
static void test_exchange(void **state)
Definition: test_exchange.c:92
static void test_exchange_zero_slots(void **state)

References test_exchange(), test_exchange_uneven(), test_exchange_with_garbage(), and test_exchange_zero_slots().

Here is the call graph for this function:

◆ setup_particles()

static int setup_particles ( int64_t  NType[6])
static

Definition at line 30 of file test_exchange.c.

31 {
33  MPI_Barrier(MPI_COMM_WORLD);
34  PartManager->MaxPart = 1024;
35  int ptype;
36  PartManager->NumPart = 0;
37  for(ptype = 0; ptype < 6; ptype ++) {
38  PartManager->NumPart += NType[ptype];
39  }
40  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
41  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
42 
43  P = (struct particle_data *) mymalloc("P", PartManager->MaxPart * sizeof(struct particle_data));
44  memset(P, 0, sizeof(struct particle_data) * PartManager->MaxPart);
45 
50 
51 
52  slots_reserve(1, NType, SlotsManager);
53 
55 
56  int i;
57  #pragma omp parallel for
58  for(i = 0; i < PartManager->NumPart; i ++) {
59  P[i].ID = i + PartManager->NumPart * ThisTask;
60  }
61 
63 
64  MPI_Allreduce(&PartManager->NumPart, &TotNumPart, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
65 
66  return 0;
67 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
#define P
Definition: partmanager.h:88
void slots_setup_id(const struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:653
size_t slots_reserve(int where, int64_t atleast[6], struct slots_manager_type *sman)
Definition: slotsmanager.c:475
void slots_set_enabled(int ptype, size_t elsize, struct slots_manager_type *sman)
Definition: slotsmanager.c:560
void slots_setup_topology(struct part_manager_type *pman, int64_t *NLocal, struct slots_manager_type *sman)
Definition: slotsmanager.c:624
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
void slots_init(double increase, struct slots_manager_type *sman)
Definition: slotsmanager.c:550
static struct ClockTable Clocks
Definition: test_exchange.c:26
int ThisTask
Definition: test_exchange.c:23
int NTask
Definition: test_exchange.c:23
int TotNumPart
Definition: test_exchange.c:24
void walltime_init(struct ClockTable *ct)
Definition: walltime.c:19
static enum TransferType ptype
Definition: zeldovich.c:146

References Clocks, part_manager_type::MaxPart, mymalloc, NTask, part_manager_type::NumPart, P, PartManager, ptype, slots_init(), slots_reserve(), slots_set_enabled(), slots_setup_id(), slots_setup_topology(), SlotsManager, ThisTask, TotNumPart, and walltime_init().

Referenced by test_exchange(), test_exchange_uneven(), test_exchange_with_garbage(), and test_exchange_zero_slots().

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

◆ teardown_particles()

static int teardown_particles ( void **  state)
static

Definition at line 70 of file test_exchange.c.

71 {
72  int TotNumPart2;
73 
74  MPI_Allreduce(&PartManager->NumPart, &TotNumPart2, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
75 
76  assert_int_equal(TotNumPart2, TotNumPart);
77 
79  myfree(P);
80  MPI_Barrier(MPI_COMM_WORLD);
81  return 0;
82 }
#define myfree(x)
Definition: mymalloc.h:19
void slots_free(struct slots_manager_type *sman)
Definition: slotsmanager.c:570

References myfree, part_manager_type::NumPart, P, PartManager, slots_free(), SlotsManager, and TotNumPart.

Referenced by test_exchange(), test_exchange_uneven(), test_exchange_with_garbage(), and test_exchange_zero_slots().

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

◆ test_exchange()

static void test_exchange ( void **  state)
static

Definition at line 92 of file test_exchange.c.

93 {
94  int64_t newSlots[6] = {NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1};
95 
96  setup_particles(newSlots);
97 
98  int i;
99 
100  int fail = domain_exchange(&test_exchange_layout_func, NULL, 1, NULL, PartManager, SlotsManager,10000, MPI_COMM_WORLD);
101 
102  assert_all_true(!fail);
103 
106 
107  for(i = 0; i < PartManager->NumPart; i ++) {
108  assert_true(P[i].ID % NTask == 1Lu * ThisTask);
109  }
110 
111  teardown_particles(state);
112  return;
113 }
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
void slots_check_id_consistency(struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:587
static int test_exchange_layout_func(int i, const void *userdata)
Definition: test_exchange.c:86
static int setup_particles(int64_t NType[6])
Definition: test_exchange.c:30
static int teardown_particles(void **state)
Definition: test_exchange.c:70
#define NUMPART1
Definition: test_exchange.c:28

References domain_exchange(), domain_test_id_uniqueness(), particle_data::ID, NTask, part_manager_type::NumPart, NUMPART1, P, PartManager, setup_particles(), slots_check_id_consistency(), SlotsManager, teardown_particles(), test_exchange_layout_func(), and ThisTask.

Referenced by main().

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

◆ test_exchange_layout_func()

static int test_exchange_layout_func ( int  i,
const void *  userdata 
)
static

Definition at line 86 of file test_exchange.c.

87 {
88  return P[i].ID % NTask;
89 }

References NTask, and P.

Referenced by test_exchange(), test_exchange_with_garbage(), and test_exchange_zero_slots().

Here is the caller graph for this function:

◆ test_exchange_layout_func_uneven()

static int test_exchange_layout_func_uneven ( int  i,
const void *  userdata 
)
static

Definition at line 170 of file test_exchange.c.

171 {
172  if(P[i].Type == 0) return 0;
173 
174  return P[i].ID % NTask;
175 }

References NTask, P, and particle_data::Type.

Referenced by test_exchange_uneven().

Here is the caller graph for this function:

◆ test_exchange_uneven()

static void test_exchange_uneven ( void **  state)
static

Definition at line 178 of file test_exchange.c.

179 {
180  int64_t newSlots[6] = {NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1};
181 
182  setup_particles(newSlots);
183  int i;
184 
185  /* this will trigger a slot growth on slot type 0 due to the inbalance */
186  int fail = domain_exchange(&test_exchange_layout_func_uneven, NULL, 1, NULL, PartManager, SlotsManager, 10000, MPI_COMM_WORLD);
187 
188  assert_all_true(!fail);
189 
190  if(ThisTask == 0) {
191  /* the slot type must have grown automatically to handle the new particles. */
192  assert_int_equal(SlotsManager->info[0].size, NUMPART1 * NTask);
193  }
194 
197 
198  for(i = 0; i < PartManager->NumPart; i ++) {
199  if(P[i].Type == 0) {
200  assert_true (ThisTask == 0);
201  } else {
202  assert_true(P[i].ID % NTask == 1Lu * ThisTask);
203  }
204  }
205 
206  teardown_particles(state);
207  return;
208 }
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
static int test_exchange_layout_func_uneven(int i, const void *userdata)

References domain_exchange(), domain_test_id_uniqueness(), particle_data::ID, slots_manager_type::info, NTask, part_manager_type::NumPart, NUMPART1, P, PartManager, setup_particles(), slot_info::size, slots_check_id_consistency(), SlotsManager, teardown_particles(), test_exchange_layout_func_uneven(), ThisTask, and particle_data::Type.

Referenced by main().

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

◆ test_exchange_with_garbage()

static void test_exchange_with_garbage ( void **  state)
static

Definition at line 140 of file test_exchange.c.

141 {
142  int64_t newSlots[6] = {NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1, NUMPART1};
143 
144  setup_particles(newSlots);
145  int i;
146 
147  slots_mark_garbage(0, PartManager, SlotsManager); /* watch out! this propagates the garbage flag to children */
148  TotNumPart -= NTask;
149 
150  int fail = domain_exchange(&test_exchange_layout_func, NULL, 1, NULL, PartManager, SlotsManager, 10000, MPI_COMM_WORLD);
151 
152  assert_all_true(!fail);
153 
156 
157  for(i = 0; i < PartManager->NumPart; i ++) {
158  assert_true (P[i].ID % NTask == 1Lu * ThisTask);
159  }
160 
161  for(i = 0; i < PartManager->NumPart; i ++) {
162  assert_true (P[i].IsGarbage == 0);
163  }
164 
165  teardown_particles(state);
166  return;
167 }
void slots_mark_garbage(int i, struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:577

References domain_exchange(), domain_test_id_uniqueness(), particle_data::ID, particle_data::IsGarbage, NTask, part_manager_type::NumPart, NUMPART1, P, PartManager, setup_particles(), slots_check_id_consistency(), slots_mark_garbage(), SlotsManager, teardown_particles(), test_exchange_layout_func(), ThisTask, and TotNumPart.

Referenced by main().

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

◆ test_exchange_zero_slots()

static void test_exchange_zero_slots ( void **  state)
static

Definition at line 116 of file test_exchange.c.

117 {
118  int64_t newSlots[6] = {NUMPART1, 0, NUMPART1, 0, NUMPART1, 0};
119 
120  setup_particles(newSlots);
121 
122  int i;
123 
124  int fail = domain_exchange(&test_exchange_layout_func, NULL, 1, NULL, PartManager, SlotsManager, 10000, MPI_COMM_WORLD);
125 
126  assert_all_true(!fail);
127 
130 
131  for(i = 0; i < PartManager->NumPart; i ++) {
132  assert_true (P[i].ID % NTask == 1Lu*ThisTask);
133  }
134 
135  teardown_particles(state);
136  return;
137 }

References domain_exchange(), domain_test_id_uniqueness(), particle_data::ID, NTask, part_manager_type::NumPart, NUMPART1, P, PartManager, setup_particles(), slots_check_id_consistency(), SlotsManager, teardown_particles(), test_exchange_layout_func(), and ThisTask.

Referenced by main().

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

Variable Documentation

◆ Clocks

struct ClockTable Clocks
static

Definition at line 24 of file test_exchange.c.

Referenced by setup_particles().

◆ NTask

int NTask

◆ ThisTask

int ThisTask

Definition at line 23 of file test_exchange.c.

Referenced by _assign_colors(), _collect_sizes(), _create_segment_group(), _MPIU_Barrier(), _solve_for_layout_mpi(), add_particle_to_group(), check_sorted(), cluster_get_num_hosts(), convert_node_to_region(), count_QSO_halos(), do_long_radix_test(), do_mpsort_test(), domain_build_exchange_list(), domain_determine_global_toptree(), domain_nonrecursively_combine_topTree(), domain_test_id_uniqueness(), endrun(), find_last_snapnum(), fof_assign_grnr(), fof_compile_catalogue(), fof_label_primary(), fof_reduce_groups(), fof_seed(), fof_seed_make_one(), fof_try_particle_exchange(), force_exchange_pseudodata(), force_insert_pseudo_particles(), force_tree_create_nodes(), force_update_hmax(), force_update_node_parallel(), hci_query_filesystem(), init_alloc_particle_slot_memory(), init_powerspectrum(), init_transfer_table(), lightcone_init(), load_heii_reion_hist(), load_treecool(), main(), MPI_Alltoallv_smart(), MPI_Alltoallv_sparse(), MPIU_cumsum(), MPIU_Gather(), MPIU_GetLoc(), MPIU_Scatter(), MPIU_Tracev(), MPIU_write_pids(), mpsort_mpi_newarray_impl(), open_outputfiles(), petaio_read_icnutransfer(), petaio_read_neutrinos(), petaio_read_snapshot(), petaio_save_neutrinos(), petaio_save_snapshot(), petapm_init(), powerspectrum_nu_save(), powerspectrum_save(), print_spec(), read_big_array(), read_parameter_file(), read_parameterfile(), read_power_table(), report_detailed_memory_usage(), save_all_transfer_tables(), save_transfer(), set_all_global_params(), set_blackhole_params(), set_cooling_params(), set_density_params(), set_domain_params(), set_fof_params(), set_gravshort_tree_params(), set_hydro_params(), set_init_params(), set_metal_return_params(), set_petaio_params(), set_qso_lightup_params(), set_sfr_params(), set_stats_params(), set_timestep_params(), set_treewalk_params(), set_winds_params(), setup_glass(), setup_particles(), sumup_large_ints(), sumup_longs(), test_exchange(), test_exchange_uneven(), test_exchange_with_garbage(), test_exchange_zero_slots(), test_fof(), and write_checkpoint().

◆ TotNumPart

int TotNumPart