Failure to invert10 column X matrix using solve from R
I am running ubuntu Xenion 16.04. I have tracked down a failure to invert a matrix X (pasted below) to use of libopenblas 0.2.18.1ubuntu1. The matrix inverts properly when using atlas.
X <- structure(c(-0.0183246205363775, 1.13622049682697, 0.0164221479553249, 0.0729961965399091, -0.609875857464348, -1.08230240907775, -0.0686607833204824, 1.30325698555181, -1.57936871203176, 2.5978373109231, 0.538141467942054, -0.710472562725386, 1.27861202430907, 0.20897543681016, -1.58795980766889, 0.0687511393189526, -0.133512722873528, 1.01411709373234, 0.488008813317973, 1.26118300231398, 0.457295975392223, -0.341091854592564, -0.814632024240786, -0.488599252258432, 0.0949641387274746, 1.16860741089279, 2.03236356336014, -1.96664465783512, 0.413456498198013, -0.335304415075884, -0.931306356875723, -1.26241325512056, -1.96795976095205, -0.974099852723222, 0.18358194719514, -0.698808262340728, -1.20963647214515, -0.0979019554272447, 0.0219843906270597, -1.46771586857813, -2.03579478861214, -1.64238562228152, 1.8249355813312, 0.732578195765233, 0.762411587745514, -0.0226068177726354, -0.439102831962741, 0.222169108232603, -0.135233144592947, 0.275401006643804, 0.494376703210131, -0.686619384331804, -1.81262577177207, -1.82341840049472, 0.574088295321699, -0.238056399321869, -2.31435244490899, 0.550938424518628, 0.227320396441992, -1.22888868538555, 0.256111798191714, 0.453904466264377, 0.125149556431634, -1.13771380860628, -0.351843125938828, -0.854771820043009, 0.23296329612233, -1.5615695652863, -0.49267150309613, -0.560824628943685, 1.6406921135603, 1.22633424212675, -0.542261375463992, 1.30057770609974, 1.43378595025897, -2.46487498000147, -0.178611952271613, 0.525187688738461, 0.79969413645376, -1.06762700961797, -0.738703460762882, -0.673462976146274, 1.58545795022362, 1.61738361499494, -0.726869693683625, -0.0587522049741603, 0.147025783507251, 0.192683969930158, 0.618894639610175, -0.125542405755284, 0.820385676719881, 0.086755366594552, 1.33102401322938, 0.371205812465264, -0.140807388055979, -0.254957683992276, 0.263752083720235, -1.68876213597794, -0.856048619566055, -0.541211379148404, 0.47089960704812, -0.194570703189612, -0.00267896967393217, -0.0747254630967753, -0.11135968960256, -0.447291470883109, -1.37054602702333, -0.175166957164431, 0.124143080432244, -0.603695179235172, 2.19551677175156, 0.253500568615382, -0.734714484006445, 0.921576860816749, -0.019622138601083, 0.778568258473928, 0.382073897186762, 0.630903798597618, 0.734722260989757, 0.463425855232821, 0.46223937195138, -1.11419604321035, -1.05243052077062, 1.07850203031989, 1.07396039555568, 0.903387322494925, -1.49489470070112, -0.0248163498022207, 0.576244193540674, -0.720666992318311, -0.732197454891401, 0.743932392572179, 0.29679050650179, -0.619421888071807, -2.08883610805079, 0.0828517527370949, -2.18385045631777, 0.933635080958064, 0.954215304436089, -0.542166793900438, -0.0331698264302433, 0.853242548090271, -1.3324544853882, 1.14419225996717, 0.681913097740884, 0.157904022177135, -0.444597848169032, 1.40748333743815, 0.659251321524338, 0.0757536473823539, -0.419143670614619, 0.315213375958331, 0.759448806040635, 0.840709406926581, -0.253711138551116, -0.226578944604284, -0.695464183998024, -0.517718327010212, -0.458456372050112, 1.06452239013767, -1.77801073464671, -1.33583244940313, 0.975395400189107, -1.04366036101114, -0.527182357205776, 0.863321835400292, -0.404330300097421, -0.886115881866504, -1.24614112575509, -0.64771644180071, -0.171619646195305, -0.129164944941407, -1.2170715486313, -0.607174588963675, -0.623439247585641, -2.44502408501927, -1.2838690632164, 0.712595234969083, 0.494846720212164, 1.67057236784801, 1.06262766941954, -1.08174333191963, 0.86285795002261, 0.667704535972496, -1.7225983863752, -1.05799333763151, -1.2347660821382, -0.274621145255875, -0.247566181877141, -0.0323182416459611, 0.866787594645252, -1.29459911006072, 0.227682905817414, -1.16699670957252, 0.671557467086824, 0.205835476629061, -0.136065581661807, 0.540309801472388, 0.764628712352957, 0.36170831474693, 0.343191877976413, 0.331114880759637, -0.325859454446891, -0.76451855967002, -1.09928501674295, 0.850184967151779, -0.571105230240452, -0.083299915642883, -0.0500224754900679, -1.62026494624892, 1.54110292164403, -0.578283310320545, -0.0762108372246819, 0.895638620677106, 0.340688835927259, -1.21356177085134, -0.541494572503277, 0.211101139256154, -0.713131060354288, 1.90419156141159, -2.99064427313526, -1.03550554077829, 0.584679145516944, 0.720271874639311, -0.461976607241052, -1.78588740425269, 0.607080257930944, -0.242287171023757, 0.120654939508799, 0.98771305181892, -0.43317460685346, -0.121329993998857, 1.51615313383023, 0.849429170308291, -1.38239037365355, -1.10299231339851, 0.055434864611189, -1.03175811444314, -0.596447733895359, -0.279842036924054, -0.796354397427675, 0.267487974392278, 0.414439926150982, 2.54660873371994, -0.628489699506962, 0.526296829728329, 0.77876670680542, -2.13995344906695, -0.865529181488719, -0.0648540046119096, 1.79512805793961, -1.24096078781437, -0.6901618936476, -0.61252394345271, -1.44001645879869, -0.588843528642021, -0.0213438615397994, 0.755609358318704, -1.17282088043667, 1.6842397256039, -0.0398232169652981, 0.442282001932987, -1.43066970043762, 0.361821234365128, -1.37368335579089, -1.69198288821107, 1.76631625411065, 0.744819560771322, -0.316394208588817, -1.09105269456664, -2.20505127470216, 1.88780753855904, -0.92773779346093, 0.856814218293148, 0.26190106746307, 1.62711912756723, 0.164628259058608, 0.64402075889129, 1.65465148916753, -2.15885344229891, -0.350830404241684, -0.750290749993182, 1.28179637411572, -0.316960948750339, 1.65366765935459, -0.249308494332604, 1.22846580612886, -0.00868096667074801, -0.131500754127986, 0.0604927878512484, 0.234951774873012, 0.578608350908284, 1.59886864486781, 0.413099249753945, -1.67122992117473, -0.920686353745881, 0.786083637703608, -0.19570505361671, 0.357086035009244, -0.625618661986467, 1.34746239888834, -1.46558169591376, 1.18413587675254, 0.462996383992966, 1.92124065668845, -1.02335225354533, 0.25052941119203, -1.41433544942304, 0.845253382525089, 0.0408706453058961, -1.90890984916441, 0.13527654949197, 1.63549555078554, -0.137720369953547, 0.066535776478073, 0.0472264230418143, 0.0745809315866798, -0.746662618160988, 0.0990628259693987, -1.85096479462109, -0.686244336203276, 1.44060751411933, 0.648208804503858, 1.70115951447366, 0.442999779575007, 0.228640887221478, 1.2897814008662, 1.81449794861498, -0.719874982138385, 0.363309769191801, -2.05207786466802, 0.537798924018139, 1.34842621546014, 0.72919291296422, 0.77654406849771, 0.889405539646175, 0.103660702806515, 1.01197558784657, -0.117311359263959, -1.33930587365902, -1.02120902560855, 0.220603821584557, -0.90245002731839, -0.981830828449529, 0.208002896744715, -0.238247043688485, -1.97262293765893, -0.0280416756878826, -0.664129457677749, 0.655757392506883, 0.567470279282619, -0.744074352836004, 0.948568281911844, 1.43314843459926, -0.895434852367493, 2.23203144532584, -1.08708285052101, 0.960739033265867, -1.52990389804354, -0.729548676544716, 1.15804163753535, -0.0847405117843599, -0.574225377570652, -0.0113561485191644, -0.595656870576798, 2.71752823558201, -0.814364584194846, -1.51657406732523, 1.7675930595896, 2.16577885462931, -0.089821573576206, -1.37614905609915, 1.13474174159364, -0.856595938060536, -1.84813779769433, -0.284423623876465, -0.831696695615702, 0.931431930834367, -0.334056857587102, 0.566859749831532, -0.364465763932989, 0.61244342695233, 1.40076151354966, 0.354395447722642, 1.73676368988686, 1.40600833443637, -0.598202292307836, 0.815386652600608, 0.247039368538575, -1.14048918791732, -0.736807111022995, -2.67572996664186, -1.54727307041469, -1.56089931356201, 0.30331853820912, 0.432490599555485, -1.31113112174361, 0.214118112747005, -0.344183977502366, 0.162336925048187, -1.33726624538948, 0.626571553228417, 0.305991126215023, 1.46617189309052, -1.4410724477927, 1.2716001743258, 0.033077453365348, -1.40065952015903, -0.349311229025778, 0.0381867407729942, -0.152149405247552, -0.587669690899191, 0.137353660162415, -1.6163638325186, -0.996368411756899, 0.474478633512279, -0.536330221426394, -0.681932697092841, 2.25902217230263, 0.826528508242915, 0.733660997685147, 0.850953506792002, 0.240563139047006, -0.58117023632535, 0.250470917139958, -0.0225215558825611, -0.194781548134476, -0.543445603138859, -1.06460034112391, 2.04482738379601, -0.608735018948688, 0.266948953258376, 1.71467098912642, -2.77040344404546, 1.04960032676421, 1.21669341386416, 0.507222965351243, -0.132140373594725, -0.497349978614964, -0.162225116614795, -1.09180984799709, 0.752801742724077, 1.02330425941868, -0.834794227016761, -1.19993514906109, 0.0714470288520584, 0.0679090496723298, -1.78044813307408, 2.01585137049718, 0.704433970825553, -1.16825781265569, 0.0998733852402792, -0.248982191290832, -0.822085463001165, 2.25647302761214, 1.84988967187117, 0.675839347318532, 1.11405529887422, -0.171603050964347, 1.2517698438845, -1.23062521058113, -1.34392202711085, -0.58893482470645, 0.727252904368098, 0.0306222028709459, 0.302759163849301, -0.543272212418795, 1.1940321179029, -1.38178744210602, 0.171993431862794, 0.256905672719907, -0.52185195456336, 0.607729017477943, 1.2730757871503, -0.903851333685636, 0.3686738695005, -1.15658847768685, 0.86822764613805, -0.403737357763004, 1.53040294280568, -0.515034989686197, 0.553524720559838, 1.23242507423589, -0.425004308060306, -0.9389678886363, 0.0513951251071313, 0.84091464923771, -1.4059148387942, -1.17032520584473, 0.790136885938554, -0.224376774431848, 1.71819253036772, -1.74287046708856, 1.56645743943825, -0.243324829192828, -0.88690098406892, -1.37202625151887, 1.90622852823504, -1.36657786933395, 0.96735542333249, 0.00381122386002982, 0.631891042656573, -1.46321725908463, 0.345074902219115, 0.221837681449849, 0.590579274374599, 0.715133171161745, 1.68942204303253, 0.422720624837258, -0.678272558372247, 1.29707032065982, -0.139158657020745, 0.1051425658064, -1.17283680453589, -1.23323438616151, -0.55781681905478, 1.16838402887517, -0.353562748406427, -0.192476163570123, -0.301034833093097, 0.694321086045202, -0.877155963565914, -1.235649748875, -0.392244725192596, 1.05882171992901, -0.198822076077473, -0.0199335382219679, 0.154005516722786, 0.730931270995129, -0.425114160558893, 0.768149863133441, -1.08467946178863, 0.908546369762779, 1.84760719889477, -0.998918135121117, -0.737276426123522, -0.148640661896268, -2.02421634735409, -1.64590002812745, 1.22635167464449, 0.263532618356636, 0.41125116942001, -1.23853364624759, 1.40490402453399, -0.840370351315947, 0.840790786190258, -0.456961003291427, -1.4269583307178, 0.975851804681892, -0.0014430190903178, 1.23018654350671, 1.45156733557806, -1.38853036419614, -0.398270557371518, 0.777947106628022, -0.500759016120374, -1.31832895135423, 0.497918444973654, 3.0815256296559, -1.13750704360064, 0.134385001073816, 0.0936923345571311, 1.49746391658487, -1.07226322294595, 1.15902464702669, -1.4525448921303, -1.02559849589024, 1.19527976374227, 1.5643283274843, -0.719931753091717, -1.08404251324574, -1.35350513515704, 1.32655388058249, 0.173653569009098, -0.40088005799863, -0.700829350385466, 0.600939102960113, -0.664836075639952, -0.81823220688488, 0.193993359072306, 0.379993083019445, -0.748002553863189, 0.980392143815664, 0.783487301064845, -0.45119667648472, -1.17181590173111, -1.08191264129503, 0.027032416018538, 1.56552195818587, -1.66779058694997, -1.56329502275338, -1.52913576565606, 0.54530491163679, 0.309381296050651, -0.203513759179869, 0.263686393658571, 0.175757460743506, -2.04179255437242, -2.51804118820573, -0.927049967309551, -1.07649574688653, -0.993713171534848, 0.469511565629595, 0.31242152650481, 0.0868481578781338, 0.373372345773708, -1.92728252019076, -0.214198966361554, 0.0303736648290666, -0.107435025347612, -0.00428380082801964, -1.06128950669791, 0.119584420379385, -0.00846754773639875, -1.5889689337816, -0.0300427892455963, 1.84943159856875, 0.32983543886777, -0.684040876322364, -0.529935636669991, -1.78084799386689, 0.490516607037378, 0.00793447183456919, -0.833878572128222, -1.25824676945843, -0.0501909825157788, 0.135942392654512, -0.0723925301853499, 1.27892439823872, 0.0876925026626609, -0.803438612420086, -0.26739772144541, -1.4003064323877, -1.40554118718107, -0.146774404364416, 0.189793553478072, -0.192397305742466, 0.554779070876396, 0.134584112606549, 2.08699383469088, -0.652583451398982, 0.329714682004022, -0.193224068427567, -0.987099534806849, 0.211720611071858, -0.4373295317878, -0.729582101845499, -1.8035404737874, -2.21125776565022, -1.80151064022309, 2.28491693535545, -0.301137887681344, -0.266068694882546, -0.193252508071667, -0.726661457641283, -0.697485006247813, -0.259680342591884, -1.06299495457329, 0.397704760108422, 0.413439918034086, 0.597463985762665, 1.7722538910686, 0.21953892923267, -2.05936139548319, 1.850027799934, -0.342736040181288, -0.857540183401715, -0.264238108572106, -0.470412698928302, 0.540184577831763, 0.00332474119530917, 1.20135101851248, 0.329371712657169, 1.41846821799859, -1.50819519414366, -0.401899248543502, 0.0480527071766982, -0.83442537535306, -1.04214532101962, -0.365059510258834, -0.59768071814639, 0.285681087241491, -1.61107350432969, -0.582117865012968, -0.398376994210514, -1.12237640810933, -0.126533701436257, -1.32300756976068, -1.55018873369959, -0.218950189161817, 1.11603102418784, -1.01178105957912, -0.887562452023342, -0.201410147436638, 0.436651895992744, -0.439484423760442, 0.327859124164702, 0.538564558852128, -0.302083773573778, -0.441061384343174, 0.85903482836384, 2.96788120971273, 0.370884678456138, 1.17045285441645, 0.64417267947844, -0.809430844443572, 2.48408737821164, -0.100320055409889, 0.645801798357776, 2.08561582266905, -0.108283224509246, -0.70148017958109, 0.762139738646292, 0.0653837592079949, -1.66503445463726, -0.555468921185506, 0.624120638416955, -2.57214088875598, -0.99572696361021, 0.331480582027499, 1.13003984836042, -2.37766826006955, -0.45664278373105, -0.119473258890385, 2.54714014260573, -0.302809882657014, 0.122576058878145, 0.0182736068745107, -1.51309617169028, -0.294725738735133, -0.27937758068495, 0.566116514855324, -0.640565854640449, 0.880404771513833, 0.00318797874963571, -2.0695749454007, 0.804121467097792, 1.05157056367857, 0.801725566693273, -0.65314340992674, -0.284212477934366, 0.833808572497447, -1.33987081135694, 1.35026362330534, 1.09715654346548, -0.55563606178689, -0.162089282605658, -1.65040497702319, -2.25307813940113, -0.502938611563223, -1.16610092152349, -1.2047411203633, -0.0376037899255341, 0.225819605588415, 0.727141057259153, -0.252079276814061, 1.16392637729763, -0.616249749472678, -1.82846400440631, -0.619398327885543), .Dim = c(76L, 10L))
solve(t(X) %*% X)
Thanks, Clark
You make a LAPACK call too - is your liblapack.so.3 from NetLib or OpenBLAS?
Copypasta in one file: 1166_R.TXT
How does it fail for you? What CPU? Give some detail... I cannot find any failures.
All I get is variety of precision loss coming from out-of-order processing. Do you get anything completely different?
'summary(abs(c(solve(XX)%*%XX-diag(10))))' Ubuntu 14 LTS on Atom, all system BLAS packages:
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.000e+00 8.240e-18 2.526e-17 6.091e-17 6.809e-17 6.661e-16 Netlib
0.000e+00 7.522e-18 1.672e-17 4.019e-17 3.930e-17 3.331e-16 Netlib + matprod=internal
0.000e+00 6.939e-18 1.887e-17 4.228e-17 4.188e-17 6.661e-16 OpenBLAS
0.000e+00 8.674e-18 2.103e-17 4.800e-17 5.551e-17 6.661e-16 Atlas
I believe liblapack.so.3 is from OpenBLAS. I run the command sudo update-alternatives --config liblapack.so.3, and /usr/lib/openblas-base/liblapack.so.3 is selected.
When it fails, it just hangs and then sometimes crashes: "The previous R session was abnormally terminated due to an unexpected crash."
I'm getting some really weird behavior in that it also seems that the problem may depend on the order in which I load libraries. It appears that if I start with a fresh workspace and run the commands I provided, everything does work OK. I'll play with things a bit more and report back if I can narrow it down to a specific sequence of loading.
Previous session message comes from RStudio, lets take that out of picture right away. It does not use BLAS at all. Does the script crash in Rscript? source(...) in R? And OPENBLAS_CORETYPE=Atom Rscript? And with different BLAS? Like netlib? Can you debug or need help with it?
I am running the script in RStudio on an AWS server. The script crashes when running the solve command. Not sure if that answers your question.
I narrowed it down to a package I had constructed, lets call it packageX. I have been loading packageX before running the code. Within that package I have an r file called onLoad.R. This file contains the following code:
.onLoad <- function(libname, pkgname){ .jpackage(pkgname, lib.loc = libname) }
If I remove onLoad.R from the package, then the code works. Otherwise it hangs as I've mentioned.
To answer your other question, yes, if I switch so that I am using liblapack.so.3 and libblas.so.3 from atlas, the code works.
I was able to simplify the code that makes R hang
library(rJava)
.jinit()
set.seed(101)
X <- matrix(rnorm(76*10), ncol=10)
solve(t(X) %*% X)
... still no crash for me ... I start to suspect problems with your setup - either - rJava is mixed up somehow, or some R package (not rJava) directly links to other BLAS (Atlas) than system default,
Does it freeze with netlib blas & lapack?
apt install libblas-dev liblapack-dev
update-alternatives --config libblas.so.3
update-alternatives --config liblapack.so.3
Run your R stuff
Does the freeze depend on presence or absence of rJava?
i.e re-arrange your script - first run set.seed ... solve block, then initialize java, then run the calculation block again.
BTW t(x) %*% x is abbreviated as crossprod(x) and saves you one argument copy.
Thanks for the tip!
I switched to /user/lib/lapack/liblapack.so.3 and /user/lib/libblas/libblas.so.3
I'm assuming this is netlib? I did run
apt install libblas-dev liblapack-dev
and it seemed it was already installed.
When I switch to what I'm assuming is netlib, everything works fine.
Next, if I first run set.seed ... solve block, then initialize java, then run the calculation using openblas for both libblas and liblapack, everything works fine. It is only when I run library(rJava); .jinit(); first that I get the crash.
So rJava crashes and not OpenBLAS? Please figure out - R freezes or R crashes.
Are you running multithreaded ? I could imagine java not playing nice with the thread setup in some way, perhaps binding all of OpenBLAS' threads to a single core via an inadvertent affinity setting. (Early versions of OpenBLAS used to do this to others in similar circumstances..)
As I say - plays super nice with archaic versions of ancient ubuntu... I want to know if R freezes or emits some mesage, because it is nearly impossible to get debug ends meet with Rstudio - frankenstein of R, nginx, chromium and 20 other componentes.
Also R can store text segments in .Rdata aka workspace, which may include OpenBLAS, thats why you need to try Rscript (no extra packages) and R ... source(...) (no rstudio loading packages)
If you are completely stuck with RStudio UI, try this: Save test script then run: system("Rscript test-script.R") It should be very verbose if crashing.