简体   繁体   中英

Configuring MKL with R

I'm having a problem to trigger threads with R using the MKL library. I am currently using Ubuntu 18.04.2 LTS.

Linux pedro-HP-EliteOne-800-G1-AiO 4.18.0-15-generic #16~18.04.1-Ubuntu SMP Thu Feb 7 14:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

r-open$ screenfetch 
                          ./+o+-       pedro@pedro-HP-EliteOne-800-G1-AiO
                  yyyyy- -yyyyyy+      OS: Ubuntu 18.04 bionic
               ://+//////-yyyyyyo      Kernel: x86_64 Linux 4.18.0-15-generic
           .++ .:/++++++/-.+sss/`      Uptime: 19h 27m
         .:++o:  /++++++++/:--:/-      Packages: 1834
        o:+o+:++.`..```.-/oo+++++/     Shell: bash
       .:+o:+o/.          `+sssoo+/    Resolution: 1920x1080
  .++/+:+oo+o:`             /sssooo.   DE: GNOME 
 /+++//+:`oo+o               /::--:.   WM: GNOME Shell
 \+/+o+++`o++o               ++////.   WM Theme: Adwaita
  .++.o+++oo+:`             /dddhhh.   GTK Theme: Ambiance [GTK2/3]
       .+.o+oo:.          `oddhhhh+    Icon Theme: ubuntu-mono-dark
        \+.++o+o``-````.:ohdhhhhh+     Font: Ubuntu 11
         `:o+++ `ohhhhhhhhyo++os:      CPU: Intel Core i5-4590S @ 4x 3.7GHz [27.8°C]
           .o:`.syhhhhhhh/.oo++o`      GPU: intel
               /osyyyyyyo++ooo+++/     RAM: 2659MiB / 7867MiB
                   ````` +oo+++o\:    
                          `oo++.      

Note : My machine has 4 cores .

Initially I downloaded the file l_mkl_2019.2.187.tgz on the intel website and did the installation for /home/pedro/ . Later I downloaded the R-3.5.2.tar.gz file to compile R with multithreaded MKL support. I performed the compilation by doing:

source /home/pedro/intel/mkl/bin/mklvars.sh intel64
cd /home/pedro/Downloads/R-3.5.2 && ./configure --enable-R-shlib --enable-threads=posix --with-lapack --with-blas="-fopenmp -m64 -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lpthread -lm"
make
make install

Apparently the compilation occurred without any problems. Using the sessionInfo() command I had the following result:

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS/LAPACK: /home/pedro/intel/compilers_and_libraries_2019.2.187/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so

locale:
 [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=pt_BR.UTF-8        LC_COLLATE=pt_BR.UTF-8    
 [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=pt_BR.UTF-8   
 [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.5.2

Basically I'm trying to parallelize a Monte Carlo simulation using the parallel :: mclapply function. The fact is that serially (1 core) I have better results using the MKL but when trying to parallelize, I realize that the threads are not fired in the 4 cores.

What I did using the function parallel::mclapply was:

parallel::mclapply(1:8, FUN = function(x) func_metodos(), mc.cores = 4)) , wherein func_metodos() is a function that I implemented in R and want to repeat 8 times.

Note : I would like a solution other than using the Microsoft R Open . I do not like to use something that Microsoft puts its finger on.

Best regards.

I covered that in some length in

This can be fully automated as I demonstrated there. I can add more color but I got to run now...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM