LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Zenghui Wu (wu_at_[hidden])
Date: 2003-12-11 09:03:01


Hello everybody,
I tried to implement one-sided communication with MPI_Put on two processes. On
both processes have two vectors, process 0 updates the vector v[0] with the
value of v[1], i.e. v[0]+=v[1], and send the updated values of v[0] to process
1. Process 1 updates the vector v[1] with v[1]+=v[0] and send the updated values
of v[1] to process 0. I used "post, start, complete and wait" synchronizing the
processes as the program below showed, but the program hanged by MPI_Win_start.
Do you think if there is still error in this program example? But when I created
only one window, it can work and get the right result. And another question, in
some documentes I have read some assert arguments for the function
MPI_Win_start, MPI_Win_post and MPI_Win_fence, e.g. MPI_MODE_NOCHECK,
MPI_MODE_NOPUT, etc. but I can't use these arguments, the compiler said it
could not find it, and I have checked in the head files, they are not defined,
why? Below is the example program. Thanks for helps.

Best Regards

Zenghui Wu

University of Dortmund, Germany

#define ENTRIES 1000

int main(int argc, char *argv[])
{
  int i, size, rank;
  long j;
  double **v;
  
  MPI_Win win[2];
  MPI_Group group;

  MPI_Init(&argc, &argv);

  MPI_Comm_size(MPI_COMM_WORLD, &size); // the size should be 2
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_group(MPI_COMM_WORLD, &group);
  
  v=(double **)calloc(size, sizeof(double *));

  
  for(i=0;i<size;i++)
    {
      MPI_Alloc_mem(sizeof(double) * ENTRIES, MPI_INFO_NULL, &v[i]);
      MPI_Win_create(v[i], sizeof(double) * ENTRIES, sizeof(double),
MPI_INFO_NULL, MPI_COMM_WORLD, &win[i]);
    }

  // initialize the values of v[0] and v[1]
  for(i=0; i<size; i++)
    for(j=0; j<ENTRIES; j++)
      v[i][j]=1.0;
      
  for(i=0;i<10;i++)
    {
      for(j=0; j<ENTRIES; j++)
        v[rank][j]=v[rank][j]+v[size-1-rank][j];

      MPI_Win_post(group, 0, win[size-1-rank]); // The program hang here.
                                                    
      MPI_Barriar(MPI_COMM_WORLD);
      
      MPI_Win_start(group, 0, win[rank]);

      MPI_Put(v[rank], ENTRIES, MPI_DOUBLE, (size-1-rank), 0 , ENTRIES,
MPI_DOUBLE, win[rank]);

      MPI_Win_complete(win[rank]);

      MPI_Win_wait(win[size-1-rank]);

    }
  
  MPI_Win_free(&win[0]);
  MPI_Win_free(&win[1]);
  MPI_Free_mem(v[0]);
  MPI_Free_mem(v[1]);
  MPI_Finalize();
  return(0);
}