fix warnings
[pluto.git] / examples / jacobi-2d-imper / jacobi-2d-imper.c
blob35569e835193bea2cfa58d2c005e61ed51301505
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <unistd.h>
5 #include <sys/time.h>
7 #include <assert.h>
9 #define N 2000
10 #define T 1000
12 #pragma declarations
13 double a[N][N];
14 double b[N][N];
15 #pragma enddeclarations
17 #ifdef TIME
18 #define IF_TIME(foo) foo;
19 #else
20 #define IF_TIME(foo)
21 #endif
23 void init_array()
25 int i, j;
27 for (i=0; i<N; i++) {
28 for (j=0; j<N; j++) {
29 a[i][j] = ((double)j)/N;
35 void print_array()
37 int i, j;
39 for (i=0; i<N; i++) {
40 for (j=0; j<N; j++) {
41 fprintf(stderr, "%lf ", a[i][j]);
42 if (j%80 == 20) fprintf(stderr, "\n");
45 fprintf(stderr, "\n");
48 double rtclock()
50 struct timezone Tzp;
51 struct timeval Tp;
52 int stat;
53 stat = gettimeofday (&Tp, &Tzp);
54 if (stat != 0) printf("Error return from gettimeofday: %d",stat);
55 return(Tp.tv_sec + Tp.tv_usec*1.0e-6);
57 #define __PLACE_TO_INSERT_FORWARD_DECLARATIONS
59 int main()
61 int t, i, j;
62 double t_start, t_end;
64 init_array();
66 IF_TIME(t_start = rtclock());
68 #pragma scop
69 for (t=0; t<T; t++) {
70 for (i=2; i<N-1; i++) {
71 for (j=2; j<N-1; j++) {
72 b[i][j]= 0.2*(a[i][j]+a[i][j-1]+a[i][1+j]+a[1+i][j]+a[i-1][j]);
75 for (i=2; i<N-1; i++) {
76 for (j=2; j<N-1; j++) {
77 a[i][j]=b[i][j];
81 #pragma endscop
83 IF_TIME(t_end = rtclock());
84 IF_TIME(fprintf(stdout, "%0.6lfs\n", t_end - t_start));
86 if (fopen(".test", "r")) {
87 #ifdef MPI
88 if (my_rank == 0) {
89 print_array();
91 #else
92 print_array();
93 #endif
96 return 0;