MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions
test_powerspectrum.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <omp.h>
#include <math.h>
#include <mpi.h>
#include "stub.h"
#include <bigfile-mpi.h>
#include <libgadget/powerspectrum.h>
Include dependency graph for test_powerspectrum.c:

Go to the source code of this file.

Macros

#define NUM_THREADS   4
 

Functions

static void test_total_powerspectrum (void **state)
 
int main (void)
 

Macro Definition Documentation

◆ NUM_THREADS

#define NUM_THREADS   4

Definition at line 18 of file test_powerspectrum.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 60 of file test_powerspectrum.c.

61 {
62  const struct CMUnitTest tests[] = {
63  cmocka_unit_test(test_total_powerspectrum),
64  };
65  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
66 }
static void test_total_powerspectrum(void **state)

References test_total_powerspectrum().

Here is the call graph for this function:

◆ test_total_powerspectrum()

static void test_total_powerspectrum ( void **  state)
static

Definition at line 21 of file test_powerspectrum.c.

21  {
22  (void) state;
23  /*Check allocation*/
24  int nmpi;
25  Power PowerSpectrum;
26  MPI_Comm_size(MPI_COMM_WORLD, &nmpi);
27 
28  powerspectrum_alloc(&PowerSpectrum,15,NUM_THREADS, 0, 3.085678e24);
29  assert_true(PowerSpectrum.Nmodes);
30  assert_true(PowerSpectrum.Power);
31  assert_true(PowerSpectrum.kk);
32  powerspectrum_zero(&PowerSpectrum);
33  assert_true(PowerSpectrum.Nmodes[0] == 0);
34  assert_true(PowerSpectrum.Nmodes[PowerSpectrum.size-1] == 0);
35 
36  //Construct input power (this would be done by the power spectrum routine in petapm)
37  int ii, th;
38  for(ii=0; ii<15; ii++) {
39  for(th = 0; th < NUM_THREADS; th++) {
40  PowerSpectrum.Nmodes[ii+PowerSpectrum.size*th] = ii;
41  PowerSpectrum.Power[ii+PowerSpectrum.size*th] = ii*sin(ii)*sin(ii);
42  PowerSpectrum.kk[ii+PowerSpectrum.size*th] = ii*ii;
43  }
44  }
45  PowerSpectrum.Norm = 1;
46  /*Now every thread and every MPI has the same data. Sum it.*/
47  powerspectrum_sum(&PowerSpectrum);
48 
49  /*Check summation was done correctly*/
50  assert_true(PowerSpectrum.Nmodes[0] == NUM_THREADS*nmpi);
51  assert_true(PowerSpectrum.Nmodes[13] == NUM_THREADS*nmpi*14);
52 
53  assert_true(fabs(PowerSpectrum.Power[0] - sin(1)*sin(1)) < 1e-5);
54  assert_true(fabs(PowerSpectrum.Power[12] - sin(13)*sin(13)) < 1e-5);
55  assert_true(fabs(PowerSpectrum.kk[12] - 2 * M_PI *13) < 1e-5);
56  assert_true(fabs(PowerSpectrum.kk[0] - 2 * M_PI ) < 1e-5);
57 
58 }
void powerspectrum_sum(Power *ps)
Definition: powerspectrum.c:54
void powerspectrum_zero(Power *ps)
Definition: powerspectrum.c:35
void powerspectrum_alloc(Power *ps, const int nbins, const int nthreads, const int MassiveNuLinResp, const double BoxSize_in_cm)
Definition: powerspectrum.c:16
double * Power
Definition: powerspectrum.h:10
int64_t * Nmodes
Definition: powerspectrum.h:11
#define NUM_THREADS

References _powerspectrum::kk, _powerspectrum::Nmodes, _powerspectrum::Norm, NUM_THREADS, _powerspectrum::Power, powerspectrum_alloc(), powerspectrum_sum(), powerspectrum_zero(), and _powerspectrum::size.

Referenced by main().

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