PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "bfs.h"
2 #include <string.h>
3 #include <unistd.h>
4 
5 int INPUT_SIZE = sizeof(struct bench_args_t);
6 
7 void run_benchmark( void *vargs ) {
8  struct bench_args_t *args = (struct bench_args_t *)vargs;
9  bfs(args->nodes, args->edges, args->starting_node, args->level, args->level_counts);
10 }
11 
12 /* Input format:
13 %% Section 1
14 uint64_t[1]: starting node
15 %% Section 2
16 uint64_t[N_NODES*2]: node structures (start and end indices of edge lists)
17 %% Section 3
18 uint64_t[N_EDGES]: edges structures (just destination node id)
19 */
20 
21 void input_to_data(int fd, void *vdata) {
22  struct bench_args_t *data = (struct bench_args_t *)vdata;
23  char *p, *s;
24  uint64_t *nodes;
25  int64_t i;
26 
27  // Zero-out everything.
28  memset(vdata,0,sizeof(struct bench_args_t));
29  // Max-ify levels
30  for(i=0; i<N_NODES; i++) {
31  data->level[i]=MAX_LEVEL;
32  }
33  // Load input string
34  p = readfile(fd);
35  // Section 1: starting node
36  s = find_section_start(p,1);
37  parse_uint64_t_array(s, &data->starting_node, 1);
38 
39  // Section 2: node structures
40  s = find_section_start(p,2);
41  nodes = (uint64_t *)malloc(N_NODES*2*sizeof(uint64_t));
42  parse_uint64_t_array(s, nodes, N_NODES*2);
43  for(i=0; i<N_NODES; i++) {
44  data->nodes[i].edge_begin = nodes[2*i];
45  data->nodes[i].edge_end = nodes[2*i+1];
46  }
47  free(nodes);
48  // Section 3: edge structures
49  s = find_section_start(p,3);
50  parse_uint64_t_array(s, (uint64_t *)(data->edges), N_EDGES);
51  free(p);
52 }
53 
54 void data_to_input(int fd, void *vdata) {
55  uint64_t *nodes;
56  int64_t i;
57 
58  struct bench_args_t *data = (struct bench_args_t *)vdata;
59  // Section 1: starting node
61  write_uint64_t_array(fd, &data->starting_node, 1);
62  // Section 2: node structures
64  nodes = (uint64_t *)malloc(N_NODES*2*sizeof(uint64_t));
65  for(i=0; i<N_NODES; i++) {
66  nodes[2*i] = data->nodes[i].edge_begin;
67  nodes[2*i+1]= data->nodes[i].edge_end;
68  }
69  write_uint64_t_array(fd, nodes, N_NODES*2);
70  free(nodes);
71  // Section 3: edge structures
73  write_uint64_t_array(fd, (uint64_t *)(&data->edges), N_EDGES);
74 }
75 
76 /* Output format:
77 %% Section 1
78 uint64_t[N_LEVELS]: horizon counts
79 */
80 
81 void output_to_data(int fd, void *vdata) {
82  struct bench_args_t *data = (struct bench_args_t *)vdata;
83  char *p, *s;
84  // Zero-out everything.
85  memset(vdata,0,sizeof(struct bench_args_t));
86  // Load input string
87  p = readfile(fd);
88  // Section 1: horizon counts
89  s = find_section_start(p,1);
91  free(p);
92 }
93 
94 void data_to_output(int fd, void *vdata) {
95  struct bench_args_t *data = (struct bench_args_t *)vdata;
96  // Section 1
99 }
100 
101 int check_data( void *vdata, void *vref ) {
102  struct bench_args_t *data = (struct bench_args_t *)vdata;
103  struct bench_args_t *ref = (struct bench_args_t *)vref;
104  int has_errors = 0;
105  int i;
106 
107  // Check that the horizons have the same number of nodes
108  for(i=0; i<N_LEVELS; i++) {
109  has_errors |= (data->level_counts[i]!=ref->level_counts[i]);
110  }
111 
112  // Return true if it's correct.
113  return !has_errors;
114 }
struct Node nodes[7]
#define N_NODES
Definition: bfs.h:18
node_index_t starting_node
Definition: bfs.h:49
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
int INPUT_SIZE
Definition: local_support.c:4
int parse_uint64_t_array(char *s, uint64_t *arr, int n)
#define N_LEVELS
Definition: bfs.h:22
void bfs(node_t nodes[N_NODES], edge_t edges[N_EDGES], node_index_t starting_node, level_t level[N_NODES], edge_index_t level_counts[N_LEVELS])
Definition: bfs.c:9
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
edge_t edges[N_EDGES]
Definition: bfs.h:48
int write_uint64_t_array(int fd, uint64_t *arr, int n)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
node_t nodes[N_NODES]
Definition: bfs.h:47
char * readfile(int fd)
Definition: support.c:34
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
#define MAX_LEVEL
Definition: bfs.h:41
edge_index_t edge_begin
Definition: bfs.h:36
char * find_section_start(char *s, int n)
Definition: support.c:56
level_t level[N_NODES]
Definition: bfs.h:50
void run_benchmark(void *vargs)
Definition: local_support.c:6
edge_index_t level_counts[N_LEVELS]
Definition: bfs.h:51
#define N_EDGES
Definition: bfs.h:19
edge_index_t edge_end
Definition: bfs.h:37

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