MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Functions
test_openmpsort.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#include "stub.h"
Include dependency graph for test_openmpsort.c:

Go to the source code of this file.

Classes

struct  __data
 

Functions

static int compare (const void *a, const void *b)
 
static void test_openmpsort_struct (void **state)
 
static void test_openmpsort (void **state)
 
int main (void)
 

Function Documentation

◆ compare()

static int compare ( const void *  a,
const void *  b 
)
static

Definition at line 22 of file test_openmpsort.c.

22  {
23  return ( *(int*)a - *(int*)b );
24 }

Referenced by test_openmpsort(), and test_openmpsort_struct().

Here is the caller graph for this function:

◆ main()

int main ( void  )

Definition at line 102 of file test_openmpsort.c.

102  {
103  const struct CMUnitTest tests[] = {
104  cmocka_unit_test(test_openmpsort),
105  cmocka_unit_test(test_openmpsort_struct),
106  };
107  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
108 }
static void test_openmpsort_struct(void **state)
static void test_openmpsort(void **state)

References test_openmpsort(), and test_openmpsort_struct().

Here is the call graph for this function:

◆ test_openmpsort()

static void test_openmpsort ( void **  state)
static

Definition at line 66 of file test_openmpsort.c.

66  {
67  int i;
68  // set up array to be sorted
69  //a bad case is 87763 threads = 12
70  int size = 87763;
71  int *a = (int *) malloc(size * sizeof(int));
72 
73  srand48(8675309);
74  for(i = 0; i < size; i++)
75  a[i] = (int) (size * drand48());
76 
77  double start, end;
78 
79  start = omp_get_wtime();
80  qsort_openmp(a, size, sizeof(int), compare);
81  end = omp_get_wtime();
82 
83  message(1,"parallel sort time = %g s %d threads\n",end-start, omp_get_max_threads());
84  for(i=1; i<size; i++) {
85  if( a[i-1]>a[i] )
86  message(1,"BAD: %d %d %d\n",i,a[i-1],a[i]);
87  assert_true(a[i-1] <= a[i]);
88  }
89 
90  srand48(8675309);
91  for(i = 0; i < size; i++)
92  a[i] = (int) (size * drand48());
93 
94  start = omp_get_wtime();
95  qsort(a, size, sizeof(int), compare);
96  end = omp_get_wtime();
97 
98  message(1, "serial sort time = %g s\n",end-start);
99 
100 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
#define qsort_openmp
Definition: test_exchange.c:14
static int compare(const void *a, const void *b)

References compare(), message(), and qsort_openmp.

Referenced by main().

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

◆ test_openmpsort_struct()

static void test_openmpsort_struct ( void **  state)
static

Definition at line 31 of file test_openmpsort.c.

31  {
32  int i;
33  // set up array to be sorted
34  //a bad case is 87763 threads = 12
35  int size = 187763;
36  struct __data *a = (struct __data *) malloc(size * sizeof(struct __data));
37 
38  srand48(8675309);
39  for(i = 0; i < size; i++)
40  a[i].dd[0] = (int) (size * drand48());
41 
42  double start, end;
43 
44  start = omp_get_wtime();
45  qsort_openmp(a, size, sizeof(struct __data), compare);
46  end = omp_get_wtime();
47 
48  message(1,"parallel sort time = %g s %d threads\n",end-start, omp_get_max_threads());
49  for(i=1; i<size; i++) {
50  if( a[i-1].dd[0] >a[i].dd[0] )
51  message(1,"BAD: %d %d %d\n",i,a[i-1].dd[0],a[i].dd[0]);
52  assert_true(a[i-1].dd[0] <= a[i].dd[0]);
53  }
54 
55  srand48(8675309);
56  for(i = 0; i < size; i++)
57  a[i].dd[0] = (int) (size * drand48());
58 
59  start = omp_get_wtime();
60  qsort(a, size, sizeof(struct __data), compare);
61  end = omp_get_wtime();
62 
63  message(1, "serial (glibc) sort time = %g s\n",end-start);
64 
65 }
int dd[200]

References compare(), __data::dd, message(), and qsort_openmp.

Referenced by main().

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