Created
June 11, 2020 15:28
-
-
Save hurbeana/b12808ead9225f77c3ed1200f687c768 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
int main(int argc, char *argv[]) { | |
MPI_Init(&argc, &argv); | |
MPI_Comm comm = MPI_COMM_WORLD; | |
MPI_Comm newcomm; | |
int rank, size; | |
MPI_Comm_rank(comm ,&rank); | |
MPI_Comm_size(comm ,&size); | |
int A[size]; | |
int B; | |
int root = size -1; | |
//int root = size/2; | |
for (int i=0; i<size; i++) A[i] = i; | |
// printf("KEY[%d] = %d\n", rank, (rank < size/2) ? rank:size-rank); | |
MPI_Comm_split (comm , 0, ((rank <size /2) ? rank : size -rank), &newcomm); | |
MPI_Scatter(A,1,MPI_INT ,&B,1,MPI_INT ,root ,newcomm ); | |
printf ("B[%d]=%d\n",rank ,B); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment