Skip to content
Snippets Groups Projects
Commit 300fd9f7 authored by Daniel Maier's avatar Daniel Maier
Browse files

add benchmark floyd-warshall

parent f5e56762
No related branches found
No related tags found
No related merge requests found
/**
* This version is stamped on May 10, 2016
*
* Contact:
* Louis-Noel Pouchet <pouchet.ohio-state.edu>
* Tomofumi Yuki <tomofumi.yuki.fr>
*
* Web address: http://polybench.sourceforge.net
*/
/* floyd-warshall.c: this file is part of PolyBench/C */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
/* Include polybench common header. */
#include <polybench.h>
/* Include benchmark-specific header. */
#include "floyd-warshall.h"
/* Array initialization. */
static
void init_array (int n,
DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
{
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
path[i][j] = i*j%7+1;
if ((i+j)%13 == 0 || (i+j)%7==0 || (i+j)%11 == 0)
path[i][j] = 999;
}
}
/* DCE code. Must scan the entire live-out data.
Can be used also to check the correctness of the output. */
static
void print_array(int n,
DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
{
int i, j;
POLYBENCH_DUMP_START;
POLYBENCH_DUMP_BEGIN("path");
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, path[i][j]);
}
POLYBENCH_DUMP_END("path");
POLYBENCH_DUMP_FINISH;
}
static
void calc_error(int n,
DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
{
for (int i = 0; i < n*n; i++) {
}
}
/* Main computational kernel. The whole function will be timed,
including the call and return. */
static
void kernel_floyd_warshall(int n,
DATA_TYPE POLYBENCH_2D(path,N,N,n,n))
{
int i, j, k;
#pragma scop
for (k = 0; k < _PB_N; k++)
{
for(i = 0; i < _PB_N; i++)
for (j = 0; j < _PB_N; j++)
path[i][j] = path[i][j] < path[i][k] + path[k][j] ?
path[i][j] : path[i][k] + path[k][j];
}
#pragma endscop
}
int main(int argc, char** argv)
{
/* Retrieve problem size. */
int n = N;
/* Variable declaration/allocation. */
POLYBENCH_2D_ARRAY_DECL(path, DATA_TYPE, N, N, n, n);
/* Initialize array(s). */
init_array (n, POLYBENCH_ARRAY(path));
/* Start timer. */
polybench_start_instruments;
/* Run kernel. */
kernel_floyd_warshall (n, POLYBENCH_ARRAY(path));
/* Stop and print timer. */
polybench_stop_instruments;
polybench_print_instruments;
/* Prevent dead-code elimination. All live-out data must be printed
by the function call in argument. */
polybench_prevent_dce(print_array(n, POLYBENCH_ARRAY(path)));
/* Be clean. */
POLYBENCH_FREE_ARRAY(path);
return 0;
}
/**
* This version is stamped on May 10, 2016
*
* Contact:
* Louis-Noel Pouchet <pouchet.ohio-state.edu>
* Tomofumi Yuki <tomofumi.yuki.fr>
*
* Web address: http://polybench.sourceforge.net
*/
#ifndef _FLOYD_WARSHALL_H
# define _FLOYD_WARSHALL_H
/* Default to LARGE_DATASET. */
# if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(MEDIUM_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
# define LARGE_DATASET
# endif
# if !defined(N)
/* Define sample dataset sizes. */
# ifdef MINI_DATASET
# define N 60
# endif
# ifdef SMALL_DATASET
# define N 180
# endif
# ifdef MEDIUM_DATASET
# define N 500
# endif
# ifdef LARGE_DATASET
# define N 2800
# endif
# ifdef EXTRALARGE_DATASET
# define N 5600
# endif
#endif /* !(N) */
# define _PB_N POLYBENCH_LOOP_BOUND(N,n)
/* Default data type */
# if !defined(DATA_TYPE_IS_INT) && !defined(DATA_TYPE_IS_FLOAT) && !defined(DATA_TYPE_IS_DOUBLE)
# define DATA_TYPE_IS_INT
# endif
#ifdef DATA_TYPE_IS_INT
# define DATA_TYPE int
# define DATA_PRINTF_MODIFIER "%d "
#endif
#ifdef DATA_TYPE_IS_FLOAT
# define DATA_TYPE float
# define DATA_PRINTF_MODIFIER "%0.2f "
# define SCALAR_VAL(x) x##f
# define SQRT_FUN(x) sqrtf(x)
# define EXP_FUN(x) expf(x)
# define POW_FUN(x,y) powf(x,y)
# endif
#ifdef DATA_TYPE_IS_DOUBLE
# define DATA_TYPE double
# define DATA_PRINTF_MODIFIER "%0.2lf "
# define SCALAR_VAL(x) x
# define SQRT_FUN(x) sqrt(x)
# define EXP_FUN(x) exp(x)
# define POW_FUN(x,y) pow(x,y)
# endif
#endif /* !_FLOYD_WARSHALL_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment