3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コミュニケータをメモリを共有するノードで分ける

Last updated at Posted at 2017-11-30

メモリ共有するプロセス間では共有メモリを使いたい場合、メモリ共有するノードだけでグループを作りたい場合などがある。

MPI ver3 以降なら、MPI_Comm_split_type で、メモリ共有するプロセスだけでcommを分けることができる。

#include <mpi.h>
#include <stdio.h>

int main(int argc,char **argv)
{
    MPI_Init(&argc, &argv);

    MPI_Comm shared_nodes;
    int all_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &all_rank);

    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shared_nodes);

    int shm_rank;
    MPI_Comm_rank(shared_nodes, &shm_rank);

    int shm_head_rank = all_rank;
    MPI_Bcast(&shm_head_rank, 1, MPI_INT, 0, shared_nodes);

    if (shm_head_rank == all_rank) {
        printf("all_rank=%d, head_rank=%d, in_shm_rank=%d (HEAD)\n",
               all_rank, shm_head_rank, shm_rank);
    } else {
        printf("all_rank=%d, head_rank=%d, in_shm_rank=%d\n",
               all_rank, shm_head_rank, shm_rank);
    }

    MPI_Comm_free(&shared_nodes);

    MPI_Finalize();
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?