레이블이 R인 게시물을 표시합니다. 모든 게시물 표시
레이블이 R인 게시물을 표시합니다. 모든 게시물 표시

2018년 7월 13일 금요일

Redhat 7.5 ppc64le에서 CRAN-R을 source로부터 설치하기


전에 Ubuntu 16.04 ppc64le에서 CRAN-R을 설치하는 과정을 올린 바 있습니다만, 이번에는 Redhat의 경우입니다.   대부분의 과정은 비슷합니다.

먼저, Redhat EPEL에 포함된 R은 3.5 버전입니다.  이걸 쓰셔도 된다면 그냥 이걸 설치하시는 것이 편합니다. 

[root@ING ~]# yum list | grep R-core
R-core.ppc64le                      3.5.0-1.el7         epel
R-core-devel.ppc64le                3.5.0-1.el7         epel


그러나 특정 버전, 가령 3.4.1을 설치하시려면 다음과 같이 CRAN에서 source를 받아다 설치하시면 됩니다.   먼저 기존에 설치된 R 3.5 버전을 다음과 같이 삭제합니다.

[root@ING ~]# yum erase R R-core R-core-devel R-devel R-java R-java-devel libticonv-devel

이어서 기본적으로 필요한 OS package들을 설치합니다.

[root@ING test]# yum install readline-devel readline-static libX11-devel libX11-common libXt-devel libXt bzip2 bzip2-libs bzip2-devel lzma-sdk-devel lzma-sdk457-devel pcre2-devel pcre3-devel gcc-gfortran libgfortran libcurl-devel curl texlive-latex texlive-latex-fonts texlive-txfonts texlive-pxfonts texlive-fontaxes java-1.8.0-openjdk java-1.8.0-openjdk-devel java-1.8.0-openjdk-headless

이제 source를 download 받습니다.

[root@ING test]# wget https://cran.r-project.org/src/base/R-3/R-3.4.1.tar.gz

[root@ING test]# tar -zxf R-3.4.1.tar.gz

[root@ING test]# cd R-3.4.1

Build 순서는 똑같습니다.  configure - make - make install 순입니다.

[root@ING R-3.4.1]# ./configure --enable-R-shlib

[root@ING R-3.4.1]# make -j 16

[root@ING R-3.4.1]# make install

이렇게 설치하면 기본적으로 /usr/local/lib64/R 밑에 설치됩니다.

[root@ING R]# pwd
/usr/local/lib64/R

[root@ING R]# ls
bin  COPYING  doc  etc  include  lib  library  modules  share  SVN-REVISION

그러나 별도로 PATH를 잡아주지 않아도 이미 /usr/local/bin에 R이 copy되어 있으므로 그냥 그대로 쓰시면 됩니다.

[root@ING ~]# which R
/usr/local/bin/R

[root@ING ~]# R

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: powerpc64le-unknown-linux-gnu (64-bit)
...
Type 'q()' to quit R.

> install.packages("knitr")

> install.packages("anim.plots")



*  저같은 경우 ./configure --enable-R-shlib 수행시 처음에는 아래와 같은 error가 발생했습니다.

configure: error: libcurl >= 7.22.0 library and headers are required with support for https

그러나 실제로 보면 아래처럼 libcurl은 이미 7.29 버전이 설치되어 있습니다.

[root@ING R-3.4.1]# yum list | grep libcurl
libcurl.ppc64le                     7.29.0-46.el7       @anaconda/7.5
libcurl-devel.ppc64le               7.29.0-46.el7       @rhel-7-for-power-9-rpms

이 error의 원인은 다음과 같이 config.log를 뒤져보면 알 수 있습니다.  즉, 환경 설정에서 PATH 변수 맨 앞에 anaconda2가 오도록 되어 있었는데, anaconda2 속에 설치된 libcurl의 버전이 낮은 것이 원인이었습니다.


[root@ING R-3.4.1]# env | grep PATH
PATH=/opt/anaconda2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/DL/tensorflow/bin:/opt/DL/protobuf/bin:/opt/DL/caffe-bvlc/bin

