Created
July 12, 2015 11:51
-
-
Save keisukefukuda/cf2e5119ae1ea09e618c to your computer and use it in GitHub Desktop.
計算機システム MPIサンプル [2]
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
/* | |
* 計算機システム MPIサンプル [2] | |
* MPIが起動されているプロセス数と、各プロセスが自分のプロセスIDを表示する | |
*/ | |
#include <stdio.h> | |
#include <mpi.h> | |
int main(int argc, char **argv) { | |
int rank; /* 自分自身のプロセスID */ | |
int size; /* 全体のプロセス数 */ | |
MPI_Init(&argc, &argv); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
MPI_Comm_size(MPI_COMM_WORLD, &size); | |
if (rank == 0) { | |
printf("Number of processes: %d\n", size); | |
} | |
MPI_Barrier(MPI_COMM_WORLD); | |
/* 出力は混ざるor順不同(正常動作) */ | |
printf("%d\n", rank); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment