Subject: | Recv and MPI_ANY_SOURCE |
Date: | Tue, 26 Nov 2013 12:16:07 +0100 |
To: | bug-Parallel-MPI-Simple [...] rt.cpan.org |
From: | Matthieu Volat <matthieu.volat [...] ujf-grenoble.fr> |
Hi,
I've noticed the logic behind Recv() in the perl module is to do 2 MPI_Recv() to get first an integer for the size of the perl scalar, then the scalar itself. But both MPI_Recv() calls use the same source and tags arguments, so if you use the ANY_SOURCE source control, the function may mix unrelated messages and fails.
The problem can simply be fixed by binding the 2nd MPI_Recv() to the source/tag of the first one:
--- Simple.xs.orig 2013-11-26 11:32:16.169406199 +0100
+++ Simple.xs 2013-11-26 11:32:51.863960405 +0100
@@ -68,7 +68,7 @@
MPI_Recv(len_buf, 1, MPI_INT, source, tag, (MPI_Comm)SvIVX(comm), &tstatus);
recv_buf = (char*)malloc((len_buf[0]+1)*sizeof(char));
if (recv_buf == NULL) croak("Allocation error in _Recv");
- MPI_Recv(recv_buf, len_buf[0], MPI_CHAR, source, tag,
+ MPI_Recv(recv_buf, len_buf[0], MPI_CHAR, tstatus.MPI_SOURCE, tstatus.MPI_TAG,
(MPI_Comm)SvIVX(comm), &tstatus);
rval = newSVpvn(recv_buf, len_buf[0]);
sv_setiv(status, tstatus.MPI_SOURCE);
--
Matthieu Volat <matthieu.volat@ujf-grenoble.fr>
Ingénieur de Recherche CNRS
ISTerre - Institut des Sciences de la Terre
Université Joseph Fourier, Grenoble
Message body not shown because it is not plain text.