R with OpenACC on new WSL Ubuntu

Hi everyone:

I have started using the WSL Ubuntu on a Windows Machine. I can get regular FORTRAN with OpenACC, MPI, and CUDA Fortran to compile just fine.

But I’m having trouble interfacing OpenACC Fortran with R.

I have a very simple subroutine:

subroutine Rtest5(x,y,n)                                                                                                  integer n,i                                                                                                             real x(n),y(n)                                                                                                                                                                                                                                                                                                                                                          !$acc kernels                                                                                                           do i=1,n                                                                                                                   y(i) = 2.0*i + x(i)                                                                                                  enddo                                                                                                                   !$acc end kernels                                                                                                                                                                                                                             end subroutine Rtest5 

And here is the Makefile
CUDA_FFLAGS=-acc -Minfo=accel -Mlarge_arrays -L/opt/pgi/linux86-64/19.10/bin/pgfortran -L/opt/pgi/linux86-64/19.10/bin/\pgcc -lblas -llapack DLLCUDA_FFLAGS=-ta=tesla:nordc -L/opt/pgi/linux86-64/19.10/lib/acc_inint_link_cuda.o -L/opt/pgi/linux86-64/19.10/lib/\libaccapi.so -L/opt/pgi/linux86-64/19.10/lib/libaccg.so -L/opt/pgi/linux86-64/19.10/lib/libaccn.so -L/opt/pgi/\linux86-64/19.10/lib/libaccg2.so -L/opt/pgi/linux86-64/19.10/lib/libcudadevice.so -L/opt/pgi/linux86-64/19.10/lib/li\bnspgc.a -L/opt/pgi/linux86-64/19.10/bin/pgfortran -L/opt/pgi/linux86-64/19.10/bin/pgcc -lcudafor #mympi.so: mympi.f90 # mpif90 -fPIC -pgf90libs -c mympi.f90 mympi.o -m64 Rtest5.so: Rtest5.f90 pgfortran -Mcuda=cuda10.1 $(CUDA_FFLAGS) -fPIC -c Rtest5.f90 -o Rtest5.o -m64 pgfortran -Mcuda=cuda10.1 $(CUDA_FFLAGS) -shared -o Rtest5.so Rtest5.o -m64

It compiles fine, but when I try to run it in R, I get the message
libgomp: TODO

Any help much appreciated

Thanks,
Erin

Hi, I have been able to compile a R package with openacc and WSL (Ubuntu) on Windows without the error “libgomp: TODO”. To remove the error, I had to recompile R by desabling openmp. I used the following code to recompile R and disable openmp:

sudo apt update
sudo apt install -y \
build-essential gfortran \
libreadline-dev libbz2-dev liblzma-dev zlib1g-dev \
libpcre2-dev libcurl4-openssl-dev libx11-dev \
libxt-dev xorg-dev libjpeg-dev libcairo2-dev \
libtiff5-dev libicu-dev libblas-dev liblapack-dev \
texinfo

Then, I used

cd ~/downloads
wget https://cran.r-project.org/src/base/R-4/R-4.3.3.tar.gz
tar xf R-4.3.3.tar.gz
cd R-4.3.3

Then I used

mkdir -p ~/local/R-4.3.3-noomp

./configure \
–prefix=$HOME/local/R-4.3.3-noomp \
–enable-R-shlib \
–disable-openmp \
CC=gcc \
CXX=g++ \
FC=gfortran \
CFLAGS=“-O2 -fPIC” \
CXXFLAGS=“-O2 -fPIC” \
FFLAGS=“-O2 -fPIC” \
FCFLAGS=“-O2 -fPIC” \
LDFLAGS=“-Wl,-Bsymbolic-functions -Wl,-z,relro” \
SHLIB_LDFLAGS=“-shared” \
SHLIB_OPENMP_CFLAGS= \
SHLIB_OPENMP_CXXFLAGS= \
SHLIB_OPENMP_FFLAGS=

Then, I used

make -j"$(nproc)"
make install

