compiling glmnet failed in windows - r

Since the R package glmnet doesn't provide binary for windows, so I have to compile it under my OS win7 64bit. How ever I got this error message:
gfortran -m64 -fdefault-real-8 -ffixed-form -O2 -mtune=core2 -c newGLMnet.f90
-o newGLMnet.o
f951.exe: sorry, unimplemented: 64-bit mode not compiled in
make: *** [newGLMnet.o] Error 1
ERROR: compilation failed for package 'glmnet'
I also tried to compile it under windows XP 32bit, but with 'configuration failed for package glmnet' error message.
Has anyone succeed compiling glmnet in Windows?

Trevor Hastie posted this on r-help 12 hours ago:
"We are aware that glmnet_1.7.3 does not pass for windows
and are looking into the problem. It has something to do
with the gcc compiler being slightly different on
windows versus linux/mac platforms. As soon as we have
resolved the issue, we will post a new version to CRAN"

On 64bit Windows, instead of the default PATH :
C:\Rtools\MinGW\bin
try :
C:\Rtools\gcc-4.6.3\bin
Then of course, stop and start a new DOS window to pick up the new PATH.
Also see: https://stackoverflow.com/a/15221883/403310

Related

Rcpp fails to compile c++ code after series of updates

I'd like to keep my OS, R, and R packages up to date. I unknowingly treaded into deep water by upgrading to OSX 10.15.6 and upgrading to R 4.0.2. Currently, Rcpp is failing to compile c++ code, which I believe is causing the CRAN installation for certain packages to fail (e.g. glmmTMB), and is also causing installations from source to fail. I'll describe what I've done and hopefully someone can elucidate a solution.
In a rough order, here's what I've done:
Installed OSX 10.15.6
I don't remember the date but it was fairly recent. I don't know how closely this is related to the problem, I was having issues installing other R packages (e.g. rstan) that needed Rcpp prior to this.
Ran into an issue trying to run some old glmmTMB models
The exact error was identical to this issue. I followed the various solutions on that thread to no avail. Perhaps the most frustrating was when attempting to install from source, which then failed to compile some c++.
This wasn't the first time I had seen similar errors. Something similar happened when I tried installing rstan, so I asked for some help on their repo under a similar issue. Nothing helped.
This was on R 3.6, so I thought maybe it'd be worth updating R and glmmTMB. Before doing this I wanted to install Xcode, as opposed to just the Command Line Developer Tools, in hopes that the installation would ensure I'd have everything clang- and c++ compiler-related squared away.
Installed Xcode to help set a baseline c++ environment
Relatively painless, am able to build and compile fairly simple c++ projects.
Installed R 4.0.2
From the r-project site, I installed R-4.0.2.pkg without issues and with the default install settings. According to the R project Tools site, I was reassured in installing Xcode and continued on to install the GNU Fortran 8.2 installer.
Followed #coatless's guide to installing Rcpp
Discovered this guide and followed each step, except for those related to xcode-select.
Testing Rcpp and RcppArmadillo from the guide
One of the last steps is to test the installation with a simple helloworld.cpp test. This fails with this error (abridged for clarity):
> Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp")
In file included from helloworld.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [helloworld.o] Error 1
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include" -I"/Users/alex/Documents/BergenLab/nlp_cancer_metaphor" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c helloworld.cpp -o helloworld.o
Error in Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp") :
Error 1 occurred building shared library.
Tried to debug Rcpp to no avail
Found some somewhat related reports, such as Packages cannot build from source due to math.h not found, Rcpp doesn't under macOS, math.h not found, Source Cpp file failed due to math.h not found, and Cannot compile R packages with c++ code after updating to macOS Catalina.
None of the solutions in these answers have helped at all. The only solution which gave me feedback was using installer to install macOS_SDK_headers_for_macOS_10.14.pkg which subsequently gave me installer: Error - the package path specified was invalid (not sure how what the implications of this are).
Installing glmmTMB from source fails
One of the solutions from an above glmmTMB issue recommends installing from source. Here is the error on my attempt:
* installing *source* package ‘glmmTMB’ ...
** package ‘glmmTMB’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c glmmTMB.cpp -o glmmTMB.o
In file included from glmmTMB.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:53:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:96:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:245:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
make: *** [glmmTMB.o] Error 1
ERROR: compilation failed for package ‘glmmTMB’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
Warning in install.packages :
installation of package ‘glmmTMB’ had non-zero exit status
Overall, I'm still unable to run my glmmTMB models (and I presume unable to build rstan as well). Something with my c++ compiler must be off but I'm a c++ beginner and am unsure how to interpret the errors I'm getting. Something's wrong with the header files, but it seems perhaps like it's not due to math.h being missing (like most other posts). It should go without saying but any help would be greatly appreciated!
Edit 1
I've tried to narrow down the error and thus followed each step from #coatless's guide, exactly as listed there and according to the R installation documentation. My exact steps:
Removed gfortran 8.2. Removed ~/.Renviron and ~/.R/Makevars. Unlinked both of these files from Rstudio with unlink().
Ran xcode-select --install, which returned with "use "Software Update" to install updates." Accordingly, softwareupdate --list estimated that nothing needed updating. Regardless, I uninstalled Command Line Tools with sudo rm -rf /Library/Developer/CommandLineTools and installed the Command Line Tools with xcode-select —install. Up to this point everything is working as expected. Small c++ programs are being compiled without issue by both gcc and clang++.
According to the R manual, from https://mac.r-project.org/libs-4/, I installed pcre2-10.34-darwin.17-x86_64.tar.gz, xz-5.2.4-darwin.17-x86_64.tar.gz , and readline-5.2.14-darwin.17-x86_64.tar.gz to /usr/local. No big issues here, although I'm not really sure how to verify that these work as expected.
Restarted an R session in RStudio.
Installed Rcpp and RcppArmadillo with install.packages(c(‘Rcpp’, ‘RcppArmadillo’))
Created a ~/helloworld.cpp with the code from Slide 15 mentioned in the comments.
Running Rcpp::sourceCpp("~/helloworld.cpp") fails with the exact error as mentioned in the body of the post. Similarly evalCpp() fails with a similar error.
After a bit of digging, the issue turned out to be neither glmmTMB, Rcpp, or really anything high-level. From what I understand: When R uses Rcpp to compile c++ code, a certain set of arguments are passed to the system c++ compiler. In my case this compiler was clang++ since I had just installed Xcode. The c++ compiler relies on a set of c++ header files to be included in exactly the right order. Seemed like the order of mine were incorrect, thus causing a slew of errors regarding "missing template definitions."
I looked into changing the order of the includes but couldn't find any straightforward solution. I knew that Rcpp was calling a very specific array of arguments to clang++, so I looked into how that might elucidate an answer. I looked into the manuals for clang++ to figure out what -isysroot and -I meant and felt like they might play a part in reconfiguring how the system header files were being compiled. From one of the threads below I discovered the $(R RHOME)/etc/Makeconf Makefile and proceeded to change the directory of the OSX SDK from what I believe was the Command Line Tools path to the Xcode path. This seemed to solve the issue.
Some threads I used to find this solution: Cannot compile R packages with c++ code after updating to macOS Catalina and Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace.
What worked for me:
Note the current header file search
From clang++ -Wp,-v -E -:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
Note the OSX SDK path
From xcrun --show-sdk-path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
Modify the R configuration
With vim $(R RHOME)/etc/Makeconf, changed the CPPFLAGS flag to:
CPPFLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include
Notice how this SDK directory is what was found in step 2. This apparently cleans up the location and order of the SDK header file includes.
Reinstall glmmTMB from source
I was still seeing a FreeADFunObject error when trying to fit a glmmTMB model, so I went back to this GH thread and followed the first suggestion: to reinstall from source. This wasn't working before since I needed a properly set up c++ configuration, which I fixed in the last two steps.
Hence, install.packages("glmmTMB", type="source") installed without issue and I can now build and fit glmmTMB models.
For posterity's sake:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base

