source: CIVL/examples/omp/DataRaceBench/micro-benchmarks/jacobi2d-parallel-no.c@ af3b8e4

1.23 2.0 main test-branch
Last change on this file since af3b8e4 was 36a61f3, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Commit DataRaceBench into CIVL examples

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@4225 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[36a61f3]1/**
2 * jacobi-2d-imper.c: This file is part of the PolyBench/C 3.2 test suite.
3 * Jacobi with array copying, no reduction.
4 *
5 * Contact: Louis-Noel Pouchet <pouchet@cse.ohio-state.edu>
6 * Web address: http://polybench.sourceforge.net
7 */
8#include <stdio.h>
9#include <unistd.h>
10#include <string.h>
11#include <math.h>
12/* Include polybench common header. */
13#include <polybench.h>
14/* Include benchmark-specific header. */
15/* Default data type is double, default size is 20x1000. */
16#include "jacobi-2d-imper.h"
17/* Array initialization. */
18
19static void init_array(int n,double A[500 + 0][500 + 0],double B[500 + 0][500 + 0])
20{
21 int i;
22 int j;
23{
24 int c2;
25 int c1;
26 if (n >= 1) {
27#pragma omp parallel for private(c2)
28 for (c1 = 0; c1 <= n + -1; c1++) {
29 for (c2 = 0; c2 <= n + -1; c2++) {
30 A[c1][c2] = (((double )c1) * (c2 + 2) + 2) / n;
31 B[c1][c2] = (((double )c1) * (c2 + 3) + 3) / n;
32 }
33 }
34 }
35 }
36}
37/* DCE code. Must scan the entire live-out data.
38 Can be used also to check the correctness of the output. */
39
40static void print_array(int n,double A[500 + 0][500 + 0])
41{
42 int i;
43 int j;
44 for (i = 0; i < n; i++)
45 for (j = 0; j < n; j++) {
46 fprintf(stderr,"%0.2lf ",A[i][j]);
47 if ((i * n + j) % 20 == 0)
48 fprintf(stderr,"\n");
49 }
50 fprintf(stderr,"\n");
51}
52/* Main computational kernel. The whole function will be timed,
53 including the call and return. */
54
55static void kernel_jacobi_2d_imper(int tsteps,int n,double A[500 + 0][500 + 0],double B[500 + 0][500 + 0])
56{
57 int t;
58 int i;
59 int j;
60
61#pragma scop
62{
63 int c2;
64 int c1;
65 int c0;
66 for (c2 = 1; c2 <= 498; c2++) {
67 B[1][c2] = 0.2 * (A[1][c2] + A[1][c2 - 1] + A[1][1 + c2] + A[1 + 1][c2] + A[1 - 1][c2]);
68 }
69 for (c0 = 2; c0 <= 525; c0++) {
70 if (c0 <= 28) {
71 if ((2 * c0 + 1) % 3 == 0) {
72 for (c2 = ((2 * c0 + 1) * 3 < 0?-(-(2 * c0 + 1) / 3) : ((3 < 0?(-(2 * c0 + 1) + - 3 - 1) / - 3 : (2 * c0 + 1 + 3 - 1) / 3))); c2 <= (((2 * c0 + 1492) * 3 < 0?((3 < 0?-((-(2 * c0 + 1492) + 3 + 1) / 3) : -((-(2 * c0 + 1492) + 3 - 1) / 3))) : (2 * c0 + 1492) / 3)); c2++) {
73 B[1][(-2 * c0 + 3 * c2 + 2) / 3] = 0.2 * (A[1][(-2 * c0 + 3 * c2 + 2) / 3] + A[1][(-2 * c0 + 3 * c2 + 2) / 3 - 1] + A[1][1 + (-2 * c0 + 3 * c2 + 2) / 3] + A[1 + 1][(-2 * c0 + 3 * c2 + 2) / 3] + A[1 - 1][(-2 * c0 + 3 * c2 + 2) / 3]);
74 }
75 }
76 }
77#pragma omp parallel for private(c2)
78 for (c1 = ((((2 * c0 + 2) * 3 < 0?-(-(2 * c0 + 2) / 3) : ((3 < 0?(-(2 * c0 + 2) + - 3 - 1) / - 3 : (2 * c0 + 2 + 3 - 1) / 3)))) > c0 + -9?(((2 * c0 + 2) * 3 < 0?-(-(2 * c0 + 2) / 3) : ((3 < 0?(-(2 * c0 + 2) + - 3 - 1) / - 3 : (2 * c0 + 2 + 3 - 1) / 3)))) : c0 + -9); c1 <= (((((2 * c0 + 498) * 3 < 0?((3 < 0?-((-(2 * c0 + 498) + 3 + 1) / 3) : -((-(2 * c0 + 498) + 3 - 1) / 3))) : (2 * c0 + 498) / 3)) < c0?(((2 * c0 + 498) * 3 < 0?((3 < 0?-((-(2 * c0 + 498) + 3 + 1) / 3) : -((-(2 * c0 + 498) + 3 - 1) / 3))) : (2 * c0 + 498) / 3)) : c0)); c1++) {
79 B[-2 * c0 + 3 * c1][1] = 0.2 * (A[-2 * c0 + 3 * c1][1] + A[-2 * c0 + 3 * c1][1 - 1] + A[-2 * c0 + 3 * c1][1 + 1] + A[1 + (-2 * c0 + 3 * c1)][1] + A[-2 * c0 + 3 * c1 - 1][1]);
80 for (c2 = 2 * c0 + -2 * c1 + 2; c2 <= 2 * c0 + -2 * c1 + 498; c2++) {
81 A[-2 * c0 + 3 * c1 + -1][-2 * c0 + 2 * c1 + c2 + -1] = B[-2 * c0 + 3 * c1 + -1][-2 * c0 + 2 * c1 + c2 + -1];
82 B[-2 * c0 + 3 * c1][-2 * c0 + 2 * c1 + c2] = 0.2 * (A[-2 * c0 + 3 * c1][-2 * c0 + 2 * c1 + c2] + A[-2 * c0 + 3 * c1][-2 * c0 + 2 * c1 + c2 - 1] + A[-2 * c0 + 3 * c1][1 + (-2 * c0 + 2 * c1 + c2)] + A[1 + (-2 * c0 + 3 * c1)][-2 * c0 + 2 * c1 + c2] + A[-2 * c0 + 3 * c1 - 1][-2 * c0 + 2 * c1 + c2]);
83 }
84 A[-2 * c0 + 3 * c1 + -1][498] = B[-2 * c0 + 3 * c1 + -1][498];
85 }
86 if (c0 >= 499) {
87 if ((2 * c0 + 1) % 3 == 0) {
88 for (c2 = ((2 * c0 + -992) * 3 < 0?-(-(2 * c0 + -992) / 3) : ((3 < 0?(-(2 * c0 + -992) + - 3 - 1) / - 3 : (2 * c0 + -992 + 3 - 1) / 3))); c2 <= (((2 * c0 + 499) * 3 < 0?((3 < 0?-((-(2 * c0 + 499) + 3 + 1) / 3) : -((-(2 * c0 + 499) + 3 - 1) / 3))) : (2 * c0 + 499) / 3)); c2++) {
89 A[498][(-2 * c0 + 3 * c2 + 995) / 3] = B[498][(-2 * c0 + 3 * c2 + 995) / 3];
90 }
91 }
92 }
93 }
94 for (c2 = 20; c2 <= 517; c2++) {
95 A[498][c2 + -19] = B[498][c2 + -19];
96 }
97 }
98
99#pragma endscop
100}
101
102int main(int argc,char **argv)
103{
104/* Retrieve problem size. */
105 int n = 500;
106 int tsteps = 10;
107/* Variable declaration/allocation. */
108 double (*A)[500 + 0][500 + 0];
109 A = ((double (*)[500 + 0][500 + 0])(polybench_alloc_data(((500 + 0) * (500 + 0)),(sizeof(double )))));
110 ;
111 double (*B)[500 + 0][500 + 0];
112 B = ((double (*)[500 + 0][500 + 0])(polybench_alloc_data(((500 + 0) * (500 + 0)),(sizeof(double )))));
113 ;
114/* Initialize array(s). */
115 init_array(n, *A, *B);
116/* Start timer. */
117 polybench_timer_start();
118 ;
119/* Run kernel. */
120 kernel_jacobi_2d_imper(tsteps,n, *A, *B);
121/* Stop and print timer. */
122 polybench_timer_stop();
123 ;
124 polybench_timer_print();
125 ;
126/* Prevent dead-code elimination. All live-out data must be printed
127 by the function call in argument. */
128 if (argc > 42 && !strcmp(argv[0],""))
129 print_array(n, *A);
130/* Be clean. */
131 free(((void *)A));
132 ;
133 free(((void *)B));
134 ;
135 return 0;
136}
Note: See TracBrowser for help on using the repository browser.