MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
test_fof.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/fof.h>
#include <libgadget/walltime.h>
#include <libgadget/domain.h>
#include <libgadget/forcetree.h>
#include <libgadget/partmanager.h>
#include "stub.h"
Include dependency graph for test_fof.c:

Go to the source code of this file.

Macros

#define qsort_openmp   qsort
 
#define NUMPART1   8
 

Functions

static int setup_particles (int NumPart, double BoxSize)
 
static int teardown_particles (void **state)
 
static void test_fof (void **state)
 
int main (void)
 

Variables

static struct ClockTable CT
 

Macro Definition Documentation

◆ NUMPART1

#define NUMPART1   8

Definition at line 25 of file test_fof.c.

◆ qsort_openmp

#define qsort_openmp   qsort

Definition at line 14 of file test_fof.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 114 of file test_fof.c.

114  {
115  const struct CMUnitTest tests[] = {
116  cmocka_unit_test(test_fof),
117  };
118  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
119 }
static void test_fof(void **state)
Definition: test_fof.c:71

References test_fof().

Here is the call graph for this function:

◆ setup_particles()

static int setup_particles ( int  NumPart,
double  BoxSize 
)
static

Definition at line 27 of file test_fof.c.

28 {
29 
30  int ThisTask;
31  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
32 
33  gsl_rng * r = gsl_rng_alloc(gsl_rng_mt19937);
34  gsl_rng_set(r, 0);
35 
36  particle_alloc_memory(PartManager, BoxSize, 1.5 * NumPart);
37  PartManager->NumPart = NumPart;
38 
39  int i;
40  #pragma omp parallel for
41  for(i = 0; i < PartManager->NumPart; i ++) {
42  P[i].ID = i + PartManager->NumPart * ThisTask;
43  /* DM only*/
44  P[i].Type = 1;
45  P[i].Mass = 1;
46  P[i].TimeBin = 0;
47  P[i].IsGarbage = 0;
48  int j;
49  for(j=0; j<3; j++)
50  P[i].Pos[j] = BoxSize * gsl_rng_uniform(r);
51  P[i].Key = PEANO(P[i].Pos, BoxSize);
52 
53  }
54 
55  gsl_rng_free(r);
56  /* TODO: Here create particles in some halo-like configuration*/
57 
58  return 0;
59 }
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
void particle_alloc_memory(struct part_manager_type *PartManager, double BoxSize, int64_t MaxPart)
Definition: partmanager.c:14
#define P
Definition: partmanager.h:88
static peano_t PEANO(double *Pos, double BoxSize)
Definition: peano.h:14
int ThisTask
Definition: test_exchange.c:23

References part_manager_type::NumPart, P, particle_alloc_memory(), PartManager, PEANO(), and ThisTask.

Referenced by test_fof().

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 62 of file test_fof.c.

63 {
64  myfree(P);
65  MPI_Barrier(MPI_COMM_WORLD);
66  return 0;
67 }
#define myfree(x)
Definition: mymalloc.h:19

References myfree, and P.

Referenced by test_fof().

Here is the caller graph for this function:

◆ test_fof()

static void test_fof ( void **  state)
static

Definition at line 71 of file test_fof.c.

72 {
73  walltime_init(&CT);
74 
75  struct DomainParams dp = {0};
78  dp.TopNodeAllocFactor = 1.;
79  dp.SetAsideFactor = 1;
80  set_domain_par(dp);
82 
83  int NumPart = 1024;
84  /* 20000 kpc*/
85  double BoxSize = 20000;
86  setup_particles(NumPart, BoxSize);
87 
88  int i, NTask, ThisTask;
89  /* Build a tree and domain decomposition*/
90  DomainDecomp ddecomp = {0};
91  domain_decompose_full(&ddecomp);
92 
93  FOFGroups fof = fof_fof(&ddecomp, 1, MPI_COMM_WORLD);
94 
95  /* Example assertion: this checks that the address of a struct is not NULL,
96  * which will always pass! */
97  assert_all_true(&fof);
98 
99  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
100  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
101 
102  /* Assert some more things about the particles,
103  * maybe checking the halo properties*/
104  for(i = 0; i < PartManager->NumPart; i ++) {
105  assert_true(P[i].ID % NTask == ThisTask);
106  }
107 
108  fof_finish(&fof);
109 
110  teardown_particles(state);
111  return;
112 }
void domain_decompose_full(DomainDecomp *ddecomp)
Definition: domain.c:155
void set_domain_par(DomainParams dp)
Definition: domain.c:78
void fof_finish(FOFGroups *fof)
Definition: fof.c:257
FOFGroups fof_fof(DomainDecomp *ddecomp, const int StoreGrNr, MPI_Comm Comm)
Definition: fof.c:151
void init_forcetree_params(const int FastParticleType)
Definition: forcetree.c:43
int DomainOverDecompositionFactor
Definition: domain.h:53
int DomainUseGlobalSorting
Definition: domain.h:55
double TopNodeAllocFactor
Definition: domain.h:57
double SetAsideFactor
Definition: domain.h:59
Definition: fof.h:62
int NTask
Definition: test_exchange.c:23
static struct ClockTable CT
Definition: test_fof.c:23
static int setup_particles(int NumPart, double BoxSize)
Definition: test_fof.c:27
static int teardown_particles(void **state)
Definition: test_fof.c:62
void walltime_init(struct ClockTable *ct)
Definition: walltime.c:19

References CT, domain_decompose_full(), DomainParams::DomainOverDecompositionFactor, DomainParams::DomainUseGlobalSorting, fof_finish(), fof_fof(), init_forcetree_params(), NTask, part_manager_type::NumPart, P, PartManager, set_domain_par(), DomainParams::SetAsideFactor, setup_particles(), teardown_particles(), ThisTask, DomainParams::TopNodeAllocFactor, and walltime_init().

Referenced by main().

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

Variable Documentation

◆ CT

struct ClockTable CT
static

Definition at line 1 of file test_fof.c.

Referenced by test_fof().