Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pi
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
pi
Commits
4aff3c3b
Commit
4aff3c3b
authored
5 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
50ed58e8
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#4427
passed
5 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hybrid/mpimppi.c
+60
-0
60 additions, 0 deletions
hybrid/mpimppi.c
with
60 additions
and
0 deletions
hybrid/mpimppi.c
0 → 100644
+
60
−
0
View file @
4aff3c3b
/*
* mpimppi.c
* Neil Gershenfeld 10/8/19
* MPI+OpenMP pi calculation benchmark
* pi = 3.14159265358979323846
*/
#include
<stdio.h>
#include
<mpi.h>
#include
<omp.h>
#include
<sys/time.h>
#include
<stdint.h>
#define NPTS 10000000000
#define NLOOP 10
void
main
(
int
argc
,
char
**
argv
)
{
uint32_t
rank
,
nproc
;
uint64_t
i
,
j
,
istart
,
iend
,
start_time
,
end_time
;
struct
timeval
start
,
end
;
double
sum
,
pi
,
mflops
,
max
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
nproc
);
max
=
0
;
if
(
rank
==
0
)
{
istart
=
1
+
rank
*
NPTS
;
iend
=
(
rank
+
1
)
*
NPTS
;
for
(
j
=
0
;
j
<
NLOOP
;
++
j
)
{
MPI_Barrier
(
MPI_COMM_WORLD
);
gettimeofday
(
&
start
,
NULL
);
sum
=
0
.
0
;
#pragma omp parallel for reduction(+:sum)
for
(
i
=
istart
;
i
<=
iend
;
++
i
)
sum
+=
0
.
5
/
((
i
-
0
.
75
)
*
(
i
-
0
.
25
));
MPI_Reduce
(
&
sum
,
&
pi
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
gettimeofday
(
&
end
,
NULL
);
start_time
=
start
.
tv_sec
*
1e6
+
start
.
tv_usec
;
end_time
=
end
.
tv_sec
*
1e6
+
end
.
tv_usec
;
mflops
=
nproc
*
NPTS
*
(
5
.
0
/
(
end_time
-
start_time
));
printf
(
"processes = %d, threads = %d, NPTS = %ld, pi = %f
\n
"
,
nproc
,
omp_get_max_threads
(),
NPTS
,
pi
);
if
(
mflops
>
max
)
max
=
mflops
;
printf
(
"time = %f, estimated MFlops = %f, max = %f
\n
"
,(
end_time
-
start_time
)
/
1.0e6
,
mflops
,
max
);
}
}
else
{
istart
=
1
+
rank
*
NPTS
;
iend
=
(
rank
+
1
)
*
NPTS
;
for
(
j
=
0
;
j
<
NLOOP
;
++
j
)
{
MPI_Barrier
(
MPI_COMM_WORLD
);
sum
=
0
.
0
;
#pragma omp parallel for reduction(+:sum)
for
(
i
=
istart
;
i
<=
iend
;
++
i
)
sum
+=
0
.
5
/
((
i
-
0
.
75
)
*
(
i
-
0
.
25
));
MPI_Reduce
(
&
sum
,
&
pi
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
}
}
MPI_Finalize
();
}
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