Dear list, there is a bug with the *solve() *function that I cannot find a solution for a month. So I ask for your help. *Whenever I try to invert a matrix using the said function, the console hangs*. Below I explain more about this situation. Consider the code D = matrix( data = c(1, 2, 3, 4), nrow = 2, ncol = 2, byrow = TRUE) solve(D) 1. *If I launch the code in R called from a terminal, say, Konsole, the session will freeze.* * I know that the exact timing of the system freeze is when I execute the solve( ) function. * According to htop, one of my CPU core is used by 100% when this happens. 2. *If I launch the same code within RStudio, the code works as expected.* However, if I call it using the terminal inside RStudio, the session hangs. * If the solve() function is used within RMarkdown document, the session will freeze and the document will not be generated. 3. Launching R with --vanilla does not resolve the issue. 4. Rebooting the PC, using my external graphic card, reinstalling the r-base-core package in apt, and trying with different terminal emulators do not help. 5. From the documentation of the solve( ) function in R, it can be seen that solve(A, B) actually takes two arguments: A is a matrix, and B a vector or a matrix. If B is a vector, it solves the linear system Ax = B. If B is a matrix, it solves AX = B and returns X. If nothing is given in the second argument, it automatically assumes identity matrix of appropriate size as B. **The first function of solving linear system works.** If I specify matrices as the second argument, however, the same problem happens. 6. Using QR decomposition with qr.solve(A) still works well. Here are my questions: *1. Has anyone had the same problem as me?* *2. I also seek recommendations on how to fix this issue.* For your information, I am using R version 3.6.3 installed from the default apt repository. Here is the output of which R and R -- version: kobyeongmin at odie:~$ which R /usr/bin/R kobyeongmin at odie:~$ R --version R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/. Thank you for reading this, and stay safe! Best regards Ko Byeongmin [[alternative HTML version deleted]]
We can see that you use Linux. Are you by chance - on a Debian or Ubuntu system, and - have the libopenblas package installed ? If so then it is a known bug with the libopenblas0-pthread package. Installing libopen0-openmp (and also removing libopenblas0-pthread) should fix it. This is likely CPU dependent. But we need more info. Can you maybe come to the r-sig-debian list (subscription needed to reduce spam) and we continue there? Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
I get the output at the bottom, which seems OK. Can you include sessionInfo() output? Possibly this is a quirk of the particular distro or machine, BLAS or LAPACK, or something in your workspace. However, if we have full information, someone may be able to run the same setup in a VM (if I have the .iso and can find a way to set up R 3.6.3 easily, I'll be willing). It may be that you should reinstall libblas or liblapack as one thing to try. JN Here's my output:> D = matrix(+ data = c(1, 2, 3, 4), + nrow = 2, + ncol = 2, + byrow = TRUE)> solve(D)[,1] [,2] [1,] -2.0 1.0 [2,] 1.5 -0.5> D %*% solve(D)[,1] [,2] [1,] 1 1.110223e-16 [2,] 0 1.000000e+00> sessionInfo()R version 4.0.0 (2020-04-24) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Linux Mint 19.3 Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1 locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=en_CA.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.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_4.0.0>On 2020-05-09 5:45 a.m., ????[ ???? / ???? ] wrote:> Dear list, > > there is a bug with the *solve() *function that I cannot find a solution > for a month. So I ask for your help. > > *Whenever I try to invert a matrix using the said function, the console > hangs*. > Below I explain more about this situation. > > Consider the code > > D = matrix( > data = c(1, 2, 3, 4), > nrow = 2, > ncol = 2, > byrow = TRUE) > solve(D) > > 1. *If I launch the code in R called from a terminal, say, Konsole, the > session will freeze.* > * I know that the exact timing of the system freeze is when I execute the > solve( ) function. > * According to htop, one of my CPU core is used by 100% when this happens. > > 2. *If I launch the same code within RStudio, the code works as expected.* > However, if I call it using the terminal inside RStudio, the session hangs. > * If the solve() function is used within RMarkdown document, the session > will freeze and the document will not be generated. > > 3. Launching R with --vanilla does not resolve the issue. > > 4. Rebooting the PC, using my external graphic card, reinstalling the > r-base-core package in apt, and trying with different terminal emulators do > not help. > > 5. From the documentation of the solve( ) function in R, it can be seen > that solve(A, B) actually takes two arguments: A is a matrix, and B a > vector or a matrix. If B is a vector, it solves the linear system Ax = B. > If B is a matrix, it solves AX = B and returns X. If nothing is given in > the second argument, it automatically assumes identity matrix of > appropriate size as B. **The first function of solving linear system > works.** If I specify matrices as the second argument, however, the same > problem happens. > > 6. Using QR decomposition with qr.solve(A) still works well. > > Here are my questions: > > *1. Has anyone had the same problem as me?* > *2. I also seek recommendations on how to fix this issue.* > > For your information, I am using R version 3.6.3 installed from the default > apt repository. Here is the output of which R and R -- version: > > kobyeongmin at odie:~$ which R > /usr/bin/R > > kobyeongmin at odie:~$ R --version > R version 3.6.3 (2020-02-29) -- "Holding the Windsock" > Copyright (C) 2020 The R Foundation for Statistical Computing > Platform: x86_64-pc-linux-gnu (64-bit) > > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under the terms of the > GNU General Public License versions 2 or 3. > For more information about these matters see > https://www.gnu.org/licenses/. > > Thank you for reading this, and stay safe! > > Best regards > > Ko Byeongmin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On 9 May 2020 at 10:30, Dirk Eddelbuettel wrote: | | We can see that you use Linux. | | Are you by chance | | - on a Debian or Ubuntu system, and | - have the libopenblas package installed ? | | If so then it is a known bug with the libopenblas0-pthread package. | | Installing libopen0-openmp (and also removing libopenblas0-pthread) should | fix it. That was imprecise. It should read "installing libopenblas-openmp-dev" and removing both "libopenblas-pthread-dev libopenblas0-pthread". I cannot reproduce the bug on the hardware I have access to (i5, i7, xeon) though I was able to a few weeks ago. Maybe something changed already... There was also a brief thread on the debian-science list (within Debian) starting with https://lists.debian.org/debian-science/2020/04/msg00081.html and leading to https://lists.debian.org/debian-science/2020/05/msg00003.html (and this cross from April to May) We would need some more information on hardware to chase this. Dirk | This is likely CPU dependent. But we need more info. Can you maybe come to the | r-sig-debian list (subscription needed to reduce spam) and we continue there? | | Dirk | | | -- | http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org | | ______________________________________________ | R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
On 2020-05-09 11:40 -0400, J C Nash wrote:> > > solve(D) > [,1] [,2] > [1,] -2.0 1.0 > [2,] 1.5 -0.5 > > D %*% solve(D) > [,1] [,2] > [1,] 1 1.110223e-16 > [2,] 0 1.000000e+00 > >Dear list, I get another solution on my Linux i7-7500U laptop, but the same solution on my FreeBSD E3-1240Lv5 machine with a really old R version (without BLAS) ... How is this possible?> D %*% solve(D)[,1] [,2] [1,] 1.000000e+00 0 [2,] 8.881784e-16 1> sessionInfo()R version 3.6.3 (2020-02-29) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Arch Linux Matrix products: default BLAS: /usr/lib/libopenblasp-r0.3.9.so LAPACK: /usr/lib/liblapack.so.3.9.0 locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_DK.UTF-8 LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=nb_NO.UTF-8 LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=nb_NO.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=nb_NO.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.6.3>>From the machine running FreeBSD:> D %*% solve(D)[,1] [,2] [1,] 1 1.110223e-16 [2,] 0 1.000000e+00> sessionInfo()R version 3.5.2 (2018-12-20) Platform: amd64-portbld-freebsd12.0 (64-bit) Running under: FreeBSD hmm 12.0-RELEASE FreeBSD 12.0-RELEASE r341666 GENERIC amd64 Matrix products: default LAPACK: /usr/local/lib/R/lib/libRlapack.so locale: [1] C/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.5.2>Best, Rasmus