Rmpi unable to load shared libraries as non root user

好久不见. 提交于 2019-12-05 02:57:12

The problem here is that OpenMPI, by default, does not register its libraries directory with the system linker. This is why some installation guides recommend you put its directories in your LD_LIBRARY_PATH variable, so that the libraries can be found at runtime. However, "adding the directories to LD_LIBRARY_PATH" must be done every time a new shell is loaded, which is why these guides suggest putting it in ~/.bashrc or the like, so that the setting is restored on every login.

However, the ~/.bashrc file (or ~/.profile, or any such) is a user-specific setting. Assuming one is logged in as root when installing openmpi, and Rmpi, and the like, which seems likely, that means that adding to these user-specific files will only set the library paths when running as root, and not as your usual runtime user.

The fix, in general, is to tell the linker where these files can be found. On my own system, which is running CentOS 7, OpenMPI 1.10.0 (using the Scientific Linux RPMs), R 3.2.3, and Rmpi 0.6-5, this is what happens when I fail to set the library path:

[dchurch@workstation ~]$ R -q -e "library('Rmpi')"
> library('Rmpi')
Error : .onLoad failed in loadNamespace() for 'Rmpi', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/lib64/R/library/Rmpi/libs/Rmpi.so':
  libmpi.so.12: cannot open shared object file: No such file or directory
Error: package or namespace load failed for ‘Rmpi’
Execution halted        

If I temporarily set the linker path with a temporary variable, it works for this invocation:

[dchurch@workstation ~]$ LD_LIBRARY_PATH=/usr/lib64/openmpi/lib R -q -e "library('Rmpi')"
> library('Rmpi')       
>
>

However, to make this change permanent, the best way to do it is to register the openmpi libraries directory with the system linker itself, by creating a new file in /etc/ld.so.conf.d and running ldconfig, as so:

[dchurch@workstation ~]$ sudo sh -c 'echo /usr/lib64/openmpi/lib > /etc/ld.so.conf.d/openmpi.conf; ldconfig'
[dchurch@workstation ~]$ R -q -e "library('Rmpi')"
> library('Rmpi')
>
>

Once you have done that, Rmpi should be able to be loaded for any user, regardless of environment variables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!