-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
executable file
·212 lines (195 loc) · 4.76 KB
/
test.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
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
============================================================================
Name : test.c
Author : Julian Fietkau
Copyright : Julian Fietkau
Description : a small test-case 4 developing
============================================================================
*/
#include <stdio.h>
#include <string.h>
#include <omp.h>
#include "matrix.h"
#include "openMP.h"
#include "pThreads.h"
#include "openMPI.h"
/*
* a small test-case 4 developing
*/
int test(int n) {
if((n < 1) || (n > 4)){
perror("test() is only defined in range from 1 upto 4.");
return 0;
}
printf("\nRUNNING MATRIX MULTIPLICATION TESTCASE: \n");
char* m1string = "[1,2;3,4;5,6]";
char* m2string = "[1,2,3;4,5,6]";
char* identityMatrix3 = "[1,0,0;0,1,0;0,0,1]";
char* m1m2string = "[9,12,15;19,26,33;29,40,51]"; // m1 * m2
char* m2m1string = "[22,28;49,64]"; // m2 * m1
matrix matrix1;
matrix matrix2;
matrix m1m2;
matrix m2m1;
matrix identity3;
matrix identityBig;
parse_matrix(&matrix1, m1string);
parse_matrix(&matrix2, m2string);
parse_matrix(&m1m2, m1m2string);
parse_matrix(&m2m1, m2m1string);
parse_matrix(&identity3, identityMatrix3);
matrix result;
createMatrix(&result, 0,0);
/*
* CASE 1 A*B
*/
printf("Testing A (3x2) * B (2x3) = C (2x2) :");
destroyMatrix(&result);
switch (n) {
case 1: printf("sequential program");
multiplication(&result, &matrix1, &matrix2);
break;
case 2:
printf(" with openMP");
openMPmultiplication(&result, &matrix1, &matrix2);
break;
case 3:
printf(" with pThreads");
pThreadsMultiplication(&result, &matrix1, &matrix2);
break;
case 4:
printf(" with MPI");
openMpiMultiplication(&result, &matrix1, &matrix2);
break;
}
if (!equals(&result, &m1m2)) {
printf(" ... false \n");
}
else{printf(" ... ok \n");}
//printMatrix(&result);
/*
* CASE 2 B*A
*/
printf("Testing B (2x3) * A (3x2) = C (3x3) :");
destroyMatrix(&result);
switch (n) {
case 1: printf("sequential program");
multiplication(&result, &matrix2, &matrix1);
break;
case 2:
printf(" with openMP");
openMPmultiplication(&result, &matrix2, &matrix1);
break;
case 3:
printf(" with pThreads");
pThreadsMultiplication(&result, &matrix2, &matrix1);
break;
case 4:
printf(" with MPI");
openMpiMultiplication(&result, &matrix2, &matrix1);
break;
}
if (!equals(&result, &m2m1)) {
printf(" ... false \n");
}
else{printf(" ... ok \n");}
//printMatrix(&result);
/*
* CASE 3 E*E
*/
printf("Testing E (3x3) * E (3x3) = C (3x3) :");
destroyMatrix(&result);
switch (n) {
case 1: printf("sequential program");
multiplication(&result, &identity3, &identity3);
break;
case 2:
printf(" with openMP");
openMPmultiplication(&result, &identity3, &identity3);
break;
case 3:
printf(" with pThreads");
pThreadsMultiplication(&result, &identity3, &identity3);
break;
case 4:
printf(" with MPI");
openMpiMultiplication(&result, &identity3, &identity3);
break;
}
if (!equals(&result, &identity3)) {
printf(" ... false \n");
}
else{printf(" ... ok \n");}
//printMatrix(&result);
//TODO if big is to high, there is a runtime error : no such file or directory
int big = 3;
createIdentityMatrix(&identityBig, big);
/*
* CASE 4 E.big*E.big
*/
printf("Testing E (%dx%d) * E (%dx%d) = C %dx%d) :",big,big,big,big,big,big);
destroyMatrix(&result);
switch (n) {
case 1: printf(" sequential program");
multiplication(&result, &identityBig, &identityBig);
break;
case 2:
printf(" with openMP");
openMPmultiplication(&result, &identityBig, &identityBig);
break;
case 3:
printf(" with pThreads");
pThreadsMultiplication(&result, &identityBig, &identityBig);
break;
case 4:
printf(" with MPI");
openMpiMultiplication(&result, &identityBig, &identityBig);
break;
}
if (!equals(&result, &identityBig)) {
printf(" ... false \n");
}
else{printf(" ... ok \n");}
//printMatrix(&result);
destroyMatrix(&result);
destroyMatrix(&matrix1);
destroyMatrix(&matrix2);
destroyMatrix(&m1m2);
destroyMatrix(&identity3);
destroyMatrix(&identityBig);
return 0;
}
#include "help.h"
/*
* greater testcase 4 benchmark calculation power
* n : 1 for sequential
* n : 2 for p_threads implementation
* n : 3 for opemMP
* n : 4 for ...
*/
void bench(matrix * m1, int n) {
matrix result;
run_timer();
switch (n) {
case 1:
printf("Benchmarking sequential program\n");
multiplication(&result,m1,m1);
break;
case 2:
printf("Benchmarking openMP\n");
openMPmultiplication(&result, m1, m1);
break;
case 3:
printf("Benchmarking pThreads\n");
pThreadsMultiplication(&result, m1, m1);
break;
case 4:
printf("Benchmarking MPI \n");
openMpiMultiplication(&result, m1, m1);
break;
}
stop_timer();
printf("-> %.3f seconds for benchmark\n", last_measured_time);
printf("\n");
destroyMatrix(&result);
}