Skip to content
Snippets Groups Projects
Commit 27a3a6bc authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 39d1a2ea
Branches
No related tags found
No related merge requests found
Pipeline #24737 passed
#
# 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("\nNPTS = %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))
......@@ -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|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment