I tried to implement a buffered version of MPI_Get, so no global fence is necessary when one process gets something from only one other process. However, I get this error:
Read -1, expected 40, errno = 14
I used openmpi version 4.1.2, and ran the program below with mpirun -n 2.
#include <mpi.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/mman.h>
void *ptr;
static MPI_Win win;
void setup(size_t maxmem)
{
if ((ptr = mmap (NULL, maxmem, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))
== (void *)(intptr_t)-1) {
MPI_Abort(MPI_COMM_WORLD, 1);
}
MPI_Win_create (ptr, maxmem, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
}
void bufferedGet(void *origin, size_t count,
size_t owner_rank, size_t offset)
{
MPI_Win_lock (MPI_LOCK_SHARED, owner_rank, 0, win);
MPI_Get (origin, count, MPI_BYTE, owner_rank,
offset, count,
MPI_BYTE, win);
MPI_Win_unlock (owner_rank, win);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
size_t size = 409600;
setup(size);
void *result = malloc(10);
bufferedGet(result, 10, 0, 1);
free(result);
MPI_Win_free(&win);
munmap(ptr, size);
MPI_Finalize();
}
I think you are just missing | PROT_READ
to your mmap
call.