Created
November 26, 2021 23:33
-
-
Save eschnett/8de7ea43c746de07909544bf2c38535a to your computer and use it in GitHub Desktop.
Build with Homebrew or MacPorts MPICH 3.4.2 on macOS Monterey. Run with >1 processes. The code will segfault in the 5th call to `MPI_Reduce`. Setting `root = 0` avoids this.
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 <mpi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
MPI_Init(&argc, &argv); | |
MPI_Comm comm = MPI_COMM_WORLD; | |
int size; | |
MPI_Comm_size(comm, &size); | |
int rank; | |
MPI_Comm_rank(comm, &rank); | |
int root = size - 1; | |
int send = rank; | |
int recv; | |
for (int i = 0; i < 10; ++i) { | |
if (rank == 0) | |
fprintf(stderr, "MPI_Reduce i=%d\n", i); | |
MPI_Reduce(&send, rank == root ? &recv : NULL, 1, MPI_INT, MPI_SUM, root, | |
comm); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment