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

bicg application

parent dbf7c62f
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
*/
/* bicg.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 "bicg.h"
/* Array initialization. */
static
void init_array (int m, int n,
DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
DATA_TYPE POLYBENCH_1D(r,N,n),
DATA_TYPE POLYBENCH_1D(p,M,m))
{
int i, j;
for (i = 0; i < m; i++)
p[i] = (DATA_TYPE)(i % m) / m;
for (i = 0; i < n; i++) {
r[i] = (DATA_TYPE)(i % n) / n;
for (j = 0; j < m; j++)
A[i][j] = (DATA_TYPE) (i*(j+1) % n)/n;
}
}
/* 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 m, int n,
DATA_TYPE POLYBENCH_1D(s,M,m),
DATA_TYPE POLYBENCH_1D(q,N,n))
{
int i;
POLYBENCH_DUMP_START;
POLYBENCH_DUMP_BEGIN("s");
for (i = 0; i < m; i++) {
if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, s[i]);
}
POLYBENCH_DUMP_END("s");
POLYBENCH_DUMP_BEGIN("q");
for (i = 0; i < n; i++) {
if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, q[i]);
}
POLYBENCH_DUMP_END("q");
POLYBENCH_DUMP_FINISH;
}
/* Main computational kernel. The whole function will be timed,
including the call and return. */
static
void kernel_bicg(int m, int n,
DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
DATA_TYPE POLYBENCH_1D(s,M,m),
DATA_TYPE POLYBENCH_1D(q,N,n),
DATA_TYPE POLYBENCH_1D(p,M,m),
DATA_TYPE POLYBENCH_1D(r,N,n))
{
int i, j;
#pragma scop
for (i = 0; i < _PB_M; i++)
s[i] = 0;
for (i = 0; i < _PB_N; i++)
{
q[i] = SCALAR_VAL(0.0);
for (j = 0; j < _PB_M; j++)
{
s[j] = s[j] + r[i] * A[i][j];
q[i] = q[i] + A[i][j] * p[j];
}
}
#pragma endscop
}
int main(int argc, char** argv)
{
/* Retrieve problem size. */
int n = N;
int m = M;
/* Variable declaration/allocation. */
POLYBENCH_2D_ARRAY_DECL(A, DATA_TYPE, N, M, n, m);
POLYBENCH_1D_ARRAY_DECL(s, DATA_TYPE, M, m);
POLYBENCH_1D_ARRAY_DECL(q, DATA_TYPE, N, n);
POLYBENCH_1D_ARRAY_DECL(p, DATA_TYPE, M, m);
POLYBENCH_1D_ARRAY_DECL(r, DATA_TYPE, N, n);
/* Initialize array(s). */
init_array (m, n,
POLYBENCH_ARRAY(A),
POLYBENCH_ARRAY(r),
POLYBENCH_ARRAY(p));
/* Start timer. */
polybench_start_instruments;
/* Run kernel. */
kernel_bicg (m, n,
POLYBENCH_ARRAY(A),
POLYBENCH_ARRAY(s),
POLYBENCH_ARRAY(q),
POLYBENCH_ARRAY(p),
POLYBENCH_ARRAY(r));
/* 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(m, n, POLYBENCH_ARRAY(s), POLYBENCH_ARRAY(q)));
/* Be clean. */
POLYBENCH_FREE_ARRAY(A);
POLYBENCH_FREE_ARRAY(s);
POLYBENCH_FREE_ARRAY(q);
POLYBENCH_FREE_ARRAY(p);
POLYBENCH_FREE_ARRAY(r);
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 _BICG_H
# define _BICG_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(M) && !defined(N)
/* Define sample dataset sizes. */
# ifdef MINI_DATASET
# define M 38
# define N 42
# endif
# ifdef SMALL_DATASET
# define M 116
# define N 124
# endif
# ifdef MEDIUM_DATASET
# define M 390
# define N 410
# endif
# ifdef LARGE_DATASET
# define M 1900
# define N 2100
# endif
# ifdef EXTRALARGE_DATASET
# define M 1800
# define N 2200
# endif
#endif /* !(M N) */
# define _PB_M POLYBENCH_LOOP_BOUND(M,m)
# 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_DOUBLE
# 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 /* !_BICG_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