简体   繁体   English

包含'mpif.h'时编译代码,但切换到使用mpi时失败

[英]Code get compiled when include 'mpif.h' but failed when switch to use mpi

I am trying to switch to use mpi for some old fortran codes I have. 我试图切换到使用mpi我的一些旧的fortran代码。 I got some strange errors when compiling the code. 编译代码时出现了一些奇怪的错误。

Error: There is no specific subroutine for the generic 'mpi_type_indexed' at (1)

when I try to switch to 'use mpi' in the code. 当我尝试在代码中切换到“使用mpi”时。 If I use 'include 'mpif.h'' then the program got compiled and is able to run correctly. 如果我使用'include'mpif.h''那么程序已经编译并且能够正确运行。

I have written a compact example to verify the program. 我写了一个简单的例子来验证程序。 Both the code and my example are compiled under gcc/8.1.0 and openmpi/3.1.2. 代码和我的例子都是在gcc / 8.1.0和openmpi / 3.1.2下编译的。

program bt

use mpi

implicit none

!include 'mpif.h'

contains

subroutine read_me()
implicit none
integer :: my_n, my_disp, my_type
integer :: ierr

my_n = 2
my_disp = 4
call MPI_Type_indexed(1, my_n, my_disp, MPI_INTEGER, my_type, ierr)

end subroutine

end program

compile it with no flag: mpif90 bt.F90 编译它没有标志:mpif90 bt.F90

With use mpi committed and include 'mpif.h' uncommitted, everything works fine. 使用mpi commit并包含'mpif.h'未提交,一切正常。 With use mpi uncommitted and include 'mpif.h' committed, I got error says 使用mpi未提交并包含'mpif.h',我得到错误说

bt.F90:23:67:

call MPI_Type_indexed(1, my_n, my_disp, MPI_INTEGER, my_type, ierr)
                                                               1
Error: There is no specific subroutine for the generic 'mpi_type_indexed' at (1)

As indicated in the comments the "problem" that has occurred is that because you have used the module rather than the include file an interface is now in scope, and the compiler can now detect that you are trying to call MPI_Type_indexed with incorrect arguments, as the 2nd and 3rd arguments should be arrays - take a look at https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node79.htm#Node79 to see what the interface should be. 正如评论中所指出的那样,已发生的“问题”是因为您已使用模块而不是包含文件,现在接口已在范围内,并且编译器现在可以检测到您尝试使用不正确的参数调用MPI_Type_indexed,如第二个和第三个参数应该是数组 - 请查看https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node79.htm#Node79以查看接口应该是什么。

Looking at your example it looks as though the original author was assuming that a scalar and a 1 element array are the same thing - this is not the case as the former is rank 0 and the later rank 1. I say this as the first argument specifies how big the arrays should be, and in your case this has the value 1. Thus the 2nd and 3rd arguments should be single element arrays, rather than the scalars you have. 看看你的例子看起来好像原作者假设一个标量和一个1元素数组是同一个东西 - 事实并非如此,因为前者是0级而后者是1级。我说这是第一个参数指定数组应该有多大,在您的情况下,它的值为1.因此,第二个和第三个参数应该是单个元素数组,而不是您拥有的标量。 The simplest solution, as these arguments are Intent( In ), is to put them in square brackets acting as an array constructor 最简单的解决方案,因为这些参数是Intent(In),是将它们放在方括号中作为数组构造函数

call MPI_Type_indexed(1, [ my_n ], [ my_disp ], MPI_INTEGER, my_type, ierr)

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

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