FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmarks/matrix_multiplication/omp.cpp at master · feiyunwill/cpp-taskflow · GitHub
feiyunwill
/
cpp-taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
benchmarks
/
matrix_multiplication
/
omp.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (77 loc) · 2.1 KB
Breadcrumbs
cpp-taskflow
/
benchmarks
/
matrix_multiplication
/
omp.cpp
Copy path
File metadata and controls
90 lines (77 loc) · 2.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
matrix_multiplication.hpp
"
#
include
<
omp.h
>
//
matrix_multiplication_omp
//
reference: https://computing.llnl.gov/tutorials/openMP/samples/C/omp_mm.c
void
matrix_multiplication_omp
(
unsigned
nthreads) {
omp_set_num_threads
(nthreads);
//
int i, j, k;
//
#pragma omp parallel for private(i, j)
//
for(i=0; i<N; ++i) {
//
for(j=0; j<N; j++) {
//
a[i][j] = i + j;
//
}
//
}
//
#pragma omp parallel for private(i, j)
//
for(i=0; i<N; ++i) {
//
for(j=0; j<N; j++) {
//
b[i][j] = i * j;
//
}
//
}
//
#pragma omp parallel for private(i, j)
//
for(i=0; i<N; ++i) {
//
for(j=0; j<N; j++) {
//
c[i][j] = 0;
//
}
//
}
//
#pragma omp parallel for private(i, j, k)
//
for(i=0; i<N; ++i) {
//
for(j=0; j<N; j++) {
//
for (k=0; k<N; k++) {
//
c[i][j] += a[i][k] * b[k][j];
//
}
//
}
//
}
#
pragma
omp parallel
{
#
pragma
omp single
{
//
Task 1: Initialize a[][]
#
pragma
omp task depend(out: a)
for
(
int
i =
0
; i < N; ++i) {
for
(
int
j =
0
; j < N; ++j) {
a[i][j] = i + j;
}
}
//
Task 2: Initialize b[][]
#
pragma
omp task depend(out: b)
for
(
int
i =
0
; i < N; ++i) {
for
(
int
j =
0
; j < N; ++j) {
b[i][j] = i * j;
}
}
//
Task 3: Initialize c[][]
#
pragma
omp task depend(out: c)
for
(
int
i =
0
; i < N; ++i) {
for
(
int
j =
0
; j < N; ++j) {
c[i][j] =
0
;
}
}
//
Task 4: Matrix multiplication (depends on a, b, and c)
#
pragma
omp task depend(in: a, b, c)
#
pragma
omp parallel for
for
(
int
i =
0
; i < N; ++i) {
for
(
int
j =
0
; j < N; ++j) {
for
(
int
k =
0
; k < N; ++k) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
//
single
}
//
parallel
}
std::chrono::microseconds
measure_time_omp
(
unsigned
num_threads) {
auto
beg =
std::chrono::high_resolution_clock::now
();
matrix_multiplication_omp
(num_threads);
auto
end =
std::chrono::high_resolution_clock::now
();
return
std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}
Back
|
FazBrowse Home
|
New Git URL