gpt4 book ai didi

fortran - 如果使用不是直接从 MPI_COMM_WORLD 创建的组,则 Fortran MPI_COMM_CREATE_GROUP 中的段错误

转载 作者:行者123 更新时间:2023-12-04 01:45:52 26 4
gpt4 key购买 nike

我有一个段错误,我无法用简单的代码真正理解它,它只是:

  • 调用 MPI_INIT
  • 通过 MPI_COMM_DUP 复制全局通信器
  • 通过 MPI_COMM_GROUP 创建一个包含全局通信器一半进程的组
  • 最后从这个组通过 MPI_COMM_CREATE_GROUP 创建一个新的通信器

具体来说,我使用最后一个调用,而不是仅仅使用 MPI_COMM_CREATE,因为它只对组中包含的进程组进行集体处理,而 MPI_COMM_CREATE 对 COMM 中的每个进程进行集体处理。代码如下

program mpi_comm_create_grp
use mpi
IMPLICIT NONE

INTEGER :: mpi_size, mpi_err_code
INTEGER :: my_comm_dup, mpi_new_comm, mpi_group_world, mpi_new_group
INTEGER :: rank_index
INTEGER, DIMENSION(:), ALLOCATABLE :: rank_vec

CALL mpi_init(mpi_err_code)
CALL mpi_comm_size(mpi_comm_world, mpi_size, mpi_err_code)

!! allocate and fill the vector for the new group
allocate(rank_vec(mpi_size/2))
rank_vec(:) = (/ (rank_index , rank_index=0, mpi_size/2) /)

!! create the group directly from the comm_world: this way works
! CALL mpi_comm_group(mpi_comm_world, mpi_group_world, mpi_err_code)

!! duplicating the comm_world creating the group form the dup: this ways fails
CALL mpi_comm_dup(mpi_comm_world, my_comm_dup, mpi_err_code)
!! creatig the group of all processes from the duplicated comm_world
CALL mpi_comm_group(my_comm_dup, mpi_group_world, mpi_err_code)

!! create a new group with just half of processes in comm_world
CALL mpi_group_incl(mpi_group_world, mpi_size/2, rank_vec,mpi_new_group, mpi_err_code)

!! create a new comm from the comm_world using the new group created
CALL mpi_comm_create_group(mpi_comm_world, mpi_new_group, 0, mpi_new_comm, mpi_err_code)

!! deallocate and finalize mpi
if(ALLOCATED(rank_vec)) DEALLOCATE(rank_vec)
CALL mpi_finalize(mpi_err_code)
end program !mpi_comm_create_grp

如果我不复制 COMM_WORLD,而是直接从全局通信器(注释行)创建组,则一切正常。

我正在使用的并行调试器将段错误追溯到对 MPI_GROUP_TRANSLATE_RANKS 的调用,但据我所知,MPI_COMM_DUP 复制了复制的通信器的所有属性,包括排名编号.

我使用的是 ifort 版本 18.0.5,但我也尝试过 17.0.4 和 19.0.2,但没有更好的结果。

最佳答案

事情有点棘手,至少对我来说是这样,但经过一些测试和帮助,找到了问题的根源。

在代码中

CALL mpi_comm_create_group(mpi_comm_world, mpi_new_group, 0, mpi_new_comm, mpi_err_code)

为组 mpi_new_group 创建一个新的通信器,之前创建。然而,用作第一个参数的 mpi_comm_worldmpi_new_group 不在同一上下文中,如 mpich reference 中所述。 :

MPI_COMM_DUP will create a new communicator over the same group as comm but with a new context

所以正确的调用应该是:

CALL mpi_comm_create_group(my_comm_copy, mpi_new_group, 0, mpi_new_comm, mpi_err_code)

即,将 mpi_comm_world 替换为 my_comm_copy,这是创建 mpi_group_world 的那个。

我仍然不确定它为什么与 OpenMPI 一起工作,但它通常更宽容与这类事情。

关于fortran - 如果使用不是直接从 MPI_COMM_WORLD 创建的组,则 Fortran MPI_COMM_CREATE_GROUP 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55251109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com