PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "sort.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 void run_benchmark( void *vargs ) {
7  struct bench_args_t *args = (struct bench_args_t *)vargs;
8  ms_mergesort( args->a );
9 }
10 
11 /* Input format:
12 %% Section 1
13 TYPE[SIZE]: the array
14 */
15 
16 void input_to_data(int fd, void *vdata) {
17  struct bench_args_t *data = (struct bench_args_t *)vdata;
18  char *p, *s;
19  // Zero-out everything.
20  memset(vdata,0,sizeof(struct bench_args_t));
21  // Load input string
22  p = readfile(fd);
23 
24  s = find_section_start(p,1);
25  STAC(parse_,TYPE,_array)(s, data->a, SIZE);
26  free(p);
27 }
28 
29 void data_to_input(int fd, void *vdata) {
30  struct bench_args_t *data = (struct bench_args_t *)vdata;
31 
33  STAC(write_,TYPE,_array)(fd, data->a, SIZE);
34 }
35 
36 /* Output format:
37 %% Section 1
38 TYPE[SIZE]: the array
39 */
40 
41 void output_to_data(int fd, void *vdata) {
42  struct bench_args_t *data = (struct bench_args_t *)vdata;
43  char *p, *s;
44  // Zero-out everything.
45  memset(vdata,0,sizeof(struct bench_args_t));
46  // Load input string
47  p = readfile(fd);
48 
49  s = find_section_start(p,1);
50  STAC(parse_,TYPE,_array)(s, data->a, SIZE);
51  free(p);
52 }
53 
54 void data_to_output(int fd, void *vdata) {
55  struct bench_args_t *data = (struct bench_args_t *)vdata;
56 
58  STAC(write_,TYPE,_array)(fd, data->a, SIZE);
59 }
60 
61 int check_data( void *vdata, void *vref ) {
62  struct bench_args_t *data = (struct bench_args_t *)vdata;
63  struct bench_args_t *ref = (struct bench_args_t *)vref;
64  int has_errors = 0;
65  int i;
66  TYPE data_sum, ref_sum;
67 
68  // Check sortedness and sum
69  data_sum = data->a[0];
70  ref_sum = ref->a[0];
71  for( i=1; i<SIZE; i++ ) {
72  has_errors |= data->a[i-1] > data->a[i];
73  data_sum += data->a[i];
74  ref_sum += ref->a[i];
75  }
76  has_errors |= (data_sum!=ref_sum);
77 
78  // Return true if it's correct.
79  return !has_errors;
80 }
TYPE a[SIZE]
Definition: sort.h:16
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
#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
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
char * readfile(int fd)
Definition: support.c:34
#define SIZE
Definition: adpcm.c:775
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
void run_benchmark(void *vargs)
Definition: local_support.c:6
void ms_mergesort(TYPE a[SIZE])
Definition: sort.c:31

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