简体   繁体   English

如何在运行时将参数从输入文件传递到fortran 77 mpirun?

[英]How to pass parameters from input file to fortran 77 mpirun during run time?

I am an MPI and Fortran 77 noob. 我是MPI和Fortran 77新手。 I have a fortran 77 code FKRPRO.f which I wanted to parallelize using OpenMPI. 我有一个Fortran 77代码FKRPRO.f ,我想使用OpenMPI对其进行并行化。 The code requires a lot of parameters which are fed into it during run time from a separate file. 该代码需要很多参数,这些参数在运行时会从一个单独的文件中输入。 Compilation and running is something like this 编译和运行是这样的

gfortran -o FKRPRO FKRPRO.f
./FKRPRO < Modelfile.txt

the equivalent lines in the code (not my code) are 代码中的等效行(不是我的代码)是

      PARAMETER(LIN=5)
      INTEGER ERROR
      LOGICAL PRNTA
      PRNTA=.FALSE.
      READ(LIN,'(L3)') PRNTA
      READ(LIN,21) M1,M2
   21 FORMAT(11I5)

and so on. 等等。 Can someone please explain to me what READ(LIN,'(L3)') PRNTA means. 有人可以向我解释READ(LIN,'(L3)') PRNTA意思。 The input in the input file Modelfile.txt is something like this 输入文件Modelfile.txt中的输入是这样的

.F.                                                                             
    0   64  
and so on..   

I put the necessary MPI statements in the code. 我在代码中放入了必要的MPI语句。

      INCLUDE 'MPIF.H'
...
      CALL MPI_INIT(ERROR)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD,NPROCS,ERROR)
      CALL MPI_COMM_RANK(MPI_COMM_WORLD,PRANK,ERROR)
...
      CALL MPI_TYPE_FREE(NEWMATRIX,ERROR)
      CALL MPI_FINALIZE(ERROR)

All processes are not being able to read the input file. 所有进程均无法读取输入文件。 I have compiled and run the code like this 我已经编译并运行了这样的代码

mpif77 -o bc3 FKRPROG5.f
mpirun -np 4 bc3 < Modelfile.txt 

This is not working. 这是行不通的。 I get the following errors. 我收到以下错误。 Only the first process or rank 0 can read the file. 只有第一个进程或等级0可以读取文件。

At line 50 of file FKRPROG5.f (unit = 5, file = 'stdin')
Fortran runtime error: End of file
At line 50 of file FKRPROG5.f (unit = 5, file = 'stdin')
Fortran runtime error: End of file
At line 50 of file FKRPROG5.f (unit = 5, file = 'stdin')
Fortran runtime error: End of file
mpirun has exited due to process rank 3 with PID 866 on
node Avinash-rMBP.local exiting improperly. There are two reasons this could occur:

1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.

2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"

This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).

50th line is READ(LIN,'(L3)') PRNTA .Someone kindly point out where I am going wrong :( So, how can I make all processes read from this input file < Modelfile.txt ?? Thanks. 第50行是READ(LIN,'(L3)') PRNTA有人请指出我要去的地方:(因此,我如何使所有进程都可以从此输入文件中读取<Modelfile.txt?谢谢。

The statement 该声明

READ(LIN,'(L3)') PRNTA

causes the program to read, from the unit attached to the channel with id LIN , a 3-character sequence which represents a logical value and assigns the value read to the variable PRNTA . 使程序从与id为LIN的通道相连的单元中读取一个3个字符的序列,该序列表示一个逻辑值,并将读取的值分配给变量PRNTA From the fragments you've shown us the program will read .F. 从您显示给我们的片段中,程序将显示为.F. and set PRNTA to .false. 并将PRNTA设置为.false. .

LIN is set to the constant value 5, which usually means stdin . LIN设置为常数5,通常表示stdin This use of 5 to denote stdin is not a de jure standard, it is more of a de facto standard. 5表示stdin不是法律上的标准,它实际上是标准。

The straightforward way to read a parameter file into an MPI program is to ensure that only one process reads the file and then sends out the values to the other processes which need them. 将参数文件读入MPI程序的直接方法是确保只有一个进程读取该文件,然后将值发送给需要它们的其他进程。

You seem to have written a program in which all processes try to read the same input file but, at run-time, the redirection you've used to pass Modelfile.txt is only working for one process (presumably the process with rank 0). 您似乎编写了一个程序,其中所有进程都尝试读取相同的输入文件,但是在运行时,您用来传递Modelfile.txt的重定向仅适用于一个进程(大概是等级为0的进程) 。 The other processes are not getting an input file at all and are complaining, then bringing the program crashing down. 其他进程根本没有获取输入文件,并且在抱怨,然后使程序崩溃。 The error message you show is typical of a Fortran program which doesn't find an input file at all when it tries to read. 您显示的错误消息是典型的Fortran程序,该程序在尝试读取时根本找不到输入文件。

Far better to write code along the lines: 最好按照以下代码编写代码:

call mpi_init ...
...
if (myrank==0) then
    open(...) inputfile
    read(...) parameters
    close(...)
end if
...
call mpi_bcast(parameters from 0 to all)
...

In general, don't expect the run-time environment for MPI processes to be identical copies of the run-time environment for a sequential program. 通常,不要期望MPI进程的运行时环境与顺序程序的运行时环境完全相同。 I think that you are seeing evidence that your run-time directs the input only to the first process created when your program runs. 我认为您正在看到证据,表明运行时仅将输入定向到程序运行时创建的第一个进程。 Since mpirun is not standardised (though mpiexec is) I don't think you can rely on this run-time behaviour being the same for all MPI implementations. 由于mpirun没有标准化(尽管mpiexec是标准化的),所以我认为您不能依赖于所有MPI实现的运行时行为都相同。 For portability and compatibility you're better off handling I/O explicitly within your program than using o/s features such as redirection. 为了实现可移植性和兼容性,与使用诸如重定向之类的o / s功能相比,最好在程序中显式处理I / O。

You could, rather than have process 0 read the parameters and distribute them to other processes, write your code such that each process reads the same file. 您可以编写代码,使每个进程读取相同的文件,而不是让进程0读取参数并将其分配给其他进程。 If you do write your code this way take care to ensure that the processes aren't fighting over access to the I/O channels; 如果您确实以这种方式编写代码,请务必确保进程不会在争夺对I / O通道的争夺中战斗。 having multiple processes trying to (nearly-)simultaneously read across a single input channel is a sure way to slow things down. 让多个进程试图(几乎)同时读取单个输入通道是确保速度变慢的肯定方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM