Ste*_*der 3 preprocessor fortran compilation directive gfortran
因此,我尝试使用 NAS 基准测试对特定 MPI 实现进行性能测试。所以我去编译 Fortran 代码,但遇到了障碍。每当我输入此命令进行编译时:
gfortran -O0 -Wall -I/home/stephen/trunk/include -I. -c ./TestData/common/timers.f
Run Code Online (Sandbox Code Playgroud)
我收到这些编译器错误:
Warning: mpif.h:2: Illegal pdreprocessor directive
Warning: mpif.h:3: Illegal preprocessor directive
Warning: mpif.h:4: Illegal preprocessor directive
Warning: mpif.h:5: Illegal preprocessor directive
Warning: mpif.h:6: Illegal preprocessor directive
Warning: mpif.h:7: Illegal preprocessor directive
Warning: mpif.h:8: Illegal preprocessor directive
Warning: mpif.h:9: Illegal preprocessor directive
Warning: mpif.h:12: Illegal preprocessor directive
Warning: mpif.h:13: Illegal preprocessor directive
Warning: mpif.h:14: Illegal preprocessor directive
Warning: mpif.h:2: Illegal preprocessor directive
Warning: mpif.h:3: Illegal preprocessor directive
Warning: mpif.h:4: Illegal preprocessor directive
Warning: mpif.h:5: Illegal preprocessor directive
Warning: mpif.h:6: Illegal preprocessor directive
Warning: mpif.h:7: Illegal preprocessor directive
Warning: mpif.h:8: Illegal preprocessor directive
Warning: mpif.h:9: Illegal preprocessor directive
Warning: mpif.h:12: Illegal preprocessor directive
Warning: mpif.h:13: Illegal preprocessor directive
Warning: mpif.h:14: Illegal preprocessor directive
mpif.h:1.1:
Included at ./TestData/common/timers.f:30:
/*
1
Error: Non-numeric character in statement label at (1)
mpif.h:1.2:
Included at ./TestData/common/timers.f:30:
/*
1
Error: Invalid character in name at (1)
mpif.h:1.1:
Included at ./TestData/common/timers.f:50:
/*
1
Error: Non-numeric character in statement label at (1)
mpif.h:1.2:
Included at ./TestData/common/timers.f:50:
/*
1
Error: Invalid character in name at (1)
make: *** [cg] Error 1
Run Code Online (Sandbox Code Playgroud)
这是出错的timers.f代码(第30行和第50行是包含行):
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine timer_start(n)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
implicit none
integer n
include 'mpif.h'
double precision start(64), elapsed(64)
common /tt/ start, elapsed
start(n) = MPI_Wtime()
return
end
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine timer_stop(n)
c---------------------------------------------------------------------
c---------------------------------------------------------------------
implicit none
integer n
include 'mpif.h'
double precision start(64), elapsed(64)
common /tt/ start, elapsed
double precision t, now
now = MPI_Wtime()
t = now - start(n)
elapsed(n) = elapsed(n) + t
return
end
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我已经尝试了 gfortran 的各种命令行参数,试图让它进行不同类型的预处理(我承认,其中大多数都是盲目完成的)。对我来说奇怪的是,编译器在非数字字符 /* 上出错,这些字符在我的代码中不存在,所以我很迷失。
谢谢!
您肯定是在以非标准方式编译此代码。使用 mpi 编译 f77 或 f90 代码的常用方法是使用程序mpif77或mpif90,它们包装用于构建特定版本的 MPI 的编译器。
例如,在我的笔记本电脑上(使用使用 gfortran/gcc 编译的 OpenMPI),该命令mpif77
大致相当于:
gfortran -I/usr/local/include -L/usr/local/lib -lmpi_f77 -lmpi -lopen-rte -lopen-pal -lutil
Run Code Online (Sandbox Code Playgroud)
(我通过以下方式获得此信息mpif90 -showme
- 我不知道该命令行选项是否是 MPI 标准的一部分,因此它可能不适合您)。
要编译你的代码,我会尝试这样的事情:
mpif77 -O0 -Wall -c ./TestData/common/timers.f -o timers.o
Run Code Online (Sandbox Code Playgroud)
由于没有其他文件要包含,因此使用附加-I
标志增加编译器包含路径并没有真正意义 - 您只是增加了意外找到错误头文件的可能性;)。
也许您的当前目录或 /home/stephen/trunk/include 中有一个文件“mpif.h”,但它在不应该被选中的情况下被选中了。(看起来您可能会看到一个 C 头文件,因为它/*
是 C 注释的开始——尽管我不明白为什么 ac 头文件被称为“mpif.h”)。