Hi, I’d like to translate a Fortran 90 program to Julia and then continue with my development in Julia. The bottleneck right now seem to be the solving of around 100 systems of linear equations where the matrix (~400x400 and complex valued) is general.
In Fortran, I’m using the ZGELSS routine from LAPACK (with ifort and mkl) and everything seems to be alright. After that, the computation continues towards the end goal and I am getting a meaningful result (the easiest result I can get are some differential cross section plots which are continuous).
Related to this, I’ve also been trying to call ZGELSS from MKL via ccall and failed (see this other topic I opened: Calling Intel MKL as an external library on Mac)
In Julia, I have very slightly different systems of linear equations, and, after trying many ways of solving the linear equations, I couldn’t get a meaningful result (the plots were always very discontinuous).
Trying to troubleshoot this, I copied a couple of matrices (the first two are 21x21 and 61x61) from gdb (while debugging the Fortran program) to Julia format. I then tried to solve them with various Julia methods and I saw that the solutions are different than the Fortran ones.
I’ve been computing A * x - b and looking at how close to 0 they were and the solutions from Fortran seemed to be weird. For the 21x21 system the last element of the A * x - b was ≈e-6 and for the 61x61 system, there were predominantly elements ≈e-6 and even some ≈e-4. In contrast, for the Julia solutions, all of the elements were ≈e-19.
here’s the code to get these: 21x21 system and 61x61 system
A * x - b for the 21x21 system
[-8.41193052129676e-20 - 1.7618285302889447e-19im;
6.021949305641171e-19 - 5.590417451878382e-20im;
3.1739912720394736e-19 - 6.776263578034403e-20im;
2.030165921001147e-19 + 3.6591823321385775e-19im;
6.576416742041591e-20 - 5.421010862427522e-20im;
-1.6568096797192123e-19 - 8.131516293641283e-20im;
-1.1265538198482195e-19 + 1.0570971181733668e-18im;
-6.775469484646352e-19 + 7.453889935837843e-19im;
-7.5174174068819155e-19 - 1.3552527156068805e-20im;
3.586125740437894e-19 - 2.574980159653073e-19im;
1.971469184734384e-18 + 4.912791094074942e-20im;
5.22036993304666e-19 - 9.215718466126788e-19im;
-4.2118713302220084e-19 - 1.9651164376299768e-19im;
1.8550021544869177e-19 + 7.860465750519907e-19im;
-2.8079142201480056e-19 + 1.1519648082658485e-19im;
-1.2475736521871776e-18 + 2.727446090158847e-19im;
-4.1504614415460717e-20 + 3.6422416731934915e-19im;
-1.6040686438628313e-19 - 6.2002811739014785e-19im;
2.286988957586611e-20 - 6.005463596032989e-19im;
-1.0942606887341493e-19 - 4.0149361699853836e-19im;
-6.604427503011574e-6 + 6.604427503011174e-6im]
A * x - b for the 61x61 system
[9.760892516039532e-5 - 4.100798101845093e-6im;
-2.730647765114168e-20 - 1.571678266618155e-20im;
6.400431078830215e-5 - 3.805928084635793e-6im;
-3.756187174301844e-6 + 5.638383581659189e-6im;
-5.342260391612202e-20 + 1.7658319322163377e-20im;
-2.438728221806456e-5 - 6.025413522853987e-6im;
-1.3821389038091633e-5 + 8.612209815336237e-6im;
-2.398256312587934e-19 + 1.013825737990661e-19im;
4.1161593406279174e-5 + 9.141185893385266e-6im;
-1.0274252913931014e-5 - 1.0543996746264763e-5im;
-3.3539866302940466e-6 + 1.1066685915407524e-6im;
0.00010069331314181374 - 8.424775358141123e-21im;
-1.8432641825977152e-6 + 1.9122637919002016e-5im;
7.829953301362379e-6 + 2.957411639832971e-6im;
1.3820346824677052e-5 + 9.304126363287537e-20im;
5.119050267405865e-6 + 1.002847074080797e-5im;
9.555217621769329e-20 + 2.2136043405215362e-20im;
7.154835356177473e-5 + 1.124904278191871e-5im;
-6.495542158257637e-7 - 6.597301609668962e-6im;
-3.0183157578901532e-5 - 2.245133389592671e-5im;
-0.0001472892965390413 + 4.473295925708644e-19im;
5.73771726031555e-6 + 3.4225865943845064e-5im;
-1.2946684480996267e-19 - 3.854230380851119e-19im;
-0.00016055757130969993 - 1.87858585318712e-6im;
1.6468286127333356e-5 + 1.5551326830996722e-5im;
3.566446962470552e-5 + 4.730876177151483e-6im;
-0.0003120660188802475 - 5.685219811429178e-20im;
4.99975369828618e-6 + 5.945819516277557e-6im;
9.574364267929141e-6 + 6.952092670467297e-7im;
0.0001976285845226872 - 3.096925363013367e-20im;
1.590357534547442e-5 + 5.943175664586429e-6im;
8.319340956772255e-6 - 2.3804324829714663e-6im;
0.00023714506325843435 + 3.211160373721208e-5im;
3.2669298156510517e-5 + 2.179302362121413e-6im;
-6.487695623290713e-19 + 1.5985781545548807e-20im;
-0.00015523211767915195 + 1.9044901694239245e-19im;
-4.452933517091035e-5 + 1.0297354528050546e-5im;
-3.018943989950913e-18 - 2.407119728549568e-19im;
0.00010356311401058251 + 1.1135757924987326e-5im;
-1.27620363060983e-5 + 1.3228694198667444e-5im;
-6.33205758091314e-21 + 2.515222138802148e-19im;
-3.0092554624420232e-5 - 1.6746107095485413e-6im;
8.919079144532807e-19 - 1.963827789169692e-19im;
-1.9880646201407765e-5 + 2.1287508248804676e-6im;
-0.00015814947471110417 + 3.710669092613512e-6im;
-0.00013754026748623695 + 3.7235210514262154e-8im;
-6.419798592577473e-5 - 1.138124089567215e-5im;
7.043353985198681e-5 - 3.450212697203164e-20im;
-4.62290385179595e-5 - 1.579528329359978e-5im;
-7.705308154600581e-7 - 9.43115835040066e-6im;
2.886030190722491e-5 + 1.6078917622759995e-19im;
5.00536886289637e-6 - 7.031114175103631e-6im;
5.065176850986559e-5 + 2.1900483801697587e-5im;
-3.767142276049058e-5 + 3.1906763381359277e-19im;
-5.5691324017020326e-5 - 3.281499493800018e-5im;
-0.00019680591760458494 + 2.2159419005093834e-6im;
1.776298006268921e-5 + 6.98001345549784e-19im;
-0.0002201167291087681 + 9.764302999792899e-5im;
-0.00012155856835381963 - 0.00012906230166654346im;
2.187084283257905e-6 - 4.6928553719359486e-18im;
0.00018884657326180516 + 0.00022475453546830226im]
At this point I started looking at the floating point standards used, but they seemed to be the same. I then looked into the stability of linear systems and the Fortran matrices that I copied from Fortran to Julia seem to have condition numbers ≈42.4 and 1.000000000000013 (this cannot be right?).
(by the way, the linear equations I was trying to solve in Julia had condition numbers between 1 and 10)
I’d like to figure out the source of the difference between the solutions of the linear systems before I move on to do anything else and I don’t know how to troubleshoot this anymore. Any input is appreciated.
Also some questions I’d like to find the answer to:
What’s the best way to quantify how good a solution is?
Is there a good way of moving large complex valued matrices from Fortran to Julia (other than writing Fortran code to output arrays that can be interpreted by Julia)? And is moving the systems the the best way to run the Julia solvers on them?