为了学习如何创建使用Fortran的R包,我创建了a simple one to calculate Pi with a monte carlo simulation。现在我试图使Fortran代码与MPI并行。
当我将use MPI
添加到我的fortran代码并单击Rstudio上的Build and Reload
按钮时,我收到以下错误。
==> R CMD INSTALL --no-multiarch --with-keep.source MyPi
* installing to library ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2’
* installing *source* package ‘MyPi’ ...
gfortran -fpic -g -O2 -fstack-protector-strong -c Fpi.f90 -o Fpi.o
/usr/lib/R/etc/Makeconf:161: recipe for target 'Fpi.o' failed
** libs
Fpi.f90:2.4:
use mpi
1
Fatal Error: Can't open module file 'mpi.mod' for reading at (1): No such file or directory
make: *** [Fpi.o] Error 1
ERROR: compilation failed for package ‘MyPi’
* removing ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2/MyPi’
* restoring previous ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2/MyPi’
Exited with status 1.
我认为问题在于Rstudio正在尝试使用gfortran而不是mpi90进行编译。我能够按照this post做一个非常基本的hello世界,但是你用mpif90 -fpic -shared -o test.so test.f90
编译代码
如何告诉Rstudio使用mpif90 -fpic -shared
代替gfortran
?
我将此添加到src/Makevars
FC=mpif90
这就是我得到的:
==> R CMD INSTALL --no-multiarch --with-keep.source MyPi
* installing to library ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2’
* installing *source* package ‘MyPi’ ...
gfortran -fpic -g -O2 -fstack-protector-strong -c Fpi.f90 -o Fpi.o
/usr/lib/R/etc/Makeconf:161: recipe for target 'Fpi.o' failed
** libs
Fpi.f90:2.4:
USE MPI
1
Fatal Error: Can't open module file 'mpi.mod' for reading at (1): No such file or directory
make: *** [Fpi.o] Error 1
ERROR: compilation failed for package ‘MyPi’
* removing ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2/MyPi’
* restoring previous ‘/home/ignacio/R/x86_64-pc-linux-gnu-library/3.2/MyPi’
Exited with status 1.
答案 0 :(得分:1)
您只需在FC
文件中设置Makevars
标志即可指示您希望使用的fortran编译器。
FC=mpif90
编辑 - 如果包含在您的软件包
中,则上述操作无效在包FC
中指定时,Makevars
宏将被覆盖,因为在src/Makevars
之前读取$RHOME/etc/Makeconf
文件会覆盖FC
宏。要更改默认编译器,请在.R/
目录的$HOME
目录中创建Makevars文件。
然后使用与上面相同的行创建文件。重新启动R并尝试再次编译(这在我的Ubuntu系统上运行)。