LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Yan Xu (yax2_at_[hidden])
Date: 2003-05-19 16:16:19


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;
}