Can't get R to recognize installed libgfortran when installing packages

I'm trying to install packages in R that depend on libgfortran, but I keep getting this error:
dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc/7/libgfortran.4.dylib
Referenced from: /usr/local/Cellar/r/3.4.3_1/lib/libR.dylib
Reason: image not found
I have gfortran installed through homebrew gcc:
❯❯ readlink `which gfortran`
../Cellar/gcc/8.2.0/bin/gfortran
There's a libgfortran available at /usr/local/opt/gcc/lib/gcc/8/libgfortran.5.dylib, but this is not the one R is looking for. How do I convince R to look for gcc 8 instead of gcc 7?
"How do I convince R to look for gcc 8 instead of gcc 7?"
You should not do that! Those libraries are NOT compatible, that's why soname is changed. The ABI is different. You need the correct version of GCC which was used to compile your R package. See very similar (but Linux) questions and answers like R v3.4.0-2 unable to find libgfortran.so.3 on Arch How to install libgfortran.so.4 on ubuntu 16.06
You really need the compatible library or update your R to a version that uses GCC 8.

Compiling R 3.1.1 using Intel MKL: --enable-R-shlib triggers undefined reference to symbol error

Problem
I need to compile R 3.1.1 with shared library (--enable-R-shlib) with ICC/MKL (Composer XE 2013 SP 1.3.174) in order to use a specific IDE (rstudio) and I am running into trouble.
Context
Some information about my platform:
OS: Ubuntu 14.04.1 LTS
Kernel: 3.13.0-30
Compiler: Intel ICC (Composer XE 2013 SP 1.3.174)
MKL: Intel MKL (Composer XE 2013 SP 1.3.174)
I previously had a working installation of R 3.1.1 (without shared library) compiled with ICC/MKL (Composer XE 2013 SP 1.3.174) as follows:
$source /opt/intel/composerxe/bin/compilervars.sh intel64
$export CC="icc"
$export CXX="icpc"
$export AR="xiar"
$export LD="xild"
$export CFLAGS="-O3 -ipo -openmp -xHost -multiple-processes"
$export CXXFLAGS="-O3 -ipo -openmp -xHost -multiple-processes"
$export MKL="-lmkl_gf_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread"
$./configure --with-lapack --with-blas="$MKL" --build="x86_64-linux-gnu" --host="x86_64-linux-gnu" > log_cfg
$make > log_make_out 2> log_make_err
#make install
When I run the commands above the compilation is successful and log_make_err is empty at the end of the process.
As I said in the beginning, I now need to compile R with shared library (--enable-R-shlib). Therefore, I tried to use the exact same commands as before (same computer) and changed the configure line to:
$./configure --with-lapack --with-blas="$MKL" --build="x86_64-linux-gnu" --host="x86_64-linux-gnu" --enable-R-shlib
This gives the following output:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: icc -std=gnu99 -O3 -ipo -openmp -xHost -multiple-processes
Fortran 77 compiler: gfortran -g -O2
C++ compiler: icpc -O3 -ipo -openmp -xHost -multiple-processes
C++ 11 compiler: icpc -std=c++11 -O3 -ipo -openmp -xHost -multiple-processes
Fortran 90/95 compiler: x86_64-linux-gnu-gfortran -g -O2
Obj-C compiler: x86_64-linux-gnu-gcc
Interfaces supported: X11, tcltk
External libraries: readline, BLAS(generic), LAPACK(in blas), lzma
Additional capabilities: PNG, JPEG, TIFF, NLS, cairo
Options enabled: shared R library, R profiling
Recommended packages: yes
In this case, the compilation is not successful and log_make_err contains the following:
ld: /tmp/ipo_iccUpPSPh.o: undefined reference to symbol '__kmpc_end##VERSION'
/opt/intel/composer_xe_2013_sp1.3.174/compiler/lib/intel64/libiomp5.so: error adding symbols: DSO missing from command line
make[3]: *** [R.bin] Error 1
make[2]: *** [R] Error 2
make[1]: *** [R] Error 1
make: *** [R] Error 1
When I run diff on the output of the configure script for each case, nothing strange shows up:
753c753
< Options enabled: R profiling
---
> Options enabled: shared R library, R profiling
I tried to include the full output of the make command but it exceeds the maximum number of characters allowed and using pastebin is not a good practice at SO.
Let me know if you feel like there is information missing that could help you lead me in the right direction.
Thanks!
I've been compiling R against MKL, and its a challenge. I haven't been doing it on ubuntu, but from your configuration four things leap out at me:
Using icc to compile against mkl, you usually have to source a shell script in one of the mkl directories to set a bunch of environment variables to the correct dynamic library search paths. I don't see that you're doing this?
You can make your life a lot easier by linking against libmkl_rt.
My configure line (which is for gcc) uses
--with-blas="mkl_rt" --with-lapack BLAS_LIBS="-lmkl_rt -liomp5 -lpthread"
You're trying to enable openmp with compiler directives without sending --enable-openmp to configure.
You're mixing icc with gfortran, and not setting a link directive or library list for gfortran. MKL may not link against gfortran unless its recompiled -- some of Intel's documentation says recompilation is necessary; I can't get a straight answer from them. gfortran with your directives doesn't seem to know that you want it to be multi-threaded, and it may not know how to find libraries.
Adding the following to the script solved it for me:
export MAIN_LDFLAGS='-openmp'
Everything else stayed the same.
Hopefully this will be useful to someone else.

