Add files via upload
This commit is contained in:
parent
ae205f8738
commit
59c00f2f76
@ -10,14 +10,16 @@ from decimal import Decimal
|
|||||||
from decimal import getcontext
|
from decimal import getcontext
|
||||||
import time
|
import time
|
||||||
from multiprocessing.dummy import Pool as Pool
|
from multiprocessing.dummy import Pool as Pool
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def pi(start):
|
def pi(start):
|
||||||
getcontext().prec=count-start
|
getcontext().prec = count - start
|
||||||
for k in range (start,int(start+one_count)):
|
for k in range(start, int(start + one_count)):
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
list_all[k]=(1/Decimal(16)**k * (Decimal(4)/(8*k+1) - Decimal(2)/(8*k+4) - Decimal(1)/(8*k+5) - Decimal(1)/(8*k+6)))
|
list_all[k] = (1/Decimal(16)**k * (Decimal(4)/(8*k+1) - Decimal(2)/(8*k+4) - Decimal(1)/(8*k+5) - Decimal(1)/(8*k+6)))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global count
|
global count
|
||||||
@ -26,7 +28,7 @@ def main():
|
|||||||
global tasks
|
global tasks
|
||||||
global one_count
|
global one_count
|
||||||
parser = argparse.ArgumentParser(description='The script computes the number pi.')
|
parser = argparse.ArgumentParser(description='The script computes the number pi.')
|
||||||
parser.add_argument('-t', '--threads', help="Number of threads default 4", required=False,type=int, default=4)
|
parser.add_argument('-t', '--threads', help="Number of threads default 4", required=False, type=int, default=4)
|
||||||
parser.add_argument('-c', '--count', help="Number of numbers after the point default 10000", required=False,type=int, default=10000)
|
parser.add_argument('-c', '--count', help="Number of numbers after the point default 10000", required=False,type=int, default=10000)
|
||||||
parser.add_argument('-f', '--filename', help="File to save result", required=False)
|
parser.add_argument('-f', '--filename', help="File to save result", required=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -44,12 +46,11 @@ def main():
|
|||||||
pbar = tqdm(total = count)
|
pbar = tqdm(total = count)
|
||||||
one_count=int(count/tasks)
|
one_count=int(count/tasks)
|
||||||
start_table = [int((one_count * i)) for i in range(tasks)]
|
start_table = [int((one_count * i)) for i in range(tasks)]
|
||||||
|
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
with Pool(processes=threads) as pool:
|
with Pool(processes=threads) as pool:
|
||||||
results = pool.starmap(
|
results = pool.starmap(
|
||||||
pi,
|
pi,
|
||||||
iterable=zip(start_table),
|
iterable=zip(start_table),
|
||||||
chunksize=100000 // threads
|
chunksize=100000 // threads
|
||||||
)
|
)
|
||||||
@ -68,12 +69,4 @@ def main():
|
|||||||
f.write(str(Decimal(result)))
|
f.write(str(Decimal(result)))
|
||||||
f.close()
|
f.close()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user