告诉Rstudio使用mpif90而不是gfortran

时间:2015-08-10 16:18:40

标签: r rstudio r-package

为了学习如何创建使用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.

1 个答案:

答案 0 :(得分:1)

您只需在FC文件中设置Makevars标志即可指示您希望使用的fortran编译器。

FC=mpif90

编辑 - 如果包含在您的软件包

中,则上述操作无效

在包FC中指定时,Makevars宏将被覆盖,因为在src/Makevars之前读取$RHOME/etc/Makeconf文件会覆盖FC宏。要更改默认编译器,请在.R/目录的$HOME目录中创建Makevars文件。

然后使用与上面相同的行创建文件。重新启动R并尝试再次编译(这在我的Ubuntu系统上运行)。