【问题标题】:Is there any way to infer how many workers are on the same node using MPI?有没有办法使用 MPI 推断同一节点上有多少工作人员?
【发布时间】:2021-12-09 08:27:11
【问题描述】:

我如何知道在同一个节点上设置了多少个工人?我可以得到整体COMM_WORLD 大小,甚至可以使用PMI,它对节点上的进程进行排名。如何知道每个节点上启动了多少进程?

【问题讨论】:

  • 使用MPI_Comm_split_type 将通信器拆分为位于节点上的子通信器。然后在这些子通信器上使用MPI_Comm_size

标签: mpi


【解决方案1】:

给你。使用MPI_Comm_split_type找到节点对应的子通信器,然后计算有多少个,以及它们的大小。

  int main( int argc,char **argv ) {
  MPI_Init(&argc,&argv);
  MPI_Comm comm = MPI_COMM_WORLD;
  int procno,nprocs;
  MPI_Comm_size( comm,&nprocs );
  MPI_Comm_rank( comm,&procno );

  MPI_Comm node_comm;
  MPI_Comm_split_type( comm,MPI_COMM_TYPE_SHARED,procno,MPI_INFO_NULL,&node_comm);
  int rank_on_node,size_of_node;
  MPI_Comm_rank( node_comm,&rank_on_node );
  MPI_Comm_size( node_comm,&size_of_node );
  int head_node = (rank_on_node==0);
  int number_of_nodes;
  MPI_Reduce( &head_node,&number_of_nodes,1,MPI_INT,MPI_SUM,0,comm);
  if (procno==0)
    printf("There are %d nodes\n",number_of_nodes);

  MPI_Comm node_heads;
  MPI_Comm_split( comm,head_node,procno,&node_heads );
  int node_sizes[number_of_nodes];
  MPI_Gather( &size_of_node,1,MPI_INT, node_sizes,1,MPI_INT, 0,node_heads );
  if (procno==0) {
    printf("Node sizes:");
    for (int inode=0; inode<number_of_nodes; inode++)
      printf(" %d",node_sizes[inode]);
    printf("\n");
  }

  MPI_Finalize();
  return 0;
}

例如,在我的系统上,如果我请求总共 10 个进程的 3 个节点,我会得到:

There are 3 nodes
Node sizes: 4 3 3

很好。我有点期待“4 4 2”。

【讨论】:

  • 非常漂亮。不会想到这一点。
猜你喜欢
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
  • 2020-12-23
  • 1970-01-01
相关资源
最近更新 更多