Skip to content

Instantly share code, notes, and snippets.

@keisukefukuda
Created July 12, 2015 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keisukefukuda/cf2e5119ae1ea09e618c to your computer and use it in GitHub Desktop.
Save keisukefukuda/cf2e5119ae1ea09e618c to your computer and use it in GitHub Desktop.
計算機システム MPIサンプル [2]
/*
* 計算機システム 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