如何获取MPI中物理机的数量 [英] How to get the number of physical machine in MPI

查看:400
本文介绍了如何获取MPI中物理机的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 MPI_Comm_size 来获取总处理器数量。
但是我怎样才能得到真正的物理机器的数量?

解决方案

em>您的意思是一组处理元素,共享一个公共内存地址空间,那么MPI-3分类类型操作 MPI_COMM_SPLIT_TYPE 可以用于可移植地获取这些机器的数量:

  int getNodeCount(void)
{
int rank,is_rank0,nodes;
MPI_Comm shmcomm;

MPI_Comm_split_type(MPI_COMM_WORLD,MPI_COMM_TYPE_SHARED,0,
MPI_INFO_NULL,& shmcomm);
MPI_Comm_rank(shmcomm,& rank);
is_rank0 =(rank == 0)? 1:0;
MPI_Allreduce(& is_rank0,& nodes,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
MPI_Comm_free(& shmcomm);
返回节点;

$ / code>

在Fortran中:

使用mpi
隐式无
整数,意图(出):: count $($)$ <$ c $> b $ b integer :: shmcomm,rank,is_rank0,ierr

call MPI_COMM_SPLIT_TYPE(MPI_COMM_WORLD,MPI_COMM_TYPE_SHARED,0,&
MPI_INFO_NULL,shmcomm,ierr)
call MPI_COMM_RANK(shmcomm ,rank,ierr)
if(rank == 0)then
is_rank0 = 1
else
is_rank0 = 0
end if
call MPI_ALLREDUCE(is_rank0 ,count,1,MPI_INTEGER,MPI_SUM,&
MPI_COMM_WORLD,ierr)
call MPI_COMM_FREE(shmcomm,ierr)
end subroutine getNodeCount
pre>

该函数首先将世界通信器分成能够创建共享内存区域的队列组,即每个物理机器一个组(给出上述定义)。然后它通过总计0级实体的数量来统计这些组的数量。由于使用集体操作,该功能必须由世界组中的所有级别调用。



免责声明:未经测试的代码 - 使用后风险自负。


I can use MPI_Comm_size to get the number of total processors. But how can I get the number of real physical machine?

解决方案

If by physical machine you mean a set of processing elements, sharing a common memory address space, then the MPI-3 split-by-type operation MPI_COMM_SPLIT_TYPE could be used to portably obtain the number of such machines:

int getNodeCount(void)
{
   int rank, is_rank0, nodes;
   MPI_Comm shmcomm;

   MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,
                       MPI_INFO_NULL, &shmcomm);
   MPI_Comm_rank(shmcomm, &rank);
   is_rank0 = (rank == 0) ? 1 : 0;
   MPI_Allreduce(&is_rank0, &nodes, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
   MPI_Comm_free(&shmcomm);
   return nodes;
}

And in Fortran:

subroutine getNodeCount(count)
  use mpi
  implicit none
  integer, intent(out) :: count
  integer :: shmcomm, rank, is_rank0, ierr

  call MPI_COMM_SPLIT_TYPE(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, &
                           MPI_INFO_NULL, shmcomm, ierr)
  call MPI_COMM_RANK(shmcomm, rank, ierr)
  if (rank == 0) then
     is_rank0 = 1
  else
     is_rank0 = 0
  end if
  call MPI_ALLREDUCE(is_rank0, count, 1, MPI_INTEGER, MPI_SUM, &
                     MPI_COMM_WORLD, ierr)
  call MPI_COMM_FREE(shmcomm, ierr)
end subroutine getNodeCount

The function first splits the world communicator into groups of ranks capable of creating shared memory regions, i.e. one group per physical machine (give the definition above). It then counts the number of such groups by summing the number of rank-0 entities. Due to the use of collective operations, the function must be called by all ranks in the world group.

Disclaimer: untested code - use at your own risk.

这篇关于如何获取MPI中物理机的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