Then, I used

export PATH=$HOME/local/R-4.3.3-noomp/bin:$PATH
which R
R --version

The content of the Makevars file of the R package is

PKG_CXXFLAGS = -acc -gpu=ccall
PKG_LIBS = -acc
LDFLAGS := $(filter-out -flto=auto -ffat-lto-objects,$(LDFLAGS))

The content of the R Makevars at ~/.R/Makevars is

NVHPC=/opt/nvidia/hpc_sdk/Linux_x86_64/24.3

CC=$(NVHPC)/compilers/bin/nvc
CXX=$(NVHPC)/compilers/bin/nvc++
CXX11=$(NVHPC)/compilers/bin/nvc++
CXX14=$(NVHPC)/compilers/bin/nvc++
CXX17=$(NVHPC)/compilers/bin/nvc++

CXX11STD=
CXX14STD=
CXX17STD=

SHLIB_CXXLD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX11LD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX14LD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX17LD=$(NVHPC)/compilers/bin/nvc++

CFLAGS=-fPIC
CXXFLAGS=-fPIC
CXX11FLAGS=-fPIC
CXX14FLAGS=-fPIC
CXX17FLAGS=-fPIC

LTO=
LTO_LD=
LDFLAGS := $(filter-out -flto=auto -ffat-lto-objects,$(LDFLAGS))

With this, I have been able to compile the R package and to run code on the GPU. Here is the result of the compilation.

manuh@EH:~/documents/Test_R$ R CMD INSTALL openaccpkg --preclean

  • installing to library ‘/home/manuh/R/x86_64-pc-linux-gnu-library/4.3’
  • installing source package ‘openaccpkg’ …
    ** using staged installation
    ** libs
    using C compiler: ‘’
    using C++ compiler: ‘’
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc -I"/home/manuh/local/R-4.3.3-noomp/lib/R/include" -DNDEBUG -I/usr/local/include -fpic -fPIC -c init.c -o init.o
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc++ -I"/home/manuh/local/R-4.3.3-noomp/lib/R/include" -DNDEBUG -I/usr/local/include -acc -gpu=ccall -fpic -fPIC -c openacc_saxpy.cpp -o openacc_saxpy.o
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc++ -shared -L/home/manuh/local/R-4.3.3-noomp/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o openaccpkg.so init.o openacc_saxpy.o -acc -L/home/manuh/local/R-4.3.3-noomp/lib/R/lib -lR
    /usr/bin/ld: warning: /tmp/pgcudafaticvlyxD4RgyF.o: missing .note.GNU-stack section implies executable stack
    /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
    installing to /home/manuh/R/x86_64-pc-linux-gnu-library/4.3/00LOCK-openaccpkg/00new/openaccpkg/libs
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    No man pages found in package ‘openaccpkg’
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** checking absolute paths in shared objects and dynamic libraries
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (openaccpkg)

Afterwards, I have been able to run the following code :

library(openaccpkg)
n ← 1e6
x ← runif(n)
y ← runif(n)
z ← saxpy_acc(2.0, x, y)

without any “libgomp: TODO” error. The content of the variable z is

z[1 : 10]
[1] 2.1952300 0.5955944 0.8378743 1.1300756 2.3213746 1.6174173 1.9615502
[8] 1.3232210 0.7651233 1.1560568

If I do not disable openmp, I also get the “libgomp: TODO” error.

related: Problem with NVFORTRAN and R

It works with Fortran as well. Here is an example :

manuh@EH:~$ cd ./documents/Test_R
manuh@EH:~/documents/Test_R$ rsync -av /mnt/d/WSL/Test_R/ ~/documents/Test_R/
sending incremental file list
openaccpkg/src/

sent 1,689 bytes received 30 bytes 3,438.00 bytes/sec
total size is 24,004 speedup is 13.96
manuh@EH:~/documents/Test_R$ export PATH=$HOME/local/R-4.3.3-noomp/bin:$PATH
which R
R --version
R CMD INSTALL openaccpkg --preclean
/home/manuh/local/R-4.3.3-noomp/bin/R
R version 4.3.3 (2024-02-29) – “Angel Food Cake”
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
Licenses - GNU Project - Free Software Foundation .

  • installing to library ‘/home/manuh/R/x86_64-pc-linux-gnu-library/4.3’
  • installing source package ‘openaccpkg’ …
    ** using staged installation
    ** libs
    using C compiler: ‘’
    using Fortran compiler: ‘’
    using C++ compiler: ‘’
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc -I"/home/manuh/local/R-4.3.3-noomp/lib/R/include" -DNDEBUG -I/usr/local/include -fpic -fPIC -c init.c -o init.o
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc++ -I"/home/manuh/local/R-4.3.3-noomp/lib/R/include" -DNDEBUG -I/usr/local/include -acc -gpu=ccall -fpic -fPIC -c openacc_saxpy.cpp -o openacc_saxpy.o
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvfortran -fpic -fPIC -acc -gpu=ccall -c saxpy_acc_f.f90 -o saxpy_acc_f.o
    /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/compilers/bin/nvc++ -shared -L/home/manuh/local/R-4.3.3-noomp/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o openaccpkg.so init.o openacc_saxpy.o saxpy_acc_f.o -acc -lgfortran -lm -lquadmath -L/home/manuh/local/R-4.3.3-noomp/lib/R/lib -lR
    /usr/bin/ld: warning: /tmp/pgcudafatObyb46rDlW1f.o: missing .note.GNU-stack section implies executable stack
    /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
    installing to /home/manuh/R/x86_64-pc-linux-gnu-library/4.3/00LOCK-openaccpkg/00new/openaccpkg/libs
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    No man pages found in package ‘openaccpkg’
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** checking absolute paths in shared objects and dynamic libraries
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (openaccpkg)
    manuh@EH:~/documents/Test_R$ R

R version 4.3.3 (2024-02-29) – “Angel Food Cake”
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type ‘license()’ or ‘licence()’ for distribution details.

R is a collaborative project with many contributors.
Type ‘contributors()’ for more information and
‘citation()’ on how to cite R or R packages in publications.

Type ‘demo()’ for some demos, ‘help()’ for on-line help, or
‘help.start()’ for an HTML browser interface to help.
Type ‘q()’ to quit R.

library(openaccpkg)
n ← 1e6
x ← runif(n)
y ← runif(n)
z ← saxpy_acc_f(2.0, x, y)
z[1 : 10]
[1] 1.5810686 2.3405559 1.6307768 0.4992863 0.7700693 1.8116058 1.5312915
[8] 1.45167

I used the following Makervars file

cat > ~/.R/Makevars <<‘EOF’
NVHPC=/opt/nvidia/hpc_sdk/Linux_x86_64/24.3
CC=$(NVHPC)/compilers/bin/nvc
CXX=$(NVHPC)/compilers/bin/nvc++
CXX11=$(NVHPC)/compilers/bin/nvc++
CXX14=$(NVHPC)/compilers/bin/nvc++
CXX17=$(NVHPC)/compilers/bin/nvc++
FC=$(NVHPC)/compilers/bin/nvfortran
F77=$(NVHPC)/compilers/bin/nvfortran
CXX11STD=
CXX14STD=
CXX17STD=
SHLIB_CXXLD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX11LD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX14LD=$(NVHPC)/compilers/bin/nvc++
SHLIB_CXX17LD=$(NVHPC)/compilers/bin/nvc++
CFLAGS=-fPIC
CXXFLAGS=-fPIC
CXX11FLAGS=-fPIC
CXX14FLAGS=-fPIC
CXX17FLAGS=-fPIC
FFLAGS=-fPIC -acc -gpu=ccall
FCFLAGS=-fPIC -acc -gpu=ccall
LTO=
LTO_LD=
LDFLAGS := $(filter-out -flto=auto -ffat-lto-objects,$(LDFLAGS))
EOF