Created
July 13, 2017 02:09
-
-
Save yt-siden/4f98c03f18d4de145e07c3b46e461c9b to your computer and use it in GitHub Desktop.
MPI_Comm_splitのcolorにMPI_UNDEFINEDを指定したときに返ってくるコミュニケータを確認する
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 <unistd.h> | |
#include <iostream> | |
int main(int argc, char* argv[]) | |
{ | |
MPI_Init(&argc, &argv); | |
int rank, size; | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
MPI_Comm_size(MPI_COMM_WORLD, &size); | |
int color = (rank < 4) ? 0 : MPI_UNDEFINED; | |
int key = 0; | |
MPI_Comm newcomm; | |
MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); | |
MPI_Barrier(MPI_COMM_WORLD); | |
for (int i=0; i<size; ++i) | |
{ | |
if (rank == i) | |
std::cout << rank << ':' << (newcomm == MPI_COMM_NULL) << ' ' << (newcomm == MPI_COMM_SELF) << std::endl; | |
usleep(10000); | |
MPI_Barrier(MPI_COMM_WORLD); | |
} | |
MPI_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment