Why am I encountering an error with comm.Bcast() function in mpi4py when broadcasting a numpy array?

18 views Asked by At

I am currently implementing parallel Python computation using the mpi4py package. In my code, there is a segment that uses comm.Bcast() to broadcast a list from rank0 to other ranks. However, I encountered an error. I have simplified the problematic code segment as follows:

if rank == 0:
    char = [0.1, 0.1, 0.1]
    char = np.array(char)
else:
    char = np.zeros(3, dtype=np.float64)
comm.Bcast(char, root=0)

After executing this code, half of the ranks successfully receive the broadcasted information (I am using 48 ranks, and upon printing 'char' after the Bcast operation, 24 ranks successfully print the array), while the other half encounter an error with the message:

mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated

I am confident that there is nothing wrong with this code segment itself. I isolated and ran it separately, and the results were normal. I have also searched for information related to this error and found that most people encountered it due to mismatched data types with command case sensitivity (i.e., Bcast vs bcast). However, I am certain that I am using the correct numpy array and Bcast, as I have used Bcast multiple times before in my code without encountering this error.

I suspect this might be related to my preceding code. However, my preceding code is lengthy, and I am unsure of what might cause this outcome. I am also unsure of which part should be included in the question. If anyone knows what could cause this problem, I would be immensely grateful for any insights.

0

There are 0 answers