-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmatmul.cc
More file actions
executable file
·55 lines (46 loc) · 1.38 KB
/
Copy pathmatmul.cc
File metadata and controls
executable file
·55 lines (46 loc) · 1.38 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <malloc.h>
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include <omp.h>
double my_timer() {
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return ((double)tv.tv_sec + (double)0.000001 * (double)tv.tv_usec);
}
int main ( int argc, char * argv[] ) {
omp_set_dynamic(0);
int number_of_cores = atoi(argv[1]);
omp_set_num_threads(number_of_cores);
printf("Number of cores = %d\n", number_of_cores);
uint64_t i, j, k;
double ** A = (double **) malloc(1500 * sizeof(double *));
double ** B = (double **) malloc(1500 * sizeof(double *));
double ** C = (double **) malloc(1500 * sizeof(double *));
#pragma omp parallel for
for (i = 0; i < 1500; i ++) {
A[i] = (double *) malloc(1500 * sizeof(double));
B[i] = (double *) malloc(1500 * sizeof(double));
C[i] = (double *) malloc(1500 * sizeof(double));
}
#pragma omp parallel for
for (i = 0; i < 1500; i ++) {
for (j = 0; j < 1500; j ++) {
A[i][j] = 1.0;
B[i][j] = 1.0;
C[i][j] = 0.0;
} }
printf("C: Matrix multiply 2 1500 x 1500 arrays (1 iteration)\n");
double time1 = my_timer();
#pragma omp parallel for
for (i = 0; i < 1500; i ++) {
for (j = 0; j < 1500; j ++) {
for (k = 0; k < 1500; k ++) {
C[i][j] += A[i][k] * B[k][j];
} } }
printf("%lf\n", my_timer() - time1);
}