[MPICH] MPI_Probe and thread
Rajeev Thakur
thakur at mcs.anl.gov
Fri Jul 28 10:10:17 CDT 2006
Wei-keng,
The specific bug you mention has been fixed in our current source.
However, a different bug has crept in that causes the recv to hang, not the
probe. We were planning to release version 1.0.4 later today, so your bug
report is timely! We will fix it before the release.
Thanks,
Rajeev
> -----Original Message-----
> From: owner-mpich-discuss at mcs.anl.gov
> [mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Wei-keng Liao
> Sent: Friday, July 28, 2006 12:24 AM
> To: mpich-discuss at mcs.anl.gov
> Subject: [MPICH] MPI_Probe and thread
>
>
> I am testing if an MPI node can send message to itself, using
> MPI_Send and
> MPI_Probe on 2 different threads. Below is the MPI program
> that creates a
> 2nd thread, then sends an integer to the thread. The 2nd thread calls
> MPI_Probe, receives the message, and exits.
>
> If MPI_Probe happens before MPI_Send, I found that the
> program will hang
> due to the 2nd thread is blocked in MPI_Probe. That is,
> MPI_Probe is busy
> waiting and will not release/yield to the main thread.
>
> If I add a pthread_yield() or sleep(2) before MPI_Probe to
> ensure MPI_Send
> occurs before MPI_Probe, the 2nd thread's probe will get the
> message and
> exit successfully.
>
> Is there a limitation on using MPI_Probe in multi-threading
> environment?
> I am using MPICH-2.1.0.3 which is configured with
> multi-threading enabled.
>
> Wei-keng
>
> ---------------------
> #include <stdio.h>
> #include <stdlib.h>
> #include <mpi.h>
> #include <pthread.h>
>
> int SELF;
>
> /*----< thread_func() >---------------------------------------------*/
> void* thread_func(void *args) {
> MPI_Status status;
> int src = -1, msg;
>
> /*
> pthread_yield();
> sleep(1);
> */
> printf("P%d (thread): thread started\n", SELF);
> MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
> src = status.MPI_SOURCE;
> printf("P%d (thread): MPI_Probe() MPI_SOURCE = %d\n", SELF, src);
> MPI_Recv(&msg, 1, MPI_INT, src, 0, MPI_COMM_WORLD, &status);
> }
>
> /*----< main() >----------------------------------------------------*/
> int main(int argc, char **argv) {
> int i, msg;
> pthread_t thread_id;
>
> MPI_Init(&argc, &argv);
> MPI_Comm_rank(MPI_COMM_WORLD, &SELF);
>
> pthread_create(&thread_id, NULL, thread_func, NULL);
>
> MPI_Ssend(&msg, 1, MPI_INT, SELF, 0, MPI_COMM_WORLD);
>
> pthread_join(thread_id, NULL);
> printf("P%d ( main ): 2nd thread joined ---- exit\n", SELF);
>
> MPI_Finalize();
> return 0;
> }
>
>
More information about the mpich-discuss
mailing list