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_kernel( args->force_x, args->force_y, args->force_z,
11  args->position_x, args->position_y, args->position_z,
12  args->NL );
13 }
14 
15 /* Input format:
16 %% Section 1
17 TYPE[nAtoms]: x positions
18 %% Section 2
19 TYPE[nAtoms]: y positions
20 %% Section 3
21 TYPE[nAtoms]: z positions
22 %% Section 4
23 int32_t[nAtoms*maxNeighbors]: neighbor list
24 */
25 
26 void input_to_data(int fd, void *vdata) {
27  struct bench_args_t *data = (struct bench_args_t *)vdata;
28  char *p, *s;
29  // Zero-out everything.
30  memset(vdata,0,sizeof(struct bench_args_t));
31  // Load input string
32  p = readfile(fd);
33 
34  s = find_section_start(p,1);
35  STAC(parse_,TYPE,_array)(s, data->position_x, nAtoms);
36 
37  s = find_section_start(p,2);
38  STAC(parse_,TYPE,_array)(s, data->position_y, nAtoms);
39 
40  s = find_section_start(p,3);
41  STAC(parse_,TYPE,_array)(s, data->position_z, nAtoms);
42 
43  s = find_section_start(p,4);
45  free(p);
46 }
47 
48 void data_to_input(int fd, void *vdata) {
49  struct bench_args_t *data = (struct bench_args_t *)vdata;
50 
52  STAC(write_,TYPE,_array)(fd, data->position_x, nAtoms);
53 
55  STAC(write_,TYPE,_array)(fd, data->position_y, nAtoms);
56 
58  STAC(write_,TYPE,_array)(fd, data->position_z, nAtoms);
59 
62 
63 }
64 
65 /* Output format:
66 %% Section 1
67 TYPE[nAtoms]: new x force
68 %% Section 2
69 TYPE[nAtoms]: new y force
70 %% Section 3
71 TYPE[nAtoms]: new z force
72 */
73 
74 void output_to_data(int fd, void *vdata) {
75  struct bench_args_t *data = (struct bench_args_t *)vdata;
76  char *p, *s;
77  // Zero-out everything.
78  memset(vdata,0,sizeof(struct bench_args_t));
79  // Load input string
80  p = readfile(fd);
81 
82  s = find_section_start(p,1);
83  STAC(parse_,TYPE,_array)(s, data->force_x, nAtoms);
84 
85  s = find_section_start(p,2);
86  STAC(parse_,TYPE,_array)(s, data->force_y, nAtoms);
87 
88  s = find_section_start(p,3);
89  STAC(parse_,TYPE,_array)(s, data->force_z, nAtoms);
90  free(p);
91 }
92 
93 void data_to_output(int fd, void *vdata) {
94  struct bench_args_t *data = (struct bench_args_t *)vdata;
95 
97  STAC(write_,TYPE,_array)(fd, data->force_x, nAtoms);
98 
100  STAC(write_,TYPE,_array)(fd, data->force_y, nAtoms);
101 
103  STAC(write_,TYPE,_array)(fd, data->force_z, nAtoms);
104 }
105 
106 int check_data( void *vdata, void *vref ) {
107  struct bench_args_t *data = (struct bench_args_t *)vdata;
108  struct bench_args_t *ref = (struct bench_args_t *)vref;
109  int has_errors = 0;
110  int i;
111  TYPE diff_x, diff_y, diff_z;
112 
113  for( i=0; i<nAtoms; i++ ) {
114  diff_x = data->force_x[i] - ref->force_x[i];
115  diff_y = data->force_y[i] - ref->force_y[i];
116  diff_z = data->force_z[i] - ref->force_z[i];
117  has_errors |= (diff_x<-EPSILON) || (EPSILON<diff_x);
118  has_errors |= (diff_y<-EPSILON) || (EPSILON<diff_y);
119  has_errors |= (diff_z<-EPSILON) || (EPSILON<diff_z);
120  }
121 
122  // Return true if it's correct.
123  return !has_errors;
124 }
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
#define EPSILON
Definition: local_support.c:6
int32_t NL[nAtoms *maxNeighbors]
Definition: md.h:38
TYPE position_z[nAtoms]
Definition: md.h:37
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 maxNeighbors
Definition: md.h:16
TYPE position_x[nAtoms]
Definition: md.h:35
#define TYPE
Definition: backprop.h:21
#define STAC(f_pfx, t, f_sfx)
Definition: support.h:51
int INPUT_SIZE
Definition: local_support.c:4
int parse_int32_t_array(char *s, int32_t *arr, int n)
TYPE position_y[nAtoms]
Definition: md.h:36
TYPE force_z[nAtoms]
Definition: md.h:34
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
TYPE force_y[nAtoms]
Definition: md.h:33
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
void md_kernel(TYPE force_x[nAtoms], TYPE force_y[nAtoms], TYPE force_z[nAtoms], TYPE position_x[nAtoms], TYPE position_y[nAtoms], TYPE position_z[nAtoms], int32_t NL[nAtoms *maxNeighbors])
Definition: md.c:10
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
#define nAtoms
Definition: md.h:9
TYPE force_x[nAtoms]
Definition: md.h:32
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