PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "md.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 #define EPSILON ((TYPE)1.0e-6)
7 
8 void run_benchmark( void *vargs ) {
9  struct bench_args_t *args = (struct bench_args_t *)vargs;
10  md( args->n_points, args->force, args->position );
11 }
12 
13 /* Input format:
14 %% Section 1
15 int32_t[blockSide^3]: grid populations
16 %% Section 2
17 TYPE[blockSide^3*densityFactor]: positions
18 */
19 
20 void input_to_data(int fd, void *vdata) {
21  struct bench_args_t *data = (struct bench_args_t *)vdata;
22  char *p, *s;
23  // Zero-out everything.
24  memset(vdata,0,sizeof(struct bench_args_t));
25  // Load input string
26  p = readfile(fd);
27 
28  s = find_section_start(p,1);
30 
31  s = find_section_start(p,2);
32  STAC(parse_,TYPE,_array)(s, (double *)(data->position), 3*blockSide*blockSide*blockSide*densityFactor);
33  free(p);
34 }
35 
36 void data_to_input(int fd, void *vdata) {
37  struct bench_args_t *data = (struct bench_args_t *)vdata;
38 
40  write_int32_t_array(fd, (int32_t *)(data->n_points), blockSide*blockSide*blockSide);
41 
43  STAC(write_,TYPE,_array)(fd, (double *)(data->position), 3*blockSide*blockSide*blockSide*densityFactor);
44 
45 }
46 
47 /* Output format:
48 %% Section 1
49 TYPE[blockSide^3*densityFactor]: force
50 */
51 
52 void output_to_data(int fd, void *vdata) {
53  struct bench_args_t *data = (struct bench_args_t *)vdata;
54  char *p, *s;
55  // Zero-out everything.
56  memset(vdata,0,sizeof(struct bench_args_t));
57  // Load input string
58  p = readfile(fd);
59 
60  s = find_section_start(p,1);
61  STAC(parse_,TYPE,_array)(s, (double *)data->force, 3*blockSide*blockSide*blockSide*densityFactor);
62  free(p);
63 }
64 
65 void data_to_output(int fd, void *vdata) {
66  struct bench_args_t *data = (struct bench_args_t *)vdata;
67 
69  STAC(write_,TYPE,_array)(fd, (double *)data->force, 3*blockSide*blockSide*blockSide*densityFactor);
70 }
71 
72 int check_data( void *vdata, void *vref ) {
73  struct bench_args_t *data = (struct bench_args_t *)vdata;
74  struct bench_args_t *ref = (struct bench_args_t *)vref;
75  int has_errors = 0;
76  int i, j, k, d;
77  TYPE diff_x, diff_y, diff_z;
78 
79  for(i=0; i<blockSide; i++) {
80  for(j=0; j<blockSide; j++) {
81  for(k=0; k<blockSide; k++) {
82  for(d=0; d<densityFactor; d++) {
83  diff_x = data->force[i][j][k][d].x - ref->force[i][j][k][d].x;
84  diff_y = data->force[i][j][k][d].y - ref->force[i][j][k][d].y;
85  diff_z = data->force[i][j][k][d].z - ref->force[i][j][k][d].z;
86  has_errors |= (diff_x<-EPSILON) || (EPSILON<diff_x);
87  has_errors |= (diff_y<-EPSILON) || (EPSILON<diff_y);
88  has_errors |= (diff_z<-EPSILON) || (EPSILON<diff_z);
89  }
90  }
91  }
92  }
93 
94  // Return true if it's correct.
95  return !has_errors;
96 }
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
#define blockSide
Definition: md.h:11
TYPE z
Definition: md.h:24
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
int write_int32_t_array(int fd, int32_t *arr, int n)
#define TYPE
Definition: backprop.h:21
#define STAC(f_pfx, t, f_sfx)
Definition: support.h:51
void md(int n_points[blockSide][blockSide][blockSide], dvector_t force[blockSide][blockSide][blockSide][densityFactor], dvector_t position[blockSide][blockSide][blockSide][densityFactor])
Definition: md.c:6
int INPUT_SIZE
Definition: local_support.c:4
int parse_int32_t_array(char *s, int32_t *arr, int n)
static const uint32_t k[]
Definition: sha-256.c:22
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
dvector_t position[blockSide][blockSide][blockSide][densityFactor]
Definition: md.h:40
int32_t n_points[blockSide][blockSide][blockSide]
Definition: md.h:38
char * readfile(int fd)
Definition: support.c:34
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
char * find_section_start(char *s, int n)
Definition: support.c:56
TYPE x
Definition: md.h:24
#define densityFactor
Definition: md.h:18
TYPE y
Definition: md.h:24
dvector_t force[blockSide][blockSide][blockSide][densityFactor]
Definition: md.h:39
#define EPSILON
Definition: local_support.c:6
void run_benchmark(void *vargs)
Definition: local_support.c:6

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13