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
73cc9da0
Commit
73cc9da0
authored
5 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
e95d406f
No related branches found
No related tags found
No related merge requests found
Pipeline
#4918
passed
5 years ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python/mpipi2.py
+48
-0
48 additions, 0 deletions
Python/mpipi2.py
with
48 additions
and
0 deletions
Python/mpipi.py
→
Python/mpipi
2
.py
+
48
−
0
View file @
73cc9da0
#
# mpipi.py
# mpipi
2
.py
# Neil Gershenfeld 2/6/20
# calculation of pi by an MPI Numba sum
# pi = 3.14159265358979323846
...
...
@@ -9,6 +9,13 @@ import time
from
numba
import
jit
from
mpi4py
import
MPI
NPTS
=
1000000000
NLOOP
=
10
comm
=
MPI
.
COMM_WORLD
rank
=
comm
.
Get_rank
()
nproc
=
comm
.
Get_size
()
@jit
(
nopython
=
True
)
def
calc
(
istart
,
iend
):
sum
=
0.0
...
...
@@ -16,22 +23,26 @@ def calc(istart,iend):
sum
+=
0.5
/
((
i
-
0.75
)
*
(
i
-
0.25
))
return
sum
NPTS
=
100000000000
comm
=
MPI
.
COMM_WORLD
rank
=
comm
.
Get_rank
()
nproc
=
comm
.
Get_size
()
if
(
rank
==
0
):
start_time
=
time
.
time
()
istart
=
int
(
1
+
NPTS
*
((
rank
+
0
)
/
nproc
))
iend
=
int
(
NPTS
*
((
rank
+
1
)
/
nproc
))
pi
=
calc
(
istart
,
iend
)
comm
.
reduce
(
pi
,
op
=
MPI
.
SUM
,
root
=
0
)
end_time
=
time
.
time
()
mflops
=
NPTS
*
5.0
/
(
1.0e6
*
(
end_time
-
start_time
))
print
(
"
NPTS = %d, pi = %f
"
%
(
NPTS
,
pi
))
print
(
"
time = %f, estimated MFlops = %f
"
%
(
end_time
-
start_time
,
mflops
))
istart
=
1
+
rank
*
NPTS
;
iend
=
(
rank
+
1
)
*
NPTS
;
max
=
0
for
j
in
range
(
NLOOP
):
comm
.
Barrier
()
start_time
=
time
.
time
()
sum
=
0.0
;
sum
=
calc
(
istart
,
iend
)
pi
=
comm
.
reduce
(
sum
,
op
=
MPI
.
SUM
,
root
=
0
)
end_time
=
time
.
time
()
mflops
=
nproc
*
NPTS
*
5.0
/
(
1.0e6
*
(
end_time
-
start_time
))
print
(
"
processes = %d, NPTS = %d, pi = %f
"
%
(
nproc
,
NPTS
,
pi
))
if
(
mflops
>
max
):
max
=
mflops
print
(
"
time = %f, estimated MFlops = %f, max = %f
"
%
(
end_time
-
start_time
,
mflops
,
max
))
else
:
istart
=
int
(
1
+
NPTS
*
((
rank
+
0
)
/
nproc
))
iend
=
int
(
NPTS
*
((
rank
+
1
)
/
nproc
))
pi
=
calc
(
istart
,
iend
)
comm
.
reduce
(
pi
,
op
=
MPI
.
SUM
,
root
=
0
)
istart
=
1
+
rank
*
NPTS
iend
=
(
rank
+
1
)
*
NPTS
for
j
in
range
(
NLOOP
):
comm
.
Barrier
()
sum
=
calc
(
istart
,
iend
)
comm
.
reduce
(
sum
,
op
=
MPI
.
SUM
,
root
=
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