Skip to content

Instantly share code, notes, and snippets.

@keisukefukuda
Created July 12, 2015 11:56
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/076e51646c292fdfd213 to your computer and use it in GitHub Desktop.
Save keisukefukuda/076e51646c292fdfd213 to your computer and use it in GitHub Desktop.
計算機システム MPIサンプル [6]
/*
* 計算機システム MPIサンプル [6]
* MPIのプロセスが実際にどのホストで実行されているかを調べる
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <mpi.h>
#include <sys/utsname.h>
void print_host() {
int rank;
struct utsname uts;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
uname(&uts);
/*
* 注意:環境により、行毎に表示されたり、
* 行同士が混ざって表示されることがある.
* プロセス同士での表示の順番は保証されない
*/
printf("rank %d: %s\n", rank, uts.nodename);
}
int main(int argc, char **argv) {
MPI_Init(&argc, &argv);
print_host();
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment