| /** |
| * trmm.c: This file is part of the PolyBench/C 3.2 test suite. |
| * |
| * |
| * Contact: Louis-Noel Pouchet <pouchet@cse.ohio-state.edu> |
| * Web address: http://polybench.sourceforge.net |
| */ |
| #include <stdio.h> |
| #include <unistd.h> |
| #include <string.h> |
| #include <math.h> |
| |
| /* Include polybench common header. */ |
| #include <polybench.h> |
| |
| /* Include benchmark-specific header. */ |
| /* Default data type is double, default size is 4000. */ |
| #include "trmm.h" |
| |
| |
| /* Array initialization. */ |
| static |
| void init_array(int ni, |
| DATA_TYPE *alpha, |
| DATA_TYPE POLYBENCH_2D(A,NI,NI,ni,ni), |
| DATA_TYPE POLYBENCH_2D(B,NI,NI,ni,ni)) |
| { |
| int i, j; |
| |
| *alpha = 32412; |
| for (i = 0; i < ni; i++) |
| for (j = 0; j < ni; j++) { |
| A[i][j] = ((DATA_TYPE) i*j) / ni; |
| B[i][j] = ((DATA_TYPE) i*j) / ni; |
| } |
| } |
| |
| |
| /* 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 ni, |
| DATA_TYPE POLYBENCH_2D(B,NI,NI,ni,ni)) |
| { |
| int i, j; |
| char *printmat = malloc(ni*8); |
| |
| for (i = 0; i < ni; i++) { |
| for (j = 0; j < ni; j++) |
| print_element(B[i][j], j*8, printmat); |
| fputs(printmat, stderr); |
| } |
| free(printmat); |
| } |
| |
| |
| /* Main computational kernel. The whole function will be timed, |
| including the call and return. */ |
| static |
| void kernel_trmm(int ni, |
| DATA_TYPE alpha, |
| DATA_TYPE POLYBENCH_2D(A,NI,NI,ni,ni), |
| DATA_TYPE POLYBENCH_2D(B,NI,NI,ni,ni)) |
| { |
| int i, j, k; |
| |
| #pragma scop |
| /* B := alpha*A'*B, A triangular */ |
| for (i = 1; i < _PB_NI; i++) |
| for (j = 0; j < _PB_NI; j++) |
| for (k = 0; k < i; k++) |
| B[i][j] += alpha * A[i][k] * B[j][k]; |
| #pragma endscop |
| |
| } |
| |
| |
| int main(int argc, char** argv) |
| { |
| /* Retrieve problem size. */ |
| int ni = NI; |
| |
| /* Variable declaration/allocation. */ |
| DATA_TYPE alpha; |
| POLYBENCH_2D_ARRAY_DECL(A,DATA_TYPE,NI,NI,ni,ni); |
| POLYBENCH_2D_ARRAY_DECL(B,DATA_TYPE,NI,NI,ni,ni); |
| |
| /* Initialize array(s). */ |
| init_array (ni, &alpha, POLYBENCH_ARRAY(A), POLYBENCH_ARRAY(B)); |
| |
| /* Start timer. */ |
| polybench_start_instruments; |
| |
| /* Run kernel. */ |
| kernel_trmm (ni, alpha, POLYBENCH_ARRAY(A), POLYBENCH_ARRAY(B)); |
| |
| /* 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(ni, POLYBENCH_ARRAY(B))); |
| |
| /* Be clean. */ |
| POLYBENCH_FREE_ARRAY(A); |
| POLYBENCH_FREE_ARRAY(B); |
| |
| return 0; |
| } |