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

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
检测Fortran中是否使用了MPI编译器_Fortran_Mpi_Preprocessor - Fatal编程技术网

检测Fortran中是否使用了MPI编译器

检测Fortran中是否使用了MPI编译器,fortran,mpi,preprocessor,Fortran,Mpi,Preprocessor,我想写一个Fortran代码,如果它是由mpif90编译的,那么它可以使用MPI,但是如果它是用gfortran编译的,那么它也可以运行(仅限于不使用MPI库)。 所以我想使用一个预处理条件,但是在互联网上我没有发现任何关于MPI定义的预处理变量的信息 例如,我想编译这个简单的代码test.f90: Program Main #ifdef __MPI USE MPI #endif implicite none integer Ierror #ifdef __MPI

我想写一个Fortran代码,如果它是由
mpif90
编译的,那么它可以使用MPI,但是如果它是用
gfortran
编译的,那么它也可以运行(仅限于不使用MPI库)。 所以我想使用一个预处理条件,但是在互联网上我没有发现任何关于MPI定义的预处理变量的信息

例如,我想编译这个简单的代码
test.f90

Program Main
#ifdef __MPI
    USE MPI
#endif
    implicite none
    integer Ierror

#ifdef __MPI
    call MPI_INTI(Ierror)
    write (*,*) 'MPI detected'
#else
    write (*,*) 'MPI not detected'
#endif

End 
然后,如果我用
mpif90
编译前面的非工作示例,我应该

$ mpif90 -cpp -o prog test.f90 && prog
> MPI detected
而如果我使用
gfortran
编译,我应该

$ gfortran -cpp -o prog test.f90 && prog
> MPI not detected

那么,有没有一种预处理条件(或其他方式)可以使此类示例正常工作?

您是否要求
mpif90
自动为您插入
-D\u MPI
?与
mpif90-cpp-D\u MPI-o prog test.f90
中一样,您可能必须重命名为
test.f90
,以便对其进行预处理。这实际上是一个副本,但请仔细阅读注释-基本上结论是不可能的。@IanBush感谢链接。然而,我认为MattShin的解决方案可能是可行的,或者我错了?@MattShin这正是我正在采取的方法。例如,在中,您是否要求
mpif90
为您自动插入
-D\u MPI
?与
mpif90-cpp-D\u MPI-o prog test.f90
中一样,您可能必须重命名为
test.f90
,以便对其进行预处理。这实际上是一个副本,但请仔细阅读注释-基本上结论是不可能的。@IanBush感谢链接。然而,我认为MattShin的解决方案可能是可行的,或者我错了?@MattShin这正是我正在采取的方法。例如在