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
27a3a6bc
Commit
27a3a6bc
authored
2 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
39d1a2ea
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#24737
passed
2 years ago
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Python/taichipi.py
+77
-0
77 additions, 0 deletions
Python/taichipi.py
README.md
+1
-0
1 addition, 0 deletions
README.md
with
78 additions
and
0 deletions
Python/taichipi.py
0 → 100644
+
77
−
0
View file @
27a3a6bc
#
# taichipi.py
# Neil Gershenfeld 2/22/23
# calculation of pi by Taichi
# pi = 3.14159265358979323846
#
import
time
import
taichi
as
ti
NPTS
=
10000000
def
calc_pi
(
NPTS
):
pi
=
0
for
i
in
range
(
1
,(
NPTS
+
1
)):
pi
+=
0.5
/
((
i
-
0.75
)
*
(
i
-
0.25
))
return
pi
pi
=
calc_pi
(
1000
)
# run first to compile
start_time
=
time
.
time
()
pi
=
calc_pi
(
NPTS
)
end_time
=
time
.
time
()
mflops
=
NPTS
*
5.0
/
(
1.0e6
*
(
end_time
-
start_time
))
print
(
"
\n
NPTS = %d, pi = %f
"
%
(
NPTS
,
pi
))
print
(
"
time = %f, estimated Python MFlops = %f
\n
"
%
(
end_time
-
start_time
,
mflops
))
ti
.
init
(
arch
=
ti
.
cpu
,
default_ip
=
ti
.
i64
,
default_fp
=
ti
.
f64
,
cpu_max_num_threads
=
1
)
NPTS
=
int
(
1000000000
)
@ti.kernel
def
calc_pi_CPU
(
NPTS
:
int
)
->
float
:
pi
=
float
(
0
)
for
i
in
range
(
1
,(
NPTS
+
1
)):
pi
+=
0.5
/
((
i
-
0.75
)
*
(
i
-
0.25
))
return
pi
pi
=
calc_pi_CPU
(
1000
)
# run first to compile
start_time
=
time
.
time
()
pi
=
calc_pi_CPU
(
NPTS
)
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 Taichi CPU serial MFlops = %f
\n
"
%
(
end_time
-
start_time
,
mflops
))
ti
.
init
(
arch
=
ti
.
cpu
,
default_ip
=
ti
.
i64
,
default_fp
=
ti
.
f64
)
@ti.kernel
def
calc_pi_CPU
(
NPTS
:
int
)
->
float
:
pi
=
float
(
0
)
for
i
in
range
(
1
,(
NPTS
+
1
)):
pi
+=
0.5
/
((
i
-
0.75
)
*
(
i
-
0.25
))
return
pi
pi
=
calc_pi_CPU
(
1000
)
# run first to compile
start_time
=
time
.
time
()
pi
=
calc_pi_CPU
(
NPTS
)
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 Taichi CPU parallel MFlops = %f
\n
"
%
(
end_time
-
start_time
,
mflops
))
ti
.
init
(
arch
=
ti
.
gpu
,
default_ip
=
ti
.
i64
,
default_fp
=
ti
.
f64
)
@ti.kernel
def
calc_pi_GPU
(
NPTS
:
int
)
->
float
:
pi
=
float
(
0
)
for
i
in
range
(
1
,(
NPTS
+
1
)):
pi
+=
0.5
/
((
i
-
0.75
)
*
(
i
-
0.25
))
return
pi
pi
=
calc_pi_GPU
(
1000
)
# run first to compile
start_time
=
time
.
time
()
pi
=
calc_pi_GPU
(
NPTS
)
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 Taichi GPU MFlops = %f
\n
"
%
(
end_time
-
start_time
,
mflops
))
This diff is collapsed.
Click to expand it.
README.md
+
1
−
0
View file @
27a3a6bc
...
...
@@ -13,6 +13,7 @@
|1,635|
[
cudapi.cu
](
CUDA/cudapi.cu
)
|C++, CUDA, 5120 cores|NVIDIA V100|March, 2020|
|1,595|prior|IBM Blue Gene/P|C, MPI, 4096 processes|prior|
|1,090|
[
numbapig.py
](
Python/numbapig.py
)
|Python, Numba, CUDA, 5120 cores|NVIDIA V100|March, 2020|
|1,062|
[
taichipi.py
](
Python/taichipi.py
)
|Python, Taichi, 5120 cores|NVIDIA V100|March, 2023|
|811|prior|Cray XT4|C, MPI, 2048 processes|prior|
|315|
[
numbapip.py
](
Python/numbapip.py
)
|Python, Numba, parallel, fastmath
<br>
96 cores|Intel 2x Xeon Platinum 8175M|February, 2020|
|272|
[
threadpi.c
](
C/threadpi.c
)
|C, 96 threads
<br>
gcc threadpi.c -o threadpi -O3 -ffast-math -pthread|Intel 2x Xeon Platinum 8175M|June, 2019|
...
...
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