PandA-2024.02
floyd-warshall.c
Go to the documentation of this file.
1 
10 /* floyd-warshall.c: this file is part of PolyBench/C */
11 
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <math.h>
16 
17 /* Include polybench common header. */
18 #include <polybench.h>
19 
20 /* Include benchmark-specific header. */
21 #include "floyd-warshall.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array (int n,
27  DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
28 {
29  int i, j;
30 
31  for (i = 0; i < n; i++)
32  for (j = 0; j < n; j++) {
33  path[i][j] = i*j%7+1;
34  if ((i+j)%13 == 0 || (i+j)%7==0 || (i+j)%11 == 0)
35  path[i][j] = 999;
36  }
37 }
38 
39 
40 /* DCE code. Must scan the entire live-out data.
41  Can be used also to check the correctness of the output. */
42 static
43 void print_array(int n,
44  DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
45 
46 {
47  int i, j;
48 
50  POLYBENCH_DUMP_BEGIN("path");
51  for (i = 0; i < n; i++)
52  for (j = 0; j < n; j++) {
53  if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
54  fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, path[i][j]);
55  }
56  POLYBENCH_DUMP_END("path");
58 }
59 
60 
61 /* Main computational kernel. The whole function will be timed,
62  including the call and return. */
63 __attribute__((noinline))
64 void kernel_floyd_warshall(int n,
65  DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
66 {
67  int i, j, k;
68 
69 #pragma scop
70  for (k = 0; k < _PB_N; k++)
71  {
72  for(i = 0; i < _PB_N; i++)
73  for (j = 0; j < _PB_N; j++)
74  path[i][j] = path[i][j] < path[i][k] + path[k][j] ?
75  path[i][j] : path[i][k] + path[k][j];
76  }
77 #pragma endscop
78 
79 }
80 
81 
82 int main(int argc, char** argv)
83 {
84  /* Retrieve problem size. */
85  int n = N;
86 
87  /* Variable declaration/allocation. */
88  POLYBENCH_2D_ARRAY_DECL(path, DATA_TYPE, N, N, n, n);
89 
90 
91  /* Initialize array(s). */
92  init_array (n, POLYBENCH_ARRAY(path));
93 
94  /* Start timer. */
96 
97  /* Run kernel. */
98  kernel_floyd_warshall (n, POLYBENCH_ARRAY(path));
99 
100  /* Stop and print timer. */
103 
104  /* Prevent dead-code elimination. All live-out data must be printed
105  by the function call in argument. */
107 
108  /* Be clean. */
109  POLYBENCH_FREE_ARRAY(path);
110 
111  return 0;
112 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
int main(int argc, char **argv)
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
static void print_array(int n, DATA_TYPE POLYBENCH_2D(path, N, N, n, n))
static const uint32_t k[]
Definition: sha-256.c:22
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define N
Definition: dfdiv.c:60
#define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:131
#define DATA_PRINTF_MODIFIER
Definition: correlation.h:73
#define polybench_prevent_dce(func)
Definition: polybench.h:170
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
static void init_array(int n, DATA_TYPE POLYBENCH_2D(path, N, N, n, n))
This version is stamped on May 10, 2016.
#define _PB_N
Definition: correlation.h:49
#define polybench_stop_instruments
Definition: polybench.h:177
#define polybench_print_instruments
Definition: polybench.h:178
#define polybench_start_instruments
Definition: polybench.h:176
#define DATA_TYPE
Definition: correlation.h:72

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