Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MPI运行的自定义中断处理程序_Mpi_Interrupt_Openmpi_Interrupt Handling_Keyboardinterrupt - Fatal编程技术网

MPI运行的自定义中断处理程序

MPI运行的自定义中断处理程序,mpi,interrupt,openmpi,interrupt-handling,keyboardinterrupt,Mpi,Interrupt,Openmpi,Interrupt Handling,Keyboardinterrupt,显然,mpirun使用了一个SIGINT处理程序,它将SIGINT信号“转发”给它产生的每个进程 这意味着您可以为启用mpi的代码编写一个中断处理程序,执行mpirun-np 3 my mpi-enabled executable,然后为这三个进程中的每一个进程发出SIGINT。之后不久,mpirun退出。当您有一个只打印错误消息然后退出的小型自定义处理程序时,这种方法可以很好地工作但是,当您的自定义中断处理程序正在执行一项非常重要的工作(例如,执行严肃的计算或持久化数据)时,该处理程序不会运行

显然,
mpirun
使用了一个SIGINT处理程序,它将SIGINT信号“转发”给它产生的每个进程

这意味着您可以为启用mpi的代码编写一个中断处理程序,执行
mpirun-np 3 my mpi-enabled executable
,然后为这三个进程中的每一个进程发出SIGINT。之后不久,mpirun退出。当您有一个只打印错误消息然后退出的小型自定义处理程序时,这种方法可以很好地工作但是,当您的自定义中断处理程序正在执行一项非常重要的工作(例如,执行严肃的计算或持久化数据)时,该处理程序不会运行到完成。我认为这是因为mpirun决定过早退出

这是在执行启用mpi的可执行文件后按ctrl-c(即导致SIGINT)时的stderr。这是理想的预期行为:

interrupted by signal 2.
running viterbi... done.
persisting parameters... done.
the master process will now exit.
interrupted by signal 2.
running viterbi... mpirun: killing job...

--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 8970 on node pharaoh exited on signal 0 (Unknown signal 0).
--------------------------------------------------------------------------
mpirun: clean termination accomplished
这是执行
mpirun-np 1我的mpi启用的可执行文件后按
ctrl-c
时的标准。这就是有问题的行为:

interrupted by signal 2.
running viterbi... done.
persisting parameters... done.
the master process will now exit.
interrupted by signal 2.
running viterbi... mpirun: killing job...

--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 8970 on node pharaoh exited on signal 0 (Unknown signal 0).
--------------------------------------------------------------------------
mpirun: clean termination accomplished
回答以下任何问题都可以解决我的问题:

  • 如何重写mpirun SIGINT处理程序(如果可能的话)
  • 如何避免在mpirun终止后立即生成的进程mpirun终止
  • 在mpirun终止之前,是否有另一个mpirun可能发送给子进程的信号
  • 是否有一种方法可以“捕获”所谓的“信号0(未知信号0)”(参见上面的第二个标准)

我正在linux上运行openmpi-1.6.3。

根据,您可以将
SIGUSR1
SIGUSR2
发送到
mpirun
,它将转发它,而不会自行关闭。

遇到同样的问题时,我遇到了这个问题,并通过@Zulan找到了答案

我特别想从用户那里捕获一个
SIGINT
(Ctrl+C),做一些事情,然后有序地退出。因此,使用
SIGUSR1
不是一个选项。然而,阅读@Zulan链接的手册页显示,mpirun(至少是OpenMPI版本)捕获一个
SIGINT
,然后向子进程发送一个
SIGTERM
信号。因此,在我的代码中捕获
SIGTERM
,允许我调用正确的退出例程


请注意,如前所述,信号处理不会与MPI一起保存。

我面临的问题与mpirun在发送信号SIGINT后立即退出的问题相同,因此如果并行进程处理信号,则会使其保持运行,这需要很长时间。如果mpirun之后的bash脚本在复制文件时执行其他操作,这是不好的,因为进程可能仍然会清理