1

I am trying to use MPI-2 features for one sided communication to write a program for distributed hash table. Each process exposes a memory (B) to all others at the start. Then, hopefully, each process can access the other's memory without synchronization. So far what I have is shown below ( a modified code from an example http://mpi.deino.net/mpi_functions/MPI_Put.html ) . At the end, I get wrong values for B[99] in some cases (differs from run to run). What am I doing wrong?


Edit: I fixed the above problem now with a wait call at the end, but I want to wait for completion of each MPI_Get call. But it looks like the only option is an MPI_Win_fence which requires global synchronization, or MPI_Win_start/MPI_Win_complete for each MPI_Get call. Is it possible to call the latter once as shown below and somehow be able to wait after each MPI_Get call?

#include "mpi.h" 
#include "stdio.h"

#define SIZE2 200

int main(int argc, char *argv[]) 
{
int rank, nprocs, *B;
MPI_Group comm_group;
MPI_Win  winl;


MPI_Init(&argc,&argv); 
MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
MPI_Comm_rank(MPI_COMM_WORLD,&rank); 

MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
for(int i=0; i<SIZE2; i++)  B[i] = 0;

MPI_Comm_group(MPI_COMM_WORLD, &comm_group);
MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int),MPI_INFO_NULL, MPI_COMM_WORLD, &winl);
MPI_Win_post(comm_group, 0, winl);
MPI_Win_start(comm_group, 0, winl);
if(rank == 0)
{
    int drank = (rank == 0) ? 1 : 0;
    int value = 200, value1;
    int index = 99;
    MPI_Get(&value1, 1, MPI_INT, drank, index+1, 1, MPI_INT, winl); 
    MPI_Put(&value, 1, MPI_INT, drank, index, 1, MPI_INT, winl); 

    MPI_Get(&value1, 1, MPI_INT, drank, index+1, 1, MPI_INT, winl); 
    MPI_Put(&value, 1, MPI_INT, drank, index, 1, MPI_INT, winl); 
}

MPI_Win_complete(winl);
MPI_Win_wait(winl);
printf("%d: %d %d\n",rank,B[99],B[100]);

MPI_Group_free(&comm_group);
MPI_Win_free(&winl); 
MPI_Free_mem(B);
MPI_Finalize();

return 0; 
}
Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
danny
  • 1,101
  • 1
  • 12
  • 34
  • I am unable to reproduce your problem. What MPI implementation are you using? On what platform? How do you start the MPI job? Could you give examples of right and wrong output? – Hristo Iliev Dec 10 '14 at 11:37
  • It looks like the problem was run-time dependent. I have fixed that now but have another problem with completing each MPI_Get operation before proceeding. Do you know how to fix it? – danny Dec 10 '14 at 14:55

0 Answers0