Created
December 16, 2011 12:41
-
-
Save aprell/1485897 to your computer and use it in GitHub Desktop.
MPI window creation must be collective
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <mpi.h> | |
#define WORKER(id) if (ID == (id)) | |
#define MASTER WORKER(0) | |
int main(int argc, char *argv[]) | |
{ | |
int numprocs, ID; | |
int *buf; | |
MPI_Win win; | |
MPI_Group group, new_group; | |
MPI_Comm new_comm; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); | |
MPI_Comm_rank(MPI_COMM_WORLD, &ID); | |
MPI_Comm_group(MPI_COMM_WORLD, &group); | |
MPI_Group_incl(group, 1, &ID, &new_group); | |
MPI_Comm_create(MPI_COMM_WORLD, new_group, &new_comm); | |
MASTER { | |
int i; | |
MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &buf); | |
*buf = 0; | |
MPI_Win_create(buf, sizeof(int), 1, MPI_INFO_NULL, new_comm, &win); | |
for (i = 1; i < numprocs; i++) | |
MPI_Send(&win, sizeof(win), MPI_BYTE, i, 0, MPI_COMM_WORLD); | |
} else { | |
MPI_Recv(&win, sizeof(win), MPI_BYTE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
} | |
// Passive target communication | |
// Cooperation from target process not needed for communication | |
MASTER { | |
MPI_Barrier(MPI_COMM_WORLD); | |
printf("Master %d: %d\n", ID, *buf); | |
} else { | |
int n = 42; | |
// Starts access epoch for window win | |
// XXX Use of win generates segmentation fault: address not mapped | |
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win); | |
MPI_Put(&n, 1, MPI_INT, 0, 0, 1, MPI_INT, win); | |
// Ends access epoch for window win | |
MPI_Win_unlock(0, win); | |
MPI_Barrier(MPI_COMM_WORLD); | |
} | |
MASTER { | |
MPI_Win_free(&win); | |
MPI_Free_mem(buf); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment