Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
GitLab upgrade completed. Current version is 17.11.3.
Show more breadcrumbs
lecture-HPC
2021
Commits
1ea97bac
Commit
1ea97bac
authored
3 years ago
by
thierry
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
6ccb7c97
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openmp/8-dotproduct-v0-time.cpp
+53
-0
53 additions, 0 deletions
openmp/8-dotproduct-v0-time.cpp
with
53 additions
and
0 deletions
openmp/8-dotproduct-v0-time.cpp
0 → 100644
+
53
−
0
View file @
1ea97bac
#include
<stdio.h>
#include
<stdlib.h>
#include
<omp.h>
#define MAX_THREADS 128
double
T
=
0.0
;
float
dotproduct
(
float
*
x
,
float
*
y
,
int
n
)
{
int
i
;
int
nthreads
=
0
;
float
d
[
MAX_THREADS
];
float
r
;
double
t0
=
omp_get_wtime
();
#pragma omp parallel shared(x,y,d, nthreads), private(i), firstprivate(n)
{
#pragma omp master
nthreads
=
omp_get_num_threads
();
int
tid
=
omp_get_thread_num
();
d
[
tid
]
=
0
;
#pragma omp for schedule(static)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
d
[
tid
]
+=
x
[
i
]
*
y
[
i
];
}
}
for
(
i
=
0
;
i
<
nthreads
;
++
i
)
r
+=
d
[
i
];
double
t1
=
omp_get_wtime
();
printf
(
"Time: %f
\n
"
,
t1
-
t0
);
T
+=
t1
-
t0
;
return
r
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
N
=
atoi
(
argv
[
1
]);
float
*
x
=
new
float
[
N
];
float
*
y
=
new
float
[
N
];
#pragma omp parallel for schedule(static)
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
x
[
i
]
=
1.0
/
double
(
i
);
y
[
i
]
=
N
/
double
(
i
);
}
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
float
d
=
dotproduct
(
x
,
y
,
N
);
}
printf
(
"Avrg: %f
\n
"
,
T
/
10
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment