rookiehpc / rookiehpc.github.io

A website covering major HPC technologies, designed to welcome contributions.
GNU Affero General Public License v3.0
56 stars 12 forks source link

MPI_Win_allocate_shared() example has bugs #327

Open jczhang07 opened 12 months ago

jczhang07 commented 12 months ago

One can not assume MPI_Barrier() could synchronize the shared memory read and write. For the example, https://github.com/rookiehpc/rookiehpc.github.io/blob/main/mpi/docs/mpi_win_allocate_shared/example_1.c, a fix would be

MPI_Win_allocate_shared(..,&window);
MPI_Win_lock_all(MPI_MODE_NOCHECK, window);

*window_buffer = 100;
// make the write observable to peer
MPI_Win_sync(window);
MPI_Barrier(MPI_COMM_WORLD);

// Modify peer's element
if (my_rank == 0) {
   window_buffer[1]++;
} else {
  window_buffer[-1]--;
}

// make the update observable to peer
MPI_Win_sync(window);
MPI_Barrier(MPI_COMM_WORLD);

MPI_Win_unlock_all(window);
MPI_Win_free(&window);

Example 12.23 in https://www.mpi-forum.org/docs/mpi-4.1/mpi-41-rc1.pdf gives a correct use, though in Fortran.

Cc @hzhou, @raffenet