openmpi,termios和stdin

时间:2018-05-07 18:26:24

标签: stdin file-descriptor openmpi termios

我有关于openmpi和标准输入文件描述符(fd)的问题 和termios的使用。 实际上是ompi程序中使用的标准fd吗?

标准输入重定向到某个等级的mpirun -stdin选项。我假设在幕后做了一些事情。

例如,以下代码段仅在tcgetattr处针对STDIN_FILENO失败,仅适用于mpirun(但按顺序工作)。

#include <iostream>
#include <mpi.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
using namespace std;

int main(int argc, char* argv[]) {
  MPI_Status status;
  MPI_Init(&argc, &argv);

  int in = dup( STDIN_FILENO );
  struct termios org_opts, new_opts;
  res = tcgetattr( in, &org_opts);
  assert(res==0);

  MPI_Finalize( );
}    

1 个答案:

答案 0 :(得分:0)

在Open MPI中,stdin进程会读取mpirun

然后将读取的数据转发到一个MPI任务(任务0,除非另有明确请求),这可能涉及orted守护程序。

从底线开始,从转发 stdin的MPI任务的角度来看,文件描述符零是本地守护程序的pipe({{1 }}或mpirun),这就是orted和朋友失败的原因。

注意所有其他MPI任务的文件描述符零指向tcgetattr()

IIRC,/dev/null提供SLURM选项(例如直接运行),其中srun是伪终端。