-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
199 lines (157 loc) · 5.66 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// main.c - Poisson problem in 3D
#include <stdio.h>
#include <stdlib.h>
#include "alloc3d.h"
#include <math.h>
#include "InitArrays.h"
#include <omp.h>
#include <mpi.h>
#include "HelperFunctions.h"
#include "Algorithms.h"
#include "Checks.h"
#define N_DEFAULT 100
//#define case_type 4 // 0 for correctness test,
// 1 for blocked Gauss Seidel,
// 2 for non blocked Gauss Seidel,
// 3 for Red and Black Gauss Seidel.
// 4 for Red and Black Gauss Seidel && OpenMP.
// 5 for Red and Black Gauss Seidel v2.
// 6 for Red and Black Gauss Seidel v3.
// 7 for Red and Black Gauss Seidel && OpenMP NUMA
// 8 for Red and Black Gauss Seidel && OpenMPv2.
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int size, rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int N = N_DEFAULT;
int iter_max = 1000;
double tolerance;
int case_type;
int output_type = 0;
char *output_prefix = "poisson_res";
char *output_ext = "";
char output_filename[FILENAME_MAX];
double ***u_anal = NULL;
double ***u = NULL;
double ***f = NULL;
/* get the paramters from the command line */
N = atoi(argv[1]); // grid size
iter_max = atoi(argv[2]); // max. no. of iterations
tolerance = atof(argv[3]); // tolerance
case_type = atof(argv[4]); // choose case type
if (argc == 6) {
output_type = atoi(argv[5]); // output type
}
//Check if valid size/N combination
int int_sqrt_size = InputCheck(N,size);
int n = N/int_sqrt_size + 2;
N = N + 2;
double t1,time;
// allocate memory
if ( (u = d_malloc_3d(n, n, N)) == NULL ) {
printf("array u: allocation failed on rank %d\n",rank);
//exit(-1);
free(u);
MPI_Finalize();
return 0;
}
if ( (f = d_malloc_3d(n, n, N)) == NULL ) {
printf("array f: allocation failed on rank %d\n",rank);
//exit(-1);
free(u);
free(f);
MPI_Finalize();
return 0;
}
// Switch between different cases!
switch(case_type){
case 0: //Correctness test
if (rank == 0){
printf("---Running correctness check with blocked Gauss Seidel---\n");
}
InitU_cortest(u, n, N);
InitF_cortest(f, n, N, size, rank);
MPI_Barrier(MPI_COMM_WORLD);
Gauss_Seidel_Blocked(f,u,n,N,iter_max,&tolerance);
if ( (u_anal = d_malloc_3d(n, n, N)) == NULL ) {
printf("array u_anal: allocation failed on rank %d\n",rank);
exit(-1);
}
double error = CorrectnessCheck(u,u_anal,rank,int_sqrt_size,n,N);
free(u_anal);
break;
case 1: // Blocked Gauss Seidel
if (rank == 0){
printf("---Running blocked Gauss Seidel---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_Seidel_Blocked(f,u,n,N,iter_max,&tolerance);
break;
case 2: // non-blocked Gauss Seidel
if (rank == 0){
printf("---Running non blocked Gauss Seidel---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_Seidel_nonblocked(f,u,n,N,iter_max,&tolerance);
break;
case 3: // Red and Black Gauss Seidel non blocked
if (rank == 0){
printf("---Running Gauss Seidel with red and black---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_seidel_redblack(f,u,n,N,iter_max,&tolerance);
break;
case 4: // Red and Black Gauss Seidel with openMP
if (rank == 0){
printf("---Running HYBRID Gauss Seidel with red and black and OpenMP---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_seidel_redblack_mp(f,u,n,N,iter_max,&tolerance);
break;
case 5: // Red and Black Gauss Seidel non blocked v2!!
if (rank == 0){
printf("---Running Gauss Seidel with red and black clean-code---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_seidel_redblack_v2(f,u,n,N,iter_max,&tolerance);
break;
case 6: // Red and Black Gauss Seidel non blocked v3!!
if (rank == 0){
printf("---Running Gauss Seidel with red and black v3---\n");
}
InitializeU(u, n, N);
InitializeF(f, n, N, size, rank);
Gauss_seidel_redblack_v3(f,u,n,N,iter_max,&tolerance);
break;
case 7: // Red and Black Gauss Seidel with openMP NUMA
if (rank == 0){
printf("---Running HYBRID Gauss Seidel with red and black and OpenMP NUMA---\n");
}
InitializeU_mp(u, n, N);
InitializeF_mp(f, n, N, size, rank);
Gauss_seidel_redblack_mp(f,u,n,N,iter_max,&tolerance);
break;
case 8: // Red and Black Gauss Seidel with openMP_v2
if (rank == 0){
printf("---Running HYBRID Gauss Seidel with red and black and OpenMP V2---\n");
}
InitializeU_mp(u, n, N);
InitializeF_mp(f, n, N, size, rank);
Gauss_seidel_redblack_mp_v2(f,u,n,N,iter_max,&tolerance);
break;
default:
printf("Incorrect case_type, chose 0 for timing - 1 for correctness check\n");
break;
}
// de-allocate memory
free(u);
free(f);
MPI_Finalize();
return 0;
}