Seite 1 von 1
Parallel Python
Verfasst: Mittwoch 3. Januar 2007, 06:29
von parallelpython
Does anybody have any experience with parallel python?
Recently I've made
Parallel Python for SMP
I would appreciate any comments/suggestions regarding it.
Thank you!
Verfasst: Mittwoch 3. Januar 2007, 12:48
von Leonidas
Hi parallelpython, welcome in the forum!
Is it your project? There are
examples but I don't see any documentation how it works under the hood.
Anyway, testing for type in the isPrime example is not considered good style.
Verfasst: Mittwoch 3. Januar 2007, 14:03
von sape
Leonidas hat geschrieben:[...]
Anyway, testing for type in the isPrime example is not considered good style.
Yes ^^
isinstance(n, int):
Code: Alles auswählen
def isPrime(n):
"""Returns True if n is prime and False otherwise"""
if not isinstance(n, int) or n < 2:
return False
elif n == 2:
return True
max = int(math.ceil(math.sqrt(n)))
i = 2
while i <= max:
if n % i == 0:
return False
i += 1
return True
Much better:
Code: Alles auswählen
def isPrime(n):
if not isinstance(n, int):
raise TypeError("n is not from data type int or long")
if n < 2:
return False
# etc.
BTW: The name of the function is not conform with the
PEP8 Style Guide. ``is_prime`` ist better as ``isPrime``
lg
P.S.: Sorry for my very bad english.
Verfasst: Donnerstag 4. Januar 2007, 01:58
von parallelpython
Leonidas hat geschrieben:Hi parallelpython, welcome in the forum!
Is it your project?
Hi Leonidas,
Yes, it is my project.
Leonidas hat geschrieben:
There are
examples but I don't see any documentation how it works under the hood.
In short, it creates worker processes which may run on different cpus/cores.
These processes execute jobs in parallel.
Verfasst: Donnerstag 4. Januar 2007, 02:09
von parallelpython
sape hat geschrieben:
Much better:
Code: Alles auswählen
def isPrime(n):
if not isinstance(n, int):
raise TypeError("n is not from data type int or long")
BTW: The name of the function is not conform with the
PEP8 Style Guide. ``is_prime`` ist better as ``isPrime``
Thank you for the feedback!
I've changed the
examples section.
I guess
isprime will be even better here (analogous to
isinstance)