Using R's GPU packages on Amazon

I spent almost a whole day trying to get this running and finally decided to come to SO because there are going to be people here who have tried this =)
I would like to get an Amazon-EC2 GPU machine running with rpud (or another R GPU package), either a cg1.4xlarge or g2.2xlarge as those are the only two GPU machines Amazon(AWS) has.
This post How to run a GPU instance using Amazon EC2 Panel? helped me realize that I couldn't just change my rstudio-server machine to a gpu machine as I was using an incorrect AMI.
Started out with this AMI from Amazon CentOS 6 (x86_64) - with Updates
So I decided I had to build my own and started following the directions here http://www.r-tutor.com/gpu-computing/rpud-installation. As well as http://www.louisaslett.com/Talks/GPU_Programming_Basics_Getting_Started/Handout.pdf (Louis Aslett is the same guy who has an amazing demo of using rstudio-server on an ec2 (http://www.louisaslett.com/RStudio_AMI/).
Both of those end up leading you to here: http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html#package-manager-installation, so you can get the CUDA toolkit (which seems to be a necessity for GPU computing). Some of the AWS machines already have a Cuda toolkit installed, however I figured I would follow the directions on my first try (even though they are installed, sometimes the versioning of stuff hasn't been the same as some of the tutorials I've found). So I follow those directions to a T and I end up getting a few errors like nvidia-settings-319.37-30.fc18.x86_64 (cuda) Requires: libgdk-x11-2.0.so.0()(64bit) when I try to run the examples with $ cuda-install-samples-5.5.sh <dir>. So I download all of those required packages. I try again and end up with rpud errors (will detail those later).
This machine is Ubuntu-12.04
So of course I think, someone must have already built an AMI for this and find someone who did it with python. I might just end up using python anyway because of more speed bonuses, but at this point I want to get it working with R. Here: http://vasir.net/blog/opencl/installing-cuda-opencl-pyopencl-on-aws-ec2 is the link to the AMI/ instructions on how to build it from scratch if you want to. Of course, then you have to install R, which defaults to R2.14, so following this great post How to install R version 3 to get R.3.1.0 running because rpud requires R>=R.2.8.
Following the directions from the r-tutor site listed above (either from simply using install.packages('rpud') or the $ R CMD INSTALL rpud_<version>.tar.gz
or by using the directions http://cran.r-project.org/web/packages/rpud/INSTALL, I get this message:
* installing *source* package ‘rpud’ ...
checking "environment variable CUDA_HOME"... "CUDA_HOME not set; using default /usr/local/cuda"
checking for /usr/local/cuda/bin/nvcc... yes
"nvcc found"
checking "whether this is the 64 bit linux version of CUDA"... checking for /usr/local/cuda/lib64/libcublas.so... yes
"yes -- using /usr/local/cuda/lib64 for CUDA libs"
"using -I/usr/share/R/include for R header files"
"using -Wl,--export-dynamic -fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lrt -ldl -lm for R shared libraries"
configure: creating ./config.status
config.status: creating src/Makefile
** libs
** arch -
/usr/local/cuda/bin/nvcc -c -I/usr/local/cuda/include -Xcompiler "-I/usr/share/R/include -fpic" rpud.cu -o rpud.o
/usr/local/cuda/bin/nvcc -c -I/usr/local/cuda/include -Xcompiler "-I/usr/share/R/include -fpic" rpudist.cu -o rpudist.o
rpudist.cu(159): warning: use of "=" where "==" may have been intended
rpudist.cu(159): warning: use of "=" where "==" may have been intended
ptxas /tmp/tmpxft_000006af_00000000-5_rpudist.ptx, line 904; warning : Double is not supported. Demoting to float
/usr/local/cuda/bin/nvcc -shared -Xlinker "-Wl,--export-dynamic -fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lrt -ldl -lm -Wl,-rpath,/usr/local/cuda/lib64" -L/usr/local/cuda/lib64 -lcublas -lcuda rpud.o rpudist.o -o rpud.so
/usr/bin/ld: unrecognized option '-Wl'
/usr/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
make: *** [rpud.so] Error 1
ERROR: compilation failed for package ‘rpud’
* removing ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.1’/rpud’
So I try to find out what -Wl is doing which leads me to another dead-end here http://www.talkstats.com/showthread.php/43438-installing-rpud-got-unrecognized-option-Wl. A friend of mine pointed me to http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html for more information on -Wl, but changing the source-code of rpud or finding/installing the correct linker might be just outside my abilities.
With regard to the comment:
ubuntu#ip-xx-xx-xx:~$ dpkg -l | grep nvidia
ii nvidia-current 319.37-0ubuntu1 NVIDIA binary Xorg driver, kernel module and VDPAU library
ii nvidia-current-dev 319.37-0ubuntu1 NVIDIA binary Xorg driver development files
ii nvidia-modprobe 319.37-0ubuntu1 Load the NVIDIA kernel driver and create device files
ii nvidia-settings 319.37-0ubuntu1 Tool for configuring the NVIDIA graphics driver
I am hoping someone is using rpud on ubuntu and could provide any further guidance on how to get rpud working. Thanks in advance for your time. If you need any more information feel free to comment.
EDIT 4/8/2014
Following the python walkthrough, http://enja.org/category/tutorial/advcl/, I am able to get a simple program running on the GPU, the python/part1 example runs perfectly. So I know that the NVIDIA drivers are working properly, at least for python. However I have yet to locate an R walk-through that will even get the packages loaded correctly.
Further findings from Python exploration: I have 2 devices on my current machine that both work.
Choose device(s):
[0] <pyopencl.Device 'Tesla M2050' on 'NVIDIA CUDA' at 0x2806460>
[1] <pyopencl.Device 'Tesla M2050' on 'NVIDIA CUDA' at 0x28064b0>
*Those could be seen by running any of the python scripts from the python GPU tutorial
Edit 4/9/2014
Knowing that Python was interfacing with OpenCL made me think, couldn't R do the same? Obviously someone else had thought the same thing and built the package 'OpenCL'
So I ran install.packages('OpenCL') and IT WORKED. Then running some of the sample code from http://cran.r-project.org/web/packages/OpenCL/OpenCL.pdf ALSO WORKED.
At this point, the only question I'm left with is, has anyone else succeeded with interfacing the GPU with R and if so, how did they do it?
I will post my step-by-step as an answer, but would love to see other ways.
Walkthrough:
Step 1: Lookup the AMI-ID ami-87377cee (the one Erik Hazzard built at http://vasir.net/blog/opencl/installing-cuda-opencl-pyopencl-on-aws-ec2) in AWS in the Community AMIs and start up a cg1.4xlarge machine.
Step 2: From command line run: sudo apt-get update then sudo apt-get install r-base-core
** this will install R2.14.1. If you want to use the latest R version, I would use the guide here: How to install R version 3
Step 3: run R, then use install.packages('OpenCL') to install OpenCL
Step 4: Have fun learning OpenCL!!
It is really that easy to get it working. Writing the code in a way that OpenCL can use is a bit tricky, but once you get the hang of it utilizing the GPU can be a very powerful tool.
See http://cran.r-project.org/web/packages/OpenCL/OpenCL.pdf for some code snippets to get you started.
With this machine you can also easily use Python with OpenCL, where I would recommend: http://enja.org/category/tutorial/advcl/ if you want to go that route.
My solution may apply on your case. I installed successfully by resolving two errors messages. First error message I resolved comes from the source file, rpudist.cu (in src folder), as the error message suggests it is in line 159. You can use a text editor to read the source file and find this code, (dev = 1.).
rpudist.cu(159): warning: use of "=" where "==" may have been intended
So I changed it to (dev == 1.), the error message was then gone.
The second error message, indeed as you have found out, is about -Wl. I think this may be more critical. It seems to conflict with another linker option -Xlinker, which is used in the file, Makefile.in in the src folder of the rpud folder (if you extract the tarball rpud_0.0.2.tar.gz).
LD_PARAMS := -Xlinker "#R_LIB# #RPATHFLAG#"
As explained in the gcc doc and I replicate here, both "Pass option as an option to the linker". So I think they passed options after them to ld to link with the files nvcc has compiled. In the following code, nvcc calls both -Xlinker, and -Wl
/usr/local/cuda/bin/nvcc -shared -Xlinker "-Wl,--export-dynamic-fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lrt -ldl -lm -Wl,-rpath,/usr/local/cuda/lib64" -L/usr/local/cuda/lib64 -lcublas -lcuda rpud.o rpudist.o -o rpud.so
Thus, the not-very-elegant workaround is to make nvcc only use -Xlinker. To sum up, except changing the (maybe not critical) file, rpudist.cu, the solution is to alter the contents in the files (1) Makefile.in (in src folder) and (2) configure (in top-level folder).
Changing the line 10 in original Makefile.in from
LD_PARAMS := -Xlinker "#R_LIB# #RPATHFLAG#"
to:
LD_PARAMS := -Xlinker #R_LIB# -Xlinker #RPATHFLAG#
Then change the line 1786 in the original configure from,
R_LIB=`"${R_HOME}/bin/R" CMD config --ldflags`
to
R_LIB="-E -fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm"
and line 1797 from,
RPATHFLAG="-Wl,-rpath,${CUDA_HOME}${CUDA_LIB_DIR}"
to
RPATHFLAG="-rpath=${CUDA_HOME}${CUDA_LIB_DIR}"
Finally, just follow Chi Yau's installation instruction
3) Expand the package in a temporary folder:
tar xf rpud_<version>.tar.gz
4) Run configure in rpud:
cd rpud
./configure
cd ..
5) Then enter the following:
R CMD INSTALL rpud
HTH

