Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
HPC
hello-world
Commits
6a6c107a
Commit
6a6c107a
authored
Sep 23, 2017
by
Alejandro E. Rendon
Browse files
Time in Omp operation
parent
867ffdff
Changes
1
Hide whitespace changes
Inline
Side-by-side
vec_add.cpp
View file @
6a6c107a
...
...
@@ -22,12 +22,19 @@ void add(int *a, int *b, int *c, int n) {
c
[
i
]
=
a
[
i
]
+
b
[
i
];
}
void
addOmp
(
int
*
a
,
int
*
b
,
int
*
c
,
int
n
)
{
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
n
;
i
++
)
c
[
i
]
=
a
[
i
]
+
b
[
i
];
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
if
(
argc
<
2
)
cout
<<
"I need more inputs"
<<
endl
;
else
{
int
vec_size
=
stoi
(
argv
[
1
]);
int
*
a
,
*
b
,
*
c
;
double
begin
,
end
;
a
=
(
int
*
)
malloc
(
vec_size
*
sizeof
(
int
));
b
=
(
int
*
)
malloc
(
vec_size
*
sizeof
(
int
));
...
...
@@ -39,10 +46,15 @@ int main(int argc, char const *argv[]) {
//print("a = ", a, vec_size);
//print("b = ", b, vec_size);
double
begin
=
omp_get_wtime
();
begin
=
omp_get_wtime
();
add
(
a
,
b
,
c
,
vec_size
);
double
end
=
omp_get_wtime
();
cout
<<
end
-
begin
<<
endl
;
end
=
omp_get_wtime
();
cout
<<
"Sequential -> "
<<
end
-
begin
<<
endl
;
begin
=
omp_get_wtime
();
addOmp
(
a
,
b
,
c
,
vec_size
);
end
=
omp_get_wtime
();
cout
<<
"OpenMP -> "
<<
end
-
begin
<<
endl
;
//print("c = ", c, vec_size);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment