rbuildamd-processoropenblasr-devel

Build R with OpenBLAS


I'm trying to build R-devel / R-patched. I've read some links, connected with steps for doing this.

1) https://www.r-bloggers.com/2022/01/building-r-4-2-for-windows-with-openblas/
2) https://www.r-bloggers.com/2020/05/building-r-4-for-windows-with-openblas/
3) https://github.com/r-windows/r-base

But unfortunatelly, without any success.

In "1" I have no "Makefile.win" and no file with "-lf77blas -latlas" In "2" manually created "full-build.sh" script do not do anything. In "3" I have an error with Use_ATLAS=YES

installing 'sysdata.rda'
make[3]: *** [../../../share/make/basepkg.mk:151: sysdata] Error 127
make[2]: *** [Makefile.win:22: all] Error 2
make[1]: *** [Makefile.win:32: R] Error 1
make: *** [Makefile:18: all] Error 2

This error is connected with this row in basepkg.mk:

@$(ECHO) "tools:::sysdata2LazyLoadDB(\"$(srcdir)/R/sysdata.rda\",\"$(top_builddir)/library/$(pkg)/R\")" | \
  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE)

So, could anyone helps me, pls? What's wrong with these 3 ways? How it's possible to build R devel correctly (with installation file if possible)? Also is it possible to compile this with AMD BLIS library (I have Ryzen 9 5950x).

Thank you.

P.S. I use Windows 11 and gcc-12.02 from winlibs P.P.S. If possible, please, add a recipe for building R with AMD BLIS...


Solution

  • 1) https://cran.r-project.org/bin/windows/base/howto-R-devel.html # the canonical guide for compiling R-devel on Windows using Rtools
    2) https://www.r-bloggers.com/2022/01/building-r-4-2-for-windows-with-openblas/ # adapt parts of this guide to get openblas with R
    

    Following the 2 above links, here are some basic steps:

    1. Install Rtools43

    (i) Download; (ii) Install it to default location (i.e., C:\rtools43)

    2. Install MikTeX and Inno Setup

    MikTeX (with basic packages and inconsolata) is needed to build package vignettes and documentation. Inno Setup is needed to build the R installer.

    3. General setup

    1. Run the Msys2 shell (c:/rtools43/msys2.exe)

    2. Make a folder to store the source files: mkdir /c/R-devel

    3. Update Msys2: pacman -Syuu it may update only the core stuff first, then ask you to close the terminal. You should follow the instructions, then relaunch Msys2 shell and rerun pacman -Syuu a second time to fully update all the components

    4. Install wget and subversion: pacman -Sy wget subversion

    5. Change the working directory to the folder created in step 3.2: cd /c/R-devel

    6. Grab latest Tcl/Tk bundle from here, a file named such as tcltk-5493-5412.zip:

       TCLBUNDLE=tcltk-5493-5412.zip
       wget https://cran.r-project.org/bin/windows/Rtools/rtools43/files/$TCLBUNDLE
      
    7. Grab the latest R version (R-devel), and unzip Tcl:

       svn checkout https://svn.r-project.org/R/trunk
       cd trunk
       unzip ../$TCLBUNDLE
      

    4. Add a MkRules.local in /c/R-devel/trunk/src/gnuwin32/

    You can use Notepad++ to create a new MkRules.local file with the following contents (edit ISDIR = ... to the appropriate directory in step 2):

    USE_ATLAS = YES
    EOPTS = -march=native -pipe
    QPDF = /usr
    ISDIR = C:/Program Files (x86)/Inno Setup 6
    

    5. Adjust /c/R-devel/trunk/src/extra/blas/Makefile.win

    You can use Notepad++ to change the line -L../../../$(IMPDIR) -lR -L"$(ATLAS_PATH)" -lf77blas -latlas to -L../../../$(IMPDIR) -lR -fopenmp -lopenblas

    -          -L../../../$(IMPDIR) -lR  -L"$(ATLAS_PATH)" -lf77blas -latlas
    +          -L../../../$(IMPDIR) -lR -fopenmp -lopenblas
    

    6. Compile R

    1. Run the Msys2 shell and change to appropriate working directory: cd /c/R-devel/trunk/src/gnuwin32/

    2. Set environment variables as follows (update the MiKTeX installation directory in the commands below):

       export PATH=/x86_64-w64-mingw32.static.posix/bin:$PATH
       export PATH=/c/Users/xxxxxxxx/AppData/Local/Programs/MiKTeX/miktex/bin/x64/:$PATH
       export TAR="/usr/bin/tar"
       export TAR_OPTIONS="--force-local"
      
    3. Test that the tools are available: which make gcc pdflatex tar

    4. Build R installer:

       make rsync-recommended
       make distribution
      
    5. The installer will be available at: /c/R-devel/trunk/src/gnuwin32/installer/R-devel-win.exe

    7. Test if our R compilation utilize OpenBLAS

    The following R code should run much faster compare to standard R for Windows downloaded from CRAN:

    m <- 10000
    n <- 2000
    A <- matrix (runif (m*n),m,n)
    system.time (S <- svd (A,nu=0,nv=0))
    
    user  system elapsed 
    4.02    0.65    7.83