- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
整个问题可以概括为我正在尝试复制调用system
(或fork
)的行为,但在 mpi 环境中。 (事实证明,你不能并行调用system
。)这意味着我有一个程序在许多节点上运行,每个节点上有一个进程,然后我希望每个进程调用一个外部程序(所以对于 n
个节点,我将运行外部程序的 n
个副本),等待所有这些副本完成,然后继续运行原始程序。
为了以并行环境中安全的方式实现这一点,我一直在使用MPI_COMM_SPAWN
和阻塞发送的组合。以下是我的实现的一些示例父程序和子程序(代码采用 Fortran 90,但语法与 C 程序类似):
父级.f90:
program parent
include 'mpif.h'
!usual mpi variables
integer :: size, rank, ierr
integer :: status(MPI_STATUS_SIZE)
integer MPI_COMM_CHILD, ri
integer tag
character *128 message
call MPI_Init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
write(*, *) "I am parent on rank", rank, "of", size
call MPI_COMM_SPAWN('./child', MPI_ARGV_NULL, 1, MPI_INFO_NULL, 0, &
MPI_COMM_SELF, MPI_COMM_CHILD, MPI_ERRCODES_IGNORE, ierr)
write(*, *) "Parent", MPI_COMM_SELF, "child comm", MPI_COMM_CHILD
tag = 1
call MPI_RECV(message, 128, MPI_CHARACTER, 0, tag, MPI_COMM_CHILD,&
status, ierr)
write(*, *) "Parent", MPI_COMM_SELF, "child comm", MPI_COMM_CHILD,&
"!!!"//trim(message)//"!!!"
call mpi_barrier(mpi_comm_world, ierr)
call MPI_Finalize(ierr)
end program parent
子.f90:
program child
include 'mpif.h'
!usual mpi variables
integer :: size, rank, ierr, parent
integer :: status(MPI_STATUS_SIZE)
integer MPI_COMM_PARENT, psize, prank
integer tag
character *128 message
call MPI_init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
call MPI_Comm_get_parent(MPI_COMM_PARENT)
call MPI_Comm_size(MPI_COMM_PARENT, psize, ierr)
call MPI_Comm_rank(MPI_COMM_PARENT, prank, ierr)
write(*, *) "I am child on rank", rank, "of", size, "with comm",&
MPI_COMM_WORLD, "and parent", MPI_COMM_PARENT,&
psize, prank
tag = 1
message = 'Hello Mom and/or Dad!'
call MPI_SEND(message, 128, MPI_CHARACTER, 0, tag, MPI_COMM_PARENT, ierr)
call mpi_barrier(MPI_COMM_WORLD, ierr)
call MPI_Finalize(ierr)
end program child
使用 ifort 16.0.3 和 intel openmpi 1.10.3 进行编译并使用(例如)mpirun -np 4 ./parent
运行后,我得到以下输出:
I am parent on rank 0 of 4
I am parent on rank 1 of 4
I am parent on rank 2 of 4
I am parent on rank 3 of 4
Parent 1 child comm 3
I am child on rank 0 of 1 with comm 0 and parent
3 1 0
Parent 1 child comm 3 !!!Hello Mom and/or Dad!!!!
Parent 1 child comm 3
I am child on rank 0 of 1 with comm 0 and parent
3 1 0
Parent 1 child comm 3
I am child on rank 0 of 1 with comm 0 and parent
3 1 0
Parent 1 child comm 3 !!!Hello Mom and/or Dad!!!!
Parent 1 child comm 3 !!!Hello Mom and/or Dad!!!!
Parent 1 child comm 3
I am child on rank 0 of 1 with comm 0 and parent
3 1 0
Parent 1 child comm 3 !!!Hello Mom and/or Dad!!!!
这本质上就是我想要的行为。据我了解,通过使用 maxprocs=1
、root=0
和 MPI_COMM_SELF
作为父通信器,我告诉每个父进程生成 1 个仅了解其父级的子级,因为它是 MPI_COMM_SELF
范围的 root=0
(也是唯一的进程)。然后我要求它等待来自子进程的消息。子进程获取父进程的 (SELF
) 通信器,并将其消息发送到只能是父进程的 root=0
。所以这一切都很好。
我希望每个进程都能在自己的节点上生成其子进程。我运行的 mpi 进程数等于节点数,当我调用 mpirun
时,我使用标志 --map-by node
来确保一个进程每个节点。我希望子进程能够以某种方式继承它,否则不知道任何其他节点的存在。但我看到的行为是非常不可预测的,一些进程分布在节点上,而其他节点(特别是主 mpi 进程的 root=0
)上有很多堆积。
是否有某种方法可以确保将进程绑定(bind)到父进程的节点?也许通过我可以传递给 MPI_COMM_SPAWN
的 MPI_Info
选项?
最佳答案
Open MPI 中的每个 MPI 作业都以分布在一台或多台主机上的一组插槽开始。这些槽由初始 MPI 进程和作为子 MPI 作业的一部分生成的任何进程使用。在您的情况下,可以在类似于以下内容的主机文件中提供主机:
host1 slots=2 max_slots=2
host2 slots=2 max_slots=2
host3 slots=2 max_slots=2
...
slots=2 max_slots=2
将 Open MPI 限制为每个主机仅运行两个进程。
初始作业启动应为每个主机指定一个进程,否则 MPI 将使用父作业中的进程填充所有槽位。 --map-by ppr:1:node
可以解决这个问题:
mpiexec --hostfile hosts --map-by ppr:1:node ./parent
现在的问题是,随着新的子作业的产生,Open MPI 将继续以先到先得的方式填充插槽,因此不能保证子进程将在与其父进程相同的主机上启动。要强制执行此操作,请按照 Gilles Gouaillardet 的建议将 info
参数的 host
键设置为 MPI_Get_processor_name
返回的主机名:
character(len=MPI_MAX_PROCESSOR_NAME) :: procn
integer :: procl
integer :: info
call MPI_Get_processor_name(procn, procl, ierr)
call MPI_Info_create(info, ierr)
call MPI_Info_set(info, 'host', trim(procn), ierr)
call MPI_Comm_spawn('./child', MPI_ARGV_NULL, 1, info, 0, &
...
您的 MPI 作业可能会中止并显示以下消息:
--------------------------------------------------------------------------
All nodes which are allocated for this job are already filled.
--------------------------------------------------------------------------
这基本上意味着请求的主机要么已满(所有插槽已满)或者该主机不在原始主机列表中,因此没有分配插槽它。前者显然不是这种情况,因为主机文件为每个主机列出了两个插槽,而父作业仅使用一个插槽。 host
键值对中提供的主机名必须与初始主机列表中的条目完全匹配。通常情况下,主机文件仅包含不合格的主机名,如第一段中的示例主机文件,而如果设置了域部分,则 MPI_Get_processor_name
返回 FQDN,例如 node1。 some.domain.local
、node2.some.domain.local
等。解决方案是在主机文件中使用 FQDN:
host1.example.local slots=2 max_slots=2
host2.example.local slots=2 max_slots=2
host3.example.local slots=2 max_slots=2
...
如果分配是由 SLURM 等资源管理器提供的,则解决方案是转换 MPI_Get_processor_name
的结果以匹配 RM 提供的结果。
请注意 MPI_Comm_spawn
的手册页列出了 add-host
键,该键应该将值中的主机名添加到作业的主机列表中:
add-host char * Add the specified host to the list of
hosts known to this job and use it for
the associated process. This will be
used similarly to the -host option.
根据我的经验,这从未起作用(使用 Open MPI 至 1.10.4 进行测试)。
关于控制 MPI_COMM_SPAWN 的节点映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47743425/
请看一下我的代码。 int main () { Program* allcommand = new Program; allcommand->addCommand("add", new
因此,当我遇到调试断言时,我正在编写代码。现在我很想知道为什么这段代码不起作用: for(Model::MeshMap::iterator it = obj1->GetMeshes().begin()
这是我上一个问题的延续 Group, Sum byType then get diff using Java streams . 按照建议,我应该作为单独的线程发布,而不是更新原始线程。 因此,通过我
我正在实现一些非常适合 map 的代码。但是,我要迭代的列表中有大量对象,所以我的问题是哪种方法是解决此问题的最佳方法: var stuff = $.map(listOfMyObjects, some
我正在尝试创建一个包含不同类的成员函数指针的映射。成员函数都具有相同的签名。为了做到这一点,我所有的类都继承了一个 Object 类,它只有默认构造函数、虚拟析构函数和一个虚拟 ToString()
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: how do you make a heterogeneous boost::map? 有可能在 C++ 中
我有一个 Mysql 查询,请检查以下内容: SELECT `tbl_classSubjects`.`classID` , `tbl_classSubjects`.`sectionID` , `tbl
抱歉,这可能是一个基本问题。 JNA直接映射和接口(interface)映射有什么区别? 我的解释是否正确: 直接映射 : 直接使用库对象(如 Java 中的静态 main) 接口(interface
在 Twitter's Scala school collections section ,它们显示了一个带有偏函数作为值的 Map: // timesTwo() was defined earlie
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
据我了解,从 scala stdlib 声明一个映射并没有将其专门用于原始类型。我要的不是付出装箱/拆箱的代价,而是同时拥有scala map 的接口(interface)。一个明显的选择是使用 tr
如何为这样的 JSON 响应创建对象映射,它只是一个整数数组: [ 565195, 565309, 565261, 565515, 565292, 565281, 566346, 5
是否可以为 DTO 对象创建映射然后查询它们 而不是域?如果不解释为什么? 如果我需要几个 dtos 怎么办? DTos 是只读的 ID 由 NH 自动生成 将来这些 dtos 将设置映射到链接的 d
我有一个返回的函数(常规代码) [words: "one two", row: 23, col: 45] 在 Scala 中,我将上面更改为 Scala Map,但随后我被迫将其声明为 Map[Str
我有一组与 Vanilla 磅蛋糕烘焙相关的数据(200 行),具有 27 个特征,如下所示。标签caketaste是衡量烤蛋糕的好坏程度,由 bad(0) 定义, neutral(1) , good
我有试图映射到新代码的遗留代码。 OLD_PERSON pid sid name age NEW_PERSON pid sid fid age RESOLVE_PERSON pid fid statu
我有一个表,其中一个字段可以指向其他 3 个表之一中的外键,具体取决于鉴别器值是什么(Project、TimeKeep 或 CostCenter。通常这是用子类实现的,我想知道我有什么 注意子类名称与
我有一个类型 [ST s (Int, [Int])] 的绑定(bind)我正在尝试申请runST使用映射到每个元素,如下所示: name :: [ST s (Int, [Int])] --Of Cou
在我正在进行的项目中,我有以下实体:分析师、客户 和承包商。每个都继承自基类 User。 public abstract class User { public virtual int Id
我想知道是否可以在 Vim 中创建一个映射(对于普通模式),允许用户在映射执行之前输入。 我想为我最常用的 grep 命令创建一个快捷方式的映射。我希望命令允许输入我正在搜索的内容,然后在输入时执行。
我是一名优秀的程序员,十分优秀!