Build R with OpenBLAS
Asked Answered
B

1

5

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...

Blueberry answered 16/10, 2022 at 11:35 Comment(2)
There is no one-size-fits-all answer to this question, as the process of building R from source will vary depending on your specific system and configuration. However, some general tips that may be helpful include: -Ensure that you have the required dependencies installed on your system before beginning the build process. -If you are using the ATLAS library, make sure that you have the correct version installed for your system architecture (i.e. 32-bit or 64-bit). -If you encounter errors during the build process, try searching for solutions online or on the R-devel mailing list.Poison
@LuckyOwl I have OpenBLAS compiled and built on my current machine with gcc. So, all links for libs, connected with ATLAS/OPENBLAS were put in the MkRules.localBlueberry
W
4
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
With answered 5/3, 2023 at 15:21 Comment(5)
Sorry for my long time silence, but stil have the same error: installing 'sysdata.rda' make[4]: *** [../../../share/make/basepkg.mk:151: sysdata] Error 127Blueberry
I implemented all steps described by you. With no effect, unfortunatelly.((( Possible, the problem is cinnected with my Windows / Rtools configuration, may it be?Blueberry
'installing 'sysdata.rda' make[4]: *** [../../../share/make/basepkg.mk:151: sysdata] Error 127 make[3]: *** [Makefile.win:22: all] Error 2 make[2]: *** [Makefile.win:32: R] Error 1 make[1]: *** [Makefile:18: all] Error 2 make: *** [Makefile:399: distribution] Error 2 'Blueberry
@Blueberry every time you need to run the Msys2 shell (c:/rtools43/msys2.exe), can you try it with "Run as administrator" (Right click the msys2.exe and pick that option)?With
yes, I did it. No effect, still have the same error.Blueberry

© 2022 - 2024 — McMap. All rights reserved.