-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmult_omp_timing.c
42 lines (38 loc) · 1.14 KB
/
mmult_omp_timing.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
/**
* This file compares the time to multiply matrices
* both unoptimized and with OMP.
*/
#include <stdio.h>
#include <time.h>
#include <sys/times.h>
#include <stdlib.h>
#include "mat.h"
int main(int argc, char* argv[]) {
struct timespec start;
struct timespec end;
struct timespec res;
double *a, *b, *c1, *c2;
int n;
double times[2];
if (argc > 1) {
n = atoi(argv[1]);
a = gen_matrix(n, n);
b = gen_matrix(n, n);
c1 = malloc(sizeof(double) * n * n);
c2 = malloc(sizeof(double) * n * n);
clock_gettime(CLOCK_REALTIME, &start);
mmult(c1, a, n, n, b, n, n);
clock_gettime(CLOCK_REALTIME, &end);
times[0] = deltaTime(&start, &end);
printf("%d %f", n, times[0]);
clock_gettime(CLOCK_REALTIME, &start);
mmult_omp(c2, a, n, n, b, n, n);
clock_gettime(CLOCK_REALTIME, &end);
times[1] = deltaTime(&start, &end);
printf(" %f", times[1]);
printf("\n");
compare_matrices(c1, c2, n, n);
} else {
fprintf(stderr, "Usage %s <n>\n", argv[0]);
}
}