R won't call gfortran compiled object?

I made a simple fortran routine
subroutine add(x,y)
real(8) :: x,y
y = x + 3
end subroutine
saved as test.f90.
I compile with
gfortran -shared test.f90 -o test.so
In R (in the same directory), I use
dyn.load('test.so')
but it gives me this error:
Error in dyn.load("test.so") :
unable to load shared object '/Users/Steven/Documents/PhD/npsR/test.so':
dlopen(/Users/Steven/Documents/PhD/npsR/test.so, 6): Symbol not found: ___addtf3
Referenced from: /usr/local/gfortran/lib/libquadmath.0.dylib
Expected in: /Library/Frameworks/R.framework/Resources/lib/libgcc_s.1.dylib
in /usr/local/gfortran/lib/libquadmath.0.dylib
Does anyone know why? I'm using mac osx Lion, with R v2.15.0 and gfortran 4.6.2.
Thank you!
Unless you really understand what you're doing, you should use gfortran that comes with R tools. The missing symbol in libgcc isn't surprising since you're trying to run code compiled with a 4.6 gfortran in a 4.2 runtime environment.
You can only use the gfortran version that was used to build R.
Since you are on Lion and presumably have Xcode installed you can get the appropriate version of gfortran from here: http://r.research.att.com/tools/
Go to section: "Apple Xcode gcc-42 add-ons" and choose the appropriate version.
You'll have to get rid of your gfortran 4.6.2 completely or make it inaccessible by changing PATH if possible (which I doubt unless it is in /opt/...).
And do use R CMD SHLIB since that will pass the correct options to compiler and linker.

Resources