| 1 | /**
|
|---|
| 2 | * adi.c: This file is part of the PolyBench/C 3.2 test suite.
|
|---|
| 3 | *
|
|---|
| 4 | * Alternating Direction Implicit solver:
|
|---|
| 5 | *
|
|---|
| 6 | * Contact: Louis-Noel Pouchet <pouchet@cse.ohio-state.edu>
|
|---|
| 7 | * Web address: http://polybench.sourceforge.net
|
|---|
| 8 | * License: /LICENSE.OSU.txt
|
|---|
| 9 | */
|
|---|
| 10 | #include <stdio.h>
|
|---|
| 11 | #include <unistd.h>
|
|---|
| 12 | #include <string.h>
|
|---|
| 13 | #include <math.h>
|
|---|
| 14 | /* Include polybench common header. */
|
|---|
| 15 | #include "polybench/polybench.h"
|
|---|
| 16 | /* Include benchmark-specific header. */
|
|---|
| 17 | /* Default data type is double, default size is 10x1024x1024. */
|
|---|
| 18 | #include "polybench/adi.h"
|
|---|
| 19 | /* Array initialization. */
|
|---|
| 20 |
|
|---|
| 21 | static void init_array(int n,double X[500 + 0][500 + 0],double A[500 + 0][500 + 0],double B[500 + 0][500 + 0])
|
|---|
| 22 | {
|
|---|
| 23 | //int i;
|
|---|
| 24 | //int j;
|
|---|
| 25 | {
|
|---|
| 26 | int c1;
|
|---|
| 27 | int c2;
|
|---|
| 28 | if (n >= 1) {
|
|---|
| 29 | #pragma omp parallel for private(c2)
|
|---|
| 30 | for (c1 = 0; c1 <= n + -1; c1++) {
|
|---|
| 31 | for (c2 = 0; c2 <= n + -1; c2++) {
|
|---|
| 32 | X[c1][c2] = (((double )c1) * (c2 + 1) + 1) / n;
|
|---|
| 33 | A[c1][c2] = (((double )c1) * (c2 + 2) + 2) / n;
|
|---|
| 34 | B[c1][c2] = (((double )c1) * (c2 + 3) + 3) / n;
|
|---|
| 35 | }
|
|---|
| 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 |
|
|---|
| 43 | static void print_array(int n,double X[500 + 0][500 + 0])
|
|---|
| 44 | {
|
|---|
| 45 | int i;
|
|---|
| 46 | int j;
|
|---|
| 47 | for (i = 0; i < n; i++)
|
|---|
| 48 | for (j = 0; j < n; j++) {
|
|---|
| 49 | fprintf(stderr,"%0.2lf ",X[i][j]);
|
|---|
| 50 | if ((i * 500 + j) % 20 == 0)
|
|---|
| 51 | fprintf(stderr,"\n");
|
|---|
| 52 | }
|
|---|
| 53 | fprintf(stderr,"\n");
|
|---|
| 54 | }
|
|---|
| 55 | /* Main computational kernel. The whole function will be timed,
|
|---|
| 56 | including the call and return. */
|
|---|
| 57 |
|
|---|
| 58 | static void kernel_adi(int tsteps,int n,double X[500 + 0][500 + 0],double A[500 + 0][500 + 0],double B[500 + 0][500 + 0])
|
|---|
| 59 | {
|
|---|
| 60 | //int t;
|
|---|
| 61 | //int i1;
|
|---|
| 62 | //int i2;
|
|---|
| 63 |
|
|---|
| 64 | //#pragma scop
|
|---|
| 65 | {
|
|---|
| 66 | int c0;
|
|---|
| 67 | int c2;
|
|---|
| 68 | int c8;
|
|---|
| 69 | for (c0 = 0; c0 <= 9; c0++) {
|
|---|
| 70 | #pragma omp parallel for private(c8)
|
|---|
| 71 | for (c2 = 0; c2 <= 499; c2++) {
|
|---|
| 72 | for (c8 = 1; c8 <= 499; c8++) {
|
|---|
| 73 | B[c2][c8] = B[c2][c8] - A[c2][c8] * A[c2][c8] / B[c2][c8 - 1];
|
|---|
| 74 | }
|
|---|
| 75 | for (c8 = 1; c8 <= 499; c8++) {
|
|---|
| 76 | X[c2][c8] = X[c2][c8] - X[c2][c8 - 1] * A[c2][c8] / B[c2][c8 - 1];
|
|---|
| 77 | }
|
|---|
| 78 | for (c8 = 0; c8 <= 497; c8++) {
|
|---|
| 79 | X[c2][500 - c8 - 2] = (X[c2][500 - 2 - c8] - X[c2][500 - 2 - c8 - 1] * A[c2][500 - c8 - 3]) / B[c2][500 - 3 - c8];
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 | #pragma omp parallel for
|
|---|
| 83 | for (c2 = 0; c2 <= 499; c2++) {
|
|---|
| 84 | X[c2][500 - 1] = X[c2][500 - 1] / B[c2][500 - 1];
|
|---|
| 85 | }
|
|---|
| 86 | #pragma omp parallel for private(c8)
|
|---|
| 87 | for (c2 = 0; c2 <= 499; c2++) {
|
|---|
| 88 | for (c8 = 1; c8 <= 499; c8++) {
|
|---|
| 89 | B[c8][c2] = B[c8][c2] - A[c8][c2] * A[c8][c2] / B[c8 - 1][c2];
|
|---|
| 90 | }
|
|---|
| 91 | for (c8 = 1; c8 <= 499; c8++) {
|
|---|
| 92 | X[c8][c2] = X[c8][c2] - X[c8 - 1][c2] * A[c8][c2] / B[c8 - 1][c2];
|
|---|
| 93 | }
|
|---|
| 94 | for (c8 = 0; c8 <= 497; c8++) {
|
|---|
| 95 | X[500 - 2 - c8][c2] = (X[500 - 2 - c8][c2] - X[500 - c8 - 3][c2] * A[500 - 3 - c8][c2]) / B[500 - 2 - c8][c2];
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | #pragma omp parallel for
|
|---|
| 99 | for (c2 = 0; c2 <= 499; c2++) {
|
|---|
| 100 | X[500 - 1][c2] = X[500 - 1][c2] / B[500 - 1][c2];
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | //#pragma endscop
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | int main(int argc,char **argv)
|
|---|
| 109 | {
|
|---|
| 110 | /* Retrieve problem size. */
|
|---|
| 111 | int n = 500;
|
|---|
| 112 | int tsteps = 10;
|
|---|
| 113 | /* Variable declaration/allocation. */
|
|---|
| 114 | double (*X)[500 + 0][500 + 0];
|
|---|
| 115 | X = ((double (*)[500 + 0][500 + 0])(polybench_alloc_data(((500 + 0) * (500 + 0)),(sizeof(double )))));
|
|---|
| 116 | ;
|
|---|
| 117 | double (*A)[500 + 0][500 + 0];
|
|---|
| 118 | A = ((double (*)[500 + 0][500 + 0])(polybench_alloc_data(((500 + 0) * (500 + 0)),(sizeof(double )))));
|
|---|
| 119 | ;
|
|---|
| 120 | double (*B)[500 + 0][500 + 0];
|
|---|
| 121 | B = ((double (*)[500 + 0][500 + 0])(polybench_alloc_data(((500 + 0) * (500 + 0)),(sizeof(double )))));
|
|---|
| 122 | ;
|
|---|
| 123 | /* Initialize array(s). */
|
|---|
| 124 | init_array(n, *X, *A, *B);
|
|---|
| 125 | /* Start timer. */
|
|---|
| 126 | polybench_timer_start();
|
|---|
| 127 | ;
|
|---|
| 128 | /* Run kernel. */
|
|---|
| 129 | kernel_adi(tsteps,n, *X, *A, *B);
|
|---|
| 130 | /* Stop and print timer. */
|
|---|
| 131 | polybench_timer_stop();
|
|---|
| 132 | ;
|
|---|
| 133 | polybench_timer_print();
|
|---|
| 134 | ;
|
|---|
| 135 | /* Prevent dead-code elimination. All live-out data must be printed
|
|---|
| 136 | by the function call in argument. */
|
|---|
| 137 | if (argc > 42 && !strcmp(argv[0],""))
|
|---|
| 138 | print_array(n, *X);
|
|---|
| 139 | /* Be clean. */
|
|---|
| 140 | free(((void *)X));
|
|---|
| 141 | ;
|
|---|
| 142 | free(((void *)A));
|
|---|
| 143 | ;
|
|---|
| 144 | free(((void *)B));
|
|---|
| 145 | ;
|
|---|
| 146 | return 0;
|
|---|
| 147 | }
|
|---|