所以我尝试使用 NAS 基准测试特定 MPI 实现的性能。所以我去编译 Fortran 代码,但遇到了障碍。每当我输入此命令进行编译时:
gfortran -O0 -Wall -I/home/stephen/trunk/include -I. -c ./TestData/common/timers.f
我得到这些编译器错误:
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
这是错误的 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
有什么想法吗?我已经为 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
(我通过 mpif90 -showme
获得了这些信息——我不知道该命令行选项是否是 MPI 标准的一部分,所以它可能不适合你)。
为了编译你的代码,我会尝试这样的事情:
mpif77 -O0 -Wall -c ./TestData/common/timers.f -o timers.o
因为没有其他文件要包含,所以使用额外的 -I
标志来增加编译器包含路径并没有什么意义——你只是增加了你不小心发生的可能性找到错误的头文件;)。
也许在您的当前目录或/home/stephen/trunk/include 中有一个文件“mpif.h”,它在不应该被选中时被选中了。 (看起来您可能会看到 C 头文件,因为 /*
是 C 注释的开头——尽管我不明白为什么 C 头文件会被称为“mpif.h”)。
关于compilation - gfortran:非法预处理器指令和无效字符/非数字字符编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002602/