Parallel Python

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
parallelpython
User
Beiträge: 3
Registriert: Mittwoch 3. Januar 2007, 06:28
Kontaktdaten:

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!
[b][url=http://www.parallelpython.com]Parallel Python[/url][/b]
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

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.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
sape
User
Beiträge: 1157
Registriert: Sonntag 3. September 2006, 12:52

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.
parallelpython
User
Beiträge: 3
Registriert: Mittwoch 3. Januar 2007, 06:28
Kontaktdaten:

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.
Zuletzt geändert von parallelpython am Donnerstag 4. Januar 2007, 02:12, insgesamt 2-mal geändert.
[b][url=http://www.parallelpython.com]Parallel Python[/url][/b]
parallelpython
User
Beiträge: 3
Registriert: Mittwoch 3. Januar 2007, 06:28
Kontaktdaten:

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)
[b][url=http://www.parallelpython.com]Parallel Python[/url][/b]
Antworten