source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB055-jacobi2d-parallel-no.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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