MPI:获取给定通讯器中所有处理器的等级
MPI: get ranks of all processors in a given communicator
我有一个通信器,我如何获得该通信器中所有处理器的等级?
我所能找到的就是如何获得给定通信器中的处理器数量,但似乎没有获得秩集合的函数。
添加到Patrick的答案中:
要获得从comm_1到comm_2或从comm_2到comm_2的进程等级,您可以首先提取底层MPI_Group
,然后使用MPI_Group_translate_ranks
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm my_comm;
int n;
MPI_Comm_size(comm, &n);
int rank1[n] = {0,1,2,3,...}
int rank2[n];
// Some Code
MPI_Group world_group;
MPI_Group my_comm_group;
MPI_Comm_group(comm, &world_group);
MPI_Comm_group(my_comm, &my_comm_group);
MPI_Group_translate_ranks(world_group, n, rank1, my_comm_group, rank2);
您将获得数组rank1,数组rank2中对应的等级。
秩总是线性分配的。如果您的通信器的大小为p
,那么所有处理器的列将为0, 1, 2, ..., p-1
。
如果您的通信器是MPI_COMM_WORLD的子通信器,则处理器将重新标记为从0
到子通信器大小的等级。
如果您正在查找子通信器的处理器的全局排列(如MPI_COMM_WORLD
中分配的)。您必须使用进程排名为MPI_COMM_WORLD
:的MPI_Gather
或MPI_Allgather
// get global rank
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// getting size of your communicator
int size;
MPI_Comm_size(your_comm, &size);
// all-gather global ranks
int * ranks = malloc(sizeof(int)*size);
MPI_Allgather(&rank, 1, MPI_INT, ranks, 1, MPI_INT, your_comm);
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- #定义c-预处理器常量..我做错了什么
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 有没有办法在从编译器获取参数时避免预处理器宏?
- 从预处理器获取 Windows 版本(C++ Win32)
- 获取文件数据预处理器宏
- 获取处理器相关性(linux)时出现问题
- 获取对源文件中特定函数的所有调用并生成其他文件(使用 C、C++预处理器或脚本)
- 如何在C或C 中获取主板地址或处理器ID /序列号
- MPI:获取给定通讯器中所有处理器的等级
- 从处理器上电以来从 std::chrono::steady_clock::now() 获取微秒时间
- 如何使用预处理器从源文件中获取一行文本
- 如何使用Boost预处理器获取类函数可访问的函数列表
- 如何从英特尔的处理器与汇编程序获取随机数?
- 使用预处理器获取枚举的大小
- 获取特定进程正在运行的处理器数
- visual在c++中获取基本的文本处理器进行编译
- 获取虚拟机内物理处理器的数量
- Win32 API 函数获取处理器的当前速度
- c++获取处理器ID