[root@ING R-3.4.1]# grep libcurl config.log
configure:40993: checking if libcurl is version 7 and >= 7.22.0
/usr/bin/ld: warning: libssl.so.1.0.0, needed by /opt/anaconda2/lib/libcurl.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libcrypto.so.1.0.0, needed by /opt/anaconda2/lib/libcurl.so, not found (try using -rpath or -rpath-link)
/opt/anaconda2/lib/libcurl.so: undefined reference to `SSL_CTX_set_srp_username'
/opt/anaconda2/lib/libcurl.so: undefined reference to `libssh2_scp_recv2'
/opt/anaconda2/lib/libcurl.so: undefined reference to `SSL_CTX_set_srp_password'
configure:41089: error: libcurl >= 7.22.0 library and headers are required with support for https

이는 간단히 PATH 환경 변수에서 anaconda2를 제거한 뒤 configure를 수행하면 간단히 핵결됩니다.

그렇게 해도 문제가 되는 수가 있는데, 그럴 경우엔 아예 다음과 같이 어느 directory에서 libcurl.so를 찾으라고 명시적으로 지정하면 확실히 해결이 됩니다.

[bsyu@p57a22 R-3.4.1]$ ./configure --enable-R-shlib LDFLAGS="-L/usr/lib64 -lcurl"


2017년 6월 2일 금요일

ppc64le 상의 R에서 gputools package 설치시 error 및 그 해결 방법



ppc64le (POWER8) 아키텍처 기반의 Linux에서 R을 사용하시면서 거기에 추가로 gputools package를 설치하시려고 하면 아래와 같은 error가 발생할 수 있습니다.

> install.packages("gputools")
(중략...)
rpath flag style... gnu
checking build system type...
tools/config.guess: unable to guess system type This script, last modified 2009-06-03, has failed to recognize the operating system you are using.
installation of package ‘gputools’ had non-zero exit status


이 error는 ./configure를 돌릴 때 흔히 나올 수 있는 error인데, 별 것은 아니고 그냥 build type을 ppc64le로 지정만 해주시면 됩니다.   제가 해보니 그것 외에도 R.h의 header file을 못 찾는다는 error도 있네요.  그것들은 모두 R CMD INSTALL 하실 때 아래와 같이 configure-args를 붙여주시면 간단히 해결됩니다.

u0017496@sys-87481:~$ sudo R
> install.packages("gputools", configure.args=c(gputools="--build=ppc64le --with-nvcc=/usr/local/cuda/bin/nvcc --with-r-include=/usr/share/R/include"))

(중략...)
/usr/local/cuda/bin/nvcc -shared    -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lcublas -lnvrtc -lcuda  rinterface.o mi.o sort.o granger.o qrdecomp.o correlation.o hcluster.o distance.o matmult.o lsfit.o kendall.o cuseful.o -o gputools.so
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
installing to /usr/local/lib/R/site-library/gputools/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (gputools)

The downloaded source packages are in
        ‘/tmp/RtmpXucwqB/downloaded_packages’
>

다음과 같이 gputools가 제대로 설치된 것을 확인하실 수 있습니다.

u0017496@sys-87481:~$ ls -l /usr/local/lib/R/site-library/gputools/libs
total 1420
-rwxrwxr-x 1 root staff 1450448 Jun  1 22:44 gputools.so

2017년 3월 27일 월요일

IBM Minsky에서의 H2O Deep Learning 설치


H2O는 확장성이 좋고 Spark, Hadoop, R 등 big data platform과 연동하여 사용하기 좋은 machine learning platform입니다.  물론 open source입니다.  H2O도 ppc64le 아키텍처, 즉 IBM Minsky (S822LC for HPC) 서버에서 사용 가능합니다.  여기서는 H2O를 R과 함께 Minsky 서버에 설치하는 방법을 정리했으며, 원본은 아래 link에 있는 내용을 참조했습니다.

http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/index.html#R


먼저, 아래 주소에서 H2O를 Minsky 서버로 download 합니다.

test@minsky:~/R$ wget http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/h2o-3.6.0.8.zip

test@minsky:~/R$ unzip h2o-3.10.4.2.zip

test@minsky:~/R$ cd h2o-3.10.4.2

test@minsky:~/R/h2o-3.10.4.2$ java -jar h2o.jar
03-27 17:04:32.866 172.18.229.117:54321  49868  main      INFO: ----- H2O started  -----
03-27 17:04:32.890 172.18.229.117:54321  49868  main      INFO: Build git branch: rel-ueno
...
03-27 17:04:34.787 172.18.229.117:54321  49868  main      INFO: Open H2O Flow in your web browser: http://172.18.229.117:54321
03-27 17:04:34.787 172.18.229.117:54321  49868  main      INFO:

이렇게 H2O 서버를 구동한 뒤에, 아래와 같이 web browser에서 54321 port로 접속이 가능합니다.




R은 Ubuntu 16.04에 포함된 r-base-core package에서 나온 3.2.3을 써도 되고, 앞선 포스팅에서 설명한 대로 MS open R server 3.3.2를 직접 build해서 써도 됩니다.  

test@minsky:~/R/h2o-3.10.4.2$ which R
/usr/local/lib/R/bin/R

먼저, R을 구동하여 R에 h2o 패키지가 설치되어 있는지 확인하여 만약 기존 것이 있으면 제거합니다.

test@minsky:~/R/h2o-3.10.4.2$ sudo R

> if ("package:h2o" %in% search()) { detach("package:h2o", unload=TRUE) }
> if ("h2o" %in% rownames(installed.packages())) { remove.packages("h2o") }

이어서 methods, statmod, stats, RCurl 등의 R 패키지를 설치합니다.

> if (! ("methods" %in% rownames(installed.packages()))) { install.packages("methods") }
> if (! ("statmod" %in% rownames(installed.packages()))) { install.packages("statmod") }
> if (! ("stats" %in% rownames(installed.packages()))) { install.packages("stats") }
> if (! ("graphics" %in% rownames(installed.packages()))) { install.packages("graphics") }
> if (! ("RCurl" %in% rownames(installed.packages()))) { install.packages("RCurl") }
> if (! ("jsonlite" %in% rownames(installed.packages()))) { install.packages("jsonlite") }
> if (! ("tools" %in% rownames(installed.packages()))) { install.packages("tools") }
> if (! ("utils" %in% rownames(installed.packages()))) { install.packages("utils") }

이 과정에서 필요시 다음과 같이 internet에서 이 package들을 download 받아옵니다.

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
HTTPS CRAN mirror

...
49: USA (CA 1) [https]             50: USA (IA) [https]
51: USA (IN) [https]               52: USA (KS) [https]
53: USA (MI 1) [https]             54: USA (OR) [https]
55: USA (TN) [https]               56: USA (TX 1) [https]
57: USA (TX 2) [https]             58: (HTTP mirrors)

Selection: 49
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/statmod_1.4.29.tar.gz'
Content type 'application/x-gzip' length 56932 bytes (55 KB)
==================================================
downloaded 55 KB


이 과정이 성공적으로 완료되면 이제 H2O 패키지를 설치합니다.  다만, 저 원본 URL에 나온 것과 같은 아래 tibshirani 버전은 H2O 버전과 맞지 않아 아래와 같은 error를 냅니다. 

> install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/R")))
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://h2o-release.s3.amazonaws.com/h2o/rel-tibshirani/8/R/src/contrib/h2o_3.6.0.8.tar.gz'
Content type 'application/x-tar; charset=binary' length 46482663 bytes (44.3 MB)
==================================================
downloaded 44.3 MB
...

> localH2O = h2o.init(nthreads=-1)
...
Error in h2o.init(nthreads = -1) :
  Version mismatch! H2O is running version 3.10.4.2 but R package is version 3.6.0.8


따라서 아래와 같이 tverberg 버전을 설치해야 합니다.

> install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/rel-tverberg/6/R")))
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://h2o-release.s3.amazonaws.com/h2o/rel-tverberg/6/R/src/contrib/h2o_3.10.3.6.tar.gz'
Content type 'application/x-tar' length 59595766 bytes (56.8 MB)
==================================================
downloaded 56.8 MB
...

설치가 완료되면 h2o를 load하고 h2o.init을 수행합니다.

> library(h2o)
----------------------------------------------------------------------
Your next step is to start H2O:
    > h2o.init()
For H2O package documentation, ask for help:
    > ??h2o
After starting H2O, you can use the Web UI at http://localhost:54321
For more information visit http://docs.h2o.ai
----------------------------------------------------------------------
Attaching package: ‘h2o’
....

> localH2O = h2o.init(nthreads=-1)
...
Starting H2O JVM and connecting: ... Connection successful!

R is connected to the H2O cluster:
    H2O cluster uptime:         3 seconds 392 milliseconds
    H2O cluster version:        3.10.3.6
    H2O cluster version age:    1 month and 6 days
    H2O cluster name:           H2O_started_from_R_root_uwo022
    H2O cluster total nodes:    1
    H2O cluster total memory:   0.89 GB
    H2O cluster total cores:    128
    H2O cluster allowed cores:  128
    H2O cluster healthy:        TRUE
    H2O Connection ip:          localhost
    H2O Connection port:        54321
    H2O Connection proxy:       NA
    R Version:                  R version 3.2.3 (2015-12-10)


이어서 demo로 kmeans를 수행해봅니다.  사전에 tightvncserver 등을 구동시켜 plot이 되도록 해놓습니다.

> demo(h2o.kmeans)

        demo(h2o.kmeans)
        ---- ~~~~~~~~~~

Type  <Return>   to start :
...
> prostate.hex = h2o.uploadFile(path = system.file("extdata", "prostate.csv", package="h2o"), destination_frame = "prostate")
  |======================================================================| 100%

> summary(prostate.hex)
 ID               CAPSULE          AGE             RACE
 Min.   :  1.00   Min.   :0.0000   Min.   :43.00   Min.   :0.000
 1st Qu.: 95.75   1st Qu.:0.0000   1st Qu.:62.00   1st Qu.:1.000
 Median :190.50   Median :0.0000   Median :67.00   Median :1.000
 Mean   :190.50   Mean   :0.4026   Mean   :66.04   Mean   :1.087
 3rd Qu.:285.25   3rd Qu.:1.0000   3rd Qu.:71.00   3rd Qu.:1.000
 Max.   :380.00   Max.   :1.0000   Max.   :79.00   Max.   :2.000
 DPROS           DCAPS           PSA               VOL
 Min.   :1.000   Min.   :1.000   Min.   :  0.300   Min.   : 0.00
 1st Qu.:1.000   1st Qu.:1.000   1st Qu.:  4.900   1st Qu.: 0.00
 Median :2.000   Median :1.000   Median :  8.664   Median :14.20
 Mean   :2.271   Mean   :1.108   Mean   : 15.409   Mean   :15.81
 3rd Qu.:3.000   3rd Qu.:1.000   3rd Qu.: 17.063   3rd Qu.:26.40
 Max.   :4.000   Max.   :2.000   Max.   :139.700   Max.   :97.60
 GLEASON
 Min.   :0.000
 1st Qu.:6.000
 Median :6.000
 Mean   :6.384
 3rd Qu.:7.000
 Max.   :9.000

....

Total Within SS:  537.6507
Between SS:  1357.349
Total SS:  1895
Centroid Statistics:
   centroid      size within_cluster_sum_of_squares
1         1 156.00000                     165.18206
2         2   6.00000                      10.15081
3         3   2.00000                       5.89369
4         4   1.00000                       0.00000
5         5  60.00000                     114.01143
6         6   2.00000                       0.04695
7         7  11.00000                      18.54178
8         8  30.00000                      82.95187
9         9  23.00000                      35.24021
10       10  89.00000                     105.63191

> plot(prostate.ctrs[,1:2])
Hit <Return> to see next plot:

> plot(prostate.ctrs[,3:4])

> title("K-Means Centers for k = 10", outer = TRUE, line = -2.0)
Warning message:
In summary.H2OFrame(prostate.hex) :
  Approximated quantiles computed! If you are interested in exact quantiles, please pass the `exact_quantiles=TRUE` parameter.


결과로서 아래와 같은 그래프가 그려지는 것을 보실 수 있습니다.