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
7f63ccdf
Commit
7f63ccdf
authored
5 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
e9304940
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#4927
passed
5 years ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python/numbapip.py
+27
-0
27 additions, 0 deletions
Python/numbapip.py
with
27 additions
and
0 deletions
Python/numbapip.py
0 → 100755
+
27
−
0
View file @
7f63ccdf
#
# numbapip.py
# Neil Gershenfeld 2/6/20
# calculation of pi by a Numba parallel sum
# pi = 3.14159265358979323846
#
import
time
from
numba
import
njit
,
prange
NPTS
=
1000000000
@njit
(
parallel
=
True
)
def
calc
():
a
=
0.5
b
=
0.75
c
=
0.25
pi
=
0
for
i
in
prange
(
1
,(
NPTS
+
1
)):
pi
+=
a
/
((
i
-
b
)
*
(
i
-
c
))
return
pi
pi
=
calc
()
# first call to compile the function
start_time
=
time
.
time
()
pi
=
calc
()
# second call uses the cached compilation
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
))
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