Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/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
C++ 将MPI_通信从Fortran传递到C/C++;导致分割错误的原因_C++_Fortran_Mpi_Interop - Fatal编程技术网

C++ 将MPI_通信从Fortran传递到C/C++;导致分割错误的原因

C++ 将MPI_通信从Fortran传递到C/C++;导致分割错误的原因,c++,fortran,mpi,interop,C++,Fortran,Mpi,Interop,我正在尝试将MPI通信器从Fortran传递到C/C++。我不确定要传递什么类型的句柄:type(MPI\u Comm),MPI\u Fint,或者只是整数。我尝试了上述选项的几种组合,但要么无法编译,要么出现了分段错误。以下代码生成错误消息: 程序接收信号SIGSEGV:分段故障-存储器无效 参考资料 接口 module Tailor_module use mpi use, intrinsic :: ISO_C_Binding, only: C_int, C_double, C_char,

我正在尝试将MPI通信器从Fortran传递到C/C++。我不确定要传递什么类型的句柄:
type(MPI\u Comm)
MPI\u Fint
,或者只是整数。我尝试了上述选项的几种组合,但要么无法编译,要么出现了分段错误。以下代码生成错误消息:

程序接收信号SIGSEGV:分段故障-存储器无效 参考资料

接口

module Tailor_module

use mpi
use, intrinsic :: ISO_C_Binding, only: C_int, C_double, C_char, c_associated
use, intrinsic :: ISO_C_Binding, only: c_ptr, C_NULL_ptr

implicit none
private

interface

    function Tailor__getobject(comm) result(optr) bind(C, name="Tailor__getobject")
        import c_ptr
        implicit none
        integer, intent(in), value :: comm
        type(c_ptr) :: optr
    end function Tailor__getobject

end interface

type(c_ptr), save :: obj = c_null_ptr

public :: Create

CONTAINS

    subroutine Create(com)
        integer, intent(in) :: com
        obj = Tailor__getobject(comm=com)
        return
    end subroutine Create

end module Tailor_module
Fortran驱动程序

program main

use mpi
use Tailor_module, only : Create
IMPLICIT NONE

integer error

call MPI_Init(error)
call Create(MPI_COMM_WORLD);
call MPI_Finalize (error)

end
C++

typedef void * OpaqueObject;

extern "C"
{
    OpaqueObject Tailor__getobject(MPI_Fint *f_handle);
}

OpaqueObject Tailor__getobject(MPI_Fint *f_handle)
{
    MPI_Comm comm;
    comm = MPI_Comm_f2c(*f_handle); 
    OpaqueObject s;
    return s;
}

您使用的是MPICH还是Open MPI(派生)?我使用的是Open MPI。您确定
修饰符吗?不。事实上,我不熟悉fortran。我正在尝试用Fortran接口编写我的C++代码。删除<代码>值>代码>关键字,消除了分割错误。你使用MPICH还是开放MPI(派生)?我用Open MPIAre你肯定关于<代码>值< /C>修饰符?不。事实上我不熟悉FORTRAN。我尝试用C++代码编写FORTRAN接口,删除<代码>值>代码>关键字,消除了分割错误。