I believe that you are not providing the proper buffering for Irecv. Each
time through the loop, if flag is false, you are going to post another
non-blocking receive using the same buffer and MPI_Request structure. I
would guess that you are overwriting MPI_Request each time, so that even
though one receive was successful, the code is waiting for the last one to
finish -- and will never get there, since you will always be testing the
overwritten value. When you uncomment the MPI_Wait line, you force the code
to wait until only one message completes, then you break the loop with no
problems.
--Paul
-----------------------
Paul Fisher
Skylight Lead Software Engineer
Integral Systems, Lanham, MD
www.skylighteos.com
-----Original Message-----
From: lam-bounces_at_[hidden] [mailto:lam-bounces_at_[hidden]]On Behalf
Of Yan Xu
Sent: Monday, May 19, 2003 5:16 PM
To: lam_at_[hidden]
Subject: LAM: question about MPI_Irecv and MPI_Test
I have a mpi program, which works only if I uncomment the line marked by
"key line".
// MPI_Wait(&request, &status);
// <---------- key line
If don't uncomment, the program seems never break from the for loop on
process 1, the output is:
PROCESS 0
Before compuation.
PROCESS 1
After computation.
MASTER: sent a = 11
count = 1000
count = 2000
count = 3000
......
Am I misunderstanding the usage of MPI_Irecv and MPI_Test? I run the
code using lam-6.5.6 in a beowulf cluster (OS: RedHat 7.1).
Thanks for your help. Following is the code.
Yan
============================================================================
==
#include <iostream.h>
#include "mpi.h"
int main(int argc, char * argv[])
{
int size, rank, i, j;
int a = 10, count = 0;
int flag = 0;
MPI_Status status;
MPI_Request request;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
cout << "PROCESS " << rank << endl;
if(rank == 0) {
cout << "Before compuation.\n";
for (i = 0; i < 1000; ++i) {
for (j = 0; j < 1000; ++j) {
a += 1;
a -= 1;
}
}
a += 1;
cout << "After computation.\n";
MPI_Send(&a, 1, MPI_INT, 1, 20, MPI_COMM_WORLD);
cout << "MASTER: sent a = " << a << endl;
}
if(rank == 1) {
count = 0;
for( ; ; ) {
MPI_Irecv(&a, 14, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &request);
// MPI_Wait(&request, &status);
// <---------- key line
MPI_Test(&request, &flag, &status);
++count;
if (count % 1000 == 0)
cout << "count = " << count << endl;
if (flag) break;
}
MPI_Get_count(&status, MPI_INT, &count);
cout << "a = " << a << endl;
}
MPI_Finalize();
return 0;
}
_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/
|