Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another question, help me please. #88

Open
sc1101 opened this issue Jan 20, 2020 · 1 comment
Open

Another question, help me please. #88

sc1101 opened this issue Jan 20, 2020 · 1 comment

Comments

@sc1101
Copy link

sc1101 commented Jan 20, 2020

Hello!
I run the example in the document, the code is as the following:
"""test.py""" from math import hypot from random import random from scoop import futures import time def test(tries): return sum(hypot(random(), random()) < 1 for _ in range(tries)) def calcPi(nbFutures, tries): expr = futures.map(test, [tries] * nbFutures) return 4. * sum(expr) / float(nbFutures * tries) if __name__ == "__main__": bt = time.time() print("pi = {}".format(calcPi(3000, 5000))) print('time:', time.time() - bt)

I run this code in the windows cmd with the command "python -m scoop test.py",
however, it cost 33 seconds. Then I used "map" instead of "futures.map", it just cost 4 seconds.

What should I do to let SCOOP be able to speed up my code?

Thanks.

@ljluestc
Copy link

from math import hypot
from random import random
from scoop import futures
import time

def test(tries):
return sum(hypot(random(), random()) < 1 for _ in range(tries))

def calcPi(nbFutures, tries):
expr = futures.map(test, [tries] * nbFutures)
return 4. * sum(expr) / float(nbFutures * tries)

if name == "main":
nbFutures = 3000
tries = 5000

bt = time.time()

# Divide the work among fewer processes to minimize overhead
chunk_size = 10
expr = futures.map(test, [chunk_size] * (nbFutures * tries // chunk_size))

print("pi = {}".format(4. * sum(expr) / float(nbFutures * tries)))
print('time:', time.time() - bt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants