0

I'm struggling to use the mpi4py gather method. I want to keep calling gather on the root node until the end of the program, which is controlled by fin(), which returns a boolean, while the other nodes send, via gather, their data to the root node. The thing is, the code doesn't even manage to display text on the screen, even though a print is in the first line of code.

Here is a minimal working code :

from mpi4py import MPI
from random import random
from math import log2

comm = MPI.COMM_WORLD

data = ""

rank = comm.Get_rank()

if rank != 0:
    while True:
        data = "s"
        datas = comm.gather(data, root = 0)

if rank == 0:      
    while True:
        datas = comm.gather(data, root = 0)
        print(datas, rank)

This, of course, runs forever, but still prints out data on the screen. This, however, doesn't print anything :

from mpi4py import MPI
from random import random
from math import log2

comm = MPI.COMM_WORLD

data = ""
datas = []
rank = comm.Get_rank()

if rank != 0:
    data = "s"
    datas = comm.gather(data, root = 0)

if rank == 0:   
    while datas != []:
        datas = comm.gather(data, root = 0)
        print(datas, rank)

This is, I believe, the issue about the following code, which is supposed to compute a dominating set of a graph using mpi4py :

https://drive.google.com/open?id=0B6O6mNqn_4AVWVlOeHNHWUZ3TmM

Thanks for any potential help you might provide !

Shibli
  • 5,879
  • 13
  • 62
  • 126
  • The problem is at `while datas != []`. If you want to know whether or not a list is empty answer is [here](https://stackoverflow.com/a/53522/1128551). – Shibli May 31 '17 at 18:16
  • 1
    Oh yeah, you're right, that seems to solve some issues ! I'll update if needed, thank you ! – BREMONT Julien May 31 '17 at 18:26
  • Possible duplicate of [Best way to check if a list is empty](https://stackoverflow.com/questions/53513/best-way-to-check-if-a-list-is-empty) – Zulan May 31 '17 at 19:06

0 Answers0