IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

multiprocessing python cluster


Sujet :

Python

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Avril 2014
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 35
    Points : 32
    Points
    32
    Par défaut multiprocessing python cluster
    Bonjour,

    je souhaite lancer un programme avec plusieurs processeurs. D'un part sur mon laptop (qui a 4 coeurs) puis sur un ordinateur d'un cluster (qui a 64 coeurs). Pour cela, apres avoir regarder sur internet, j'utilise la bibliotheque multiprocessing car le threading semble deconseille sous python


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    from multiprocessing import Process,Queue
     
    threads = []
    q = Queue()
    nbrThread=4
    for thread in range(0,nbrThread):
                print("Launching thread...."+str(thread))
     
                t=Process(target=function_test, args=(currentMat,q))
                t.start()
                threads.append(t)
    print("Waiting for treads....")
     
    for thread in range(0,nbrThread):
                threads[thread].join()
    while not q.empty():
                temp=q.get()
                coeff_output[temp[0]]=temp[1]
    Lorsque je le lance sur mon pc, mon code tourne bien et je vois que cela tourne correctement sur les 4 processeurs.

    Alors que lorsque je le lance sur le cluster, il a bien l'air de passer dans les threads mais sans les lancer, et il ne print pas "Waiting for threads". Pourtant les 64 processeurs ont bien l'air de "tourner" (lorsque je lance la connabd "top" sous linux, chaque processeur est occupé )


    Voila l'output que j'ai:
    Launhcing thread....0
    Launhcing thread....1
    Launhcing thread....2
    Launhcing thread....3
    Launhcing thread....4
    Launhcing thread....5
    Launhcing thread....6
    Launhcing thread....7
    Launhcing thread....8
    Launhcing thread....9
    Launhcing thread....10
    Launhcing thread....11
    Launhcing thread....12
    Launhcing thread....13
    Launhcing thread....14
    Launhcing thread....15
    Launhcing thread....16
    Launhcing thread....17
    Launhcing thread....18
    Launhcing thread....19
    Launhcing thread....20
    Launhcing thread....21
    Launhcing thread....22
    Launhcing thread....23
    Launhcing thread....24
    Launhcing thread....25
    Launhcing thread....26
    Launhcing thread....27
    Launhcing thread....28
    Launhcing thread....29
    Launhcing thread....30
    Launhcing thread....31
    Launhcing thread....32
    Launhcing thread....33
    Launhcing thread....34
    Launhcing thread....35
    Launhcing thread....36
    Launhcing thread....37
    Launhcing thread....38
    Launhcing thread....39
    Launhcing thread....40
    Launhcing thread....41
    Launhcing thread....42
    Launhcing thread....43
    Launhcing thread....44
    Launhcing thread....45
    Launhcing thread....46
    Launhcing thread....47
    Launhcing thread....48
    Launhcing thread....49
    Launhcing thread....50
    Launhcing thread....51
    Launhcing thread....52
    Launhcing thread....53
    Launhcing thread....54
    Launhcing thread....55
    Launhcing thread....56
    Launhcing thread....57
    Launhcing thread....58
    Launhcing thread....59
    Launhcing thread....60
    Launhcing thread....61
    Launhcing thread....62
    Launhcing thread....63

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Japon

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 4
    Points : 8
    Points
    8
    Par défaut
    Bonjour,

    J'ai eu le même souci récemment, sur mon ordinateur tout fonctionnait normalement mais en lançant sur un cluster ca tournait dans le vide (pendant plusieurs jours), en ne sortant qu'une partie des informations.

    J'ai régler mon problème en utilisant une autre classe de multithreading: Pool (qui se chargera de lancer tes thread correctement quel que soit ton architecture, un multicore ou un cluster). En utilisant Pool ton code deviendra:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    from multiprocessing import Pool
     
    nbrThread=4 
     
    p = Pool(processes=nbrThread)
     
    results = p.map(function_test,(currentMat,q))
    Tu auras certainement a adapter un peu plus a ton code et ta problématique mais l'esprit est la (et c'est bien plus concis que d'utiliser les thread a la main).

    Par contre Pool.map s'utilise comme map de la bibliothèque standard. Il faut que tu fasses le même nombre de "currentMat" que de "q", ou bien tu utilise une autre fonction comme wrapper.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Avril 2014
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 35
    Points : 32
    Points
    32
    Par défaut
    merci pour ta réponse, j'essaye d'utiliser pool.map mais j'ai les problemes suivants:

    - j'ai plusieurs variables en input qui ont differences formes (en grois des numpy array qui sont soit 2D soit 3D, avec differentes tailles et qui sont differends pour chaque thread....)
    En grios avant j'utilisais:

    t=Process(target=function_test, args=(npArray1,npArray2,npArray3,npArray4,npArray5,q))

    mais maintenant ce n'est plus possible car visiblement map.pool ne prends qu'un seul parametre.

    En regardant sur internet les solutions a ce probleme je vois les possibilités suivantes mais sans vraiment savoir si c'est correct ou pas :

    - créer un struct contenant tous les arguments similaire de ce qui se fait sous c++ et le passer en argument ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    class MyStruct():
        def __init__(self, field1, field2, field3):
            self.array1 = field1
            self.array2 = field2
            self.array3 = field3
            self.array4 = field4
            self.array5 = field5
    - utiliser la function partial mais j'ai l'impression que cela force a avoir un argument constant sur les tous les threads alors que ce n'est pas mon cas ?


    Vous avez un conseil / un autre idéé ?

  4. #4
    Futur Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Japon

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Mai 2015
    Messages : 4
    Points : 8
    Points
    8
    Par défaut
    Personnellement j'utilise une liste pour passer mes arguments comme ca:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    l1 = [1,2,3]
    l2=[4,5,6]
    l3 = 99
     
    arguments = [(a,b,l3) for a , b in zip(l1, l2)]
     
    results = pool.map( my_func, arguments )
    ca utilisera chaque tuple de ta liste comme argument. Ensuite ma fonction "my_func" est juste un wrapper qui fait:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    def my_func(args):
        return real_func(*args)
    avec "real_func" la véritable fonction que tu compte appeler.

    Il y a peut être un moyen plus élégant de faire avec des décorateurs peut être, mais cette méthode fonctionne avec moi.

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Avril 2014
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2014
    Messages : 35
    Points : 32
    Points
    32
    Par défaut
    c'est bon, merci pour ton aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Python multiprocessing, partager plusieurs variables
    Par AJMont dans le forum Général Python
    Réponses: 1
    Dernier message: 19/07/2015, 15h44
  2. multiprocessing avec python
    Par khadi8 dans le forum Général Python
    Réponses: 1
    Dernier message: 17/06/2014, 20h38
  3. multiprocessing python 2.6
    Par asmaeH dans le forum Général Python
    Réponses: 5
    Dernier message: 24/07/2012, 16h52
  4. CORBA & PYTHON
    Par stan91stan dans le forum CORBA
    Réponses: 5
    Dernier message: 10/06/2004, 12h32
  5. Cluster sous Débian 3.0 (Woody)
    Par regular dans le forum Développement
    Réponses: 3
    Dernier message: 06/08/2003, 11h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo