Created
December 27, 2020 22:48
-
-
Save ksiazekm/17046cad0d244188d0e2391262aa918c to your computer and use it in GitHub Desktop.
Processes returns wrong results on OpenMPI 4.0.4 unless $OMPI_MCA_pml is set to "^ucx"
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
int main(int argc, char **argv) | |
{ | |
int mpirank, mpisize; | |
int tabsize = atoi(*(argv + 1)); | |
MPI_Init(&argc, &argv); | |
MPI_Comm_rank(MPI_COMM_WORLD, &mpirank); | |
MPI_Comm_size(MPI_COMM_WORLD, &mpisize); | |
unsigned long int sum = 0; | |
int rcvsize = tabsize / mpisize; | |
int *rcvbuf = malloc(rcvsize * sizeof(int)); | |
int *tab = malloc(tabsize * sizeof(int)); | |
int totalsum = 0; | |
if(mpirank == 0){ | |
for(int i=0; i < tabsize; i++){ | |
*(tab + i) = 1; | |
} | |
} | |
MPI_Scatter(tab, tabsize/mpisize, MPI_INT, rcvbuf, tabsize/mpisize, MPI_INT, 0, MPI_COMM_WORLD); | |
for(int i=0; i < tabsize/mpisize; i++){ | |
sum += *(rcvbuf + i); | |
} | |
printf("%d sum = %ld %d\n", mpirank, sum, tabsize/mpisize); | |
MPI_Reduce(&sum, &totalsum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); | |
if(mpirank == 0){ | |
printf("The totalsum = %li\n", totalsum); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment