Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenMP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xinzhe Wu
OpenMP
Commits
4ddbc17d
Commit
4ddbc17d
authored
4 years ago
by
Xinzhe Wu
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
72811ec8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
3_affinity_query/3_affinity_query.cpp
+85
-12
85 additions, 12 deletions
3_affinity_query/3_affinity_query.cpp
with
85 additions
and
12 deletions
3_affinity_query/3_affinity_query.cpp
+
85
−
12
View file @
4ddbc17d
...
...
@@ -35,6 +35,10 @@ void numa_in_operations(int socket_num){
int
main
()
{
/*
* output: Size, Sum, serial time, NUMA domain time, node time, NUMA-aware time
*
*/
int
n_sockets
,
socket_num
;
int
n_procs
;
...
...
@@ -44,10 +48,11 @@ int main()
n_sockets
=
omp_get_num_places
();
printf
(
"number of sockets = %d
\n
"
,
n_sockets
);
//
printf("number of sockets = %d \n", n_sockets);
int
size
=
100000000
0
;
int
size
=
100000000
;
/*Serial Sum*/
double
*
a
=
new
double
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++
){
...
...
@@ -57,37 +62,105 @@ int main()
double
sum
=
0
;
auto
t1
=
high_resolution_clock
::
now
();
for
(
int
i
=
0
;
i
<
size
;
i
++
){
sum
+=
a
[
i
];
}
auto
t2
=
high_resolution_clock
::
now
();
auto
t
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
printf
(
"Sum of array is : %f in %f seconds
\n
"
,
sum
,
t
.
count
());
printf
(
"%d,%f,%f,"
,
size
,
sum
,
t
.
count
());
delete
[]
a
;
/*Numa domain Sum*/
double
*
b
=
new
double
[
size
];
double
total
=
0
;
auto
start
=
high_resolution_clock
::
now
();
for
(
int
i
=
0
;
i
<
size
;
i
++
){
b
[
i
]
=
i
+
1
;
}
sum
=
0
;
#pragma omp parallel num_threads(n_sockets) shared(total) private(socket_num, n_procs) proc_bind(spread)
t1
=
high_resolution_clock
::
now
();
#pragma omp parallel num_threads(n_sockets) shared(sum) private(socket_num, n_procs) proc_bind(spread)
{
socket_num
=
omp_get_place_num
();
n_procs
=
omp_get_place_num_procs
(
socket_num
);
if
(
socket_num
==
0
){
#pragma omp parallel for reduction(+:
total
) num_threads(n_procs)
#pragma omp parallel for reduction(+:
sum
) num_threads(n_procs)
for
(
int
i
=
0
;
i
<
size
;
i
++
){
total
+=
a
[
i
];
sum
+=
b
[
i
];
}
}
else
{
/*
printf("The other sockets do nothing\n");
*/
}
}
auto
end
=
high_resolution_clock
::
now
();
t2
=
high_resolution_clock
::
now
();
t
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
printf
(
"%f,"
,
t
.
count
());
delete
[]
b
;
/*Node*/
double
*
c
=
new
double
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++
){
c
[
i
]
=
i
+
1
;
}
sum
=
0
;
t1
=
high_resolution_clock
::
now
();
#pragma omp parallel for reduction(+:sum)
for
(
int
i
=
0
;
i
<
size
;
i
++
){
sum
+=
c
[
i
];
}
t2
=
high_resolution_clock
::
now
();
t
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
printf
(
"%f,"
,
t
.
count
());
// printf("Node: Sum of array is : %f in %f seconds\n", sum, t.count());
delete
[]
c
;
/*Node with NUMA-Aware*/
double
*
d
=
new
double
[
size
];
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
size
;
i
++
){
d
[
i
]
=
i
+
1
;
}
sum
=
0
;
t1
=
high_resolution_clock
::
now
();
#pragma omp parallel for reduction(+:sum)
for
(
int
i
=
0
;
i
<
size
;
i
++
){
sum
+=
d
[
i
];
}
t2
=
high_resolution_clock
::
now
();
t
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
auto
time_span
=
duration_cast
<
duration
<
double
>>
(
end
-
start
);
printf
(
"%f
\n
"
,
t
.
count
()
);
printf
(
"Total of array is : %f in %f seconds
\n
"
,
total
,
time_span
.
count
())
;
delete
[]
d
;
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