Possible memory leak when using LAPACKE_dgesv

Post here if you want to report a bug to the LAPACK team

Possible memory leak when using LAPACKE_dgesv

Postby laurentberset » Wed Nov 21, 2012 8:22 pm

Hi,

I am having trouble when I use the function LAPACKE_dgesv. At first, I was using it in one of my subfunction and everytime I was running it, a segmentation fault would crash the execution. At this point, I assumed I was manipulating the variable incorrectly and that was causing the segmentation fault. Below is my subfunction using LAPACKE_dgesv:

Code: Select all
#include "lapacke.h"

int dgesv(int n, int nrhs, double* a, int lda, double* b, int ldb) {
   int info, ipiv[2];

   info = LAPACKE_dgesv(LAPACK_ROW_MAJOR,n,nrhs,b,ldb,ipiv,a,lda);

   return info;
}


My debugging skill being limited, I moved the call for the function within the main. Here is the code I used:
Code: Select all
int main (int argc, char* argv[]) {
   double a[] = {0.960953869740567,1.37897197791661,-0.353849997774433,0.350179410603312,-1.15640165566400,1.01868528212858,-1.12012830124373,-1.33200442131525,0.124049800003193,-1.05818025798736,-0.823586525156853,-0.299066030332982,-0.533557109315987,-0.133217479507735,2.52599969211831,-2.32986715580508,1.43669662271894,-0.468615581100624,-1.57705702279920,0.0228897927516298,-2.00263573588306,-0.714530163787158,1.65549759288735,-1.44909729283874,-1.96089999936503,-0.272469409250188,0.507974650905946,-0.261995434966092,0.964229422631628,1.35138576842666,0.307535159238252,0.333510833065806,-0.197698225974150,1.09842461788862,0.281984063670556,-1.75021236844679,0.520060101455458,-0.224771056052584,-1.25711835935205,0.391353604432901,-1.20784548525980,-0.277871932787639,0.0334798822444514,-0.285650971595330,-0.0200278516425381,-0.589029030720801,-0.865468030554804,0.451679418928238,2.90800803072936,0.701541458163284,-1.33367794342811,-0.831366511567624,-0.0347710860284830,-0.293753597735416,-0.176534114231451,-0.130284653145721,0.825218894228491,-2.05181629991115,1.12749227834159,-0.979206305167302,-0.798163584564142,-0.847926243637934,0.791416061628634,0.183689095861942};
   double b[] = {-0.863652821988714,-0.225584402271252,-1.49159031063761,-0.764849236567874,0.197811053464361,-1.14795277889859,-0.438966153934773,0.489965321173948,0.0773590911304249,1.11735613881447,-0.742301837259857,-1.40226896933876,1.58769908997406,0.104874716016494,-1.79467884145512,0.739363123604474,-1.21411704361541,-1.08906429505224,-1.06158173331999,-1.42237592509150,-0.804465956349547,0.722254032225002,0.840375529753905,1.71188778298155,-1.11350074148676,0.0325574641649735,2.35045722400204,0.488193909859941,0.696624415849607,2.58549125261624,-0.888032082329010,-0.194123535758265,-0.00684932810334806,0.552527021112224,-0.615601881466894,-0.177375156618825,0.835088165072682,-0.666890670701386,0.100092833139322,-2.13835526943994,1.53263030828475,1.10061021788087,0.748076783703985,-0.196053487807333,-0.243715140377952,0.187331024578940,-0.544528929990548,-0.839588747336614,-0.769665913753682,1.54421189550395,-0.192418510588264,1.41931015064255,0.215670086403744,-0.0824944253709554,0.303520794649354,1.35459432800464,0.371378812760058,0.0859311331754255,0.888610425420721,0.291584373984183,-1.16584393148205,-1.93302291785099,-0.600326562133734,-1.07215528838425};

   int info, nrhs=8, lda=8, ldb=8, n=8;
   int a1=1,a2=2,a3=3,a4=4;
   int ipiv[2];

   info = LAPACKE_dgesv(LAPACK_ROW_MAJOR,n,nrhs,b,ldb,ipiv,a,lda);
}


The matrices a and b are random generated matrices by MatLab.

Below is the console output of the execution. (I added the parameter I am passing to the function and their memory address)
Code: Select all
MAIN: before LAPACKE_dgesv -----------------------
@a[0]:0x22fae0
@a[24]:0x22fba0
@b[0]:0x22fce0
@b[24]:0x22fda0
n(8):8          @: 0x22fef8
nrhs(8):8       @: 0x22ff04
lda(8):8        @: 0x22ff00
ldb(8):8        @: 0x22fefc
a1(1):1 @: 0x22fef4
a2(2):2 @: 0x22fef0
a3(3):3 @: 0x22feec
a4(4):4 @: 0x22fee8
MAIN: after LAPACKE_dgesv -----------------------
@a[0]:0x22fae0
@a[24]:0x22fba0
@b[0]:0x22fce0
@b[24]:0x22fda0
n(8):7          @: 0x22fef8
nrhs(8):8       @: 0x22ff04
lda(8):8        @: 0x22ff00
ldb(8):8        @: 0x22fefc
a1(1):8 @: 0x22fef4
a2(2):7 @: 0x22fef0
a3(3):7 @: 0x22feec
a4(4):4 @: 0x22fee8

RESULT: LAPACKE_dgesv -----------------------
info: 0

-0.894483   -0.0648154   0.254521   0.832071   0.478159   -0.076208   -0.182274   0.36999
1.20481      -0.511619   -0.815435   -1.30753   -0.481337   -1.04871   0.693935   -0.298648
1.53742      -4.95996   0.0751944   -1.98395   0.131645   -2.93339   6.48097      -0.43967
-1.22146   3.46785      0.558691   1.76207      0.737501   2.50507      -4.83092   1.04021
0.870406   -2.95369   0.0824745   -1.12543   0.928554   -1.76242   4.82236      -0.450789
-1.773      3.16286      -0.111111   1.32086      0.120631   2.00619      -4.23275   0.538064
2.06185      -3.56459   -0.592326   -2.10559   0.160154   -3.17644   5.26349      -0.104808
1.05472      -1.81218   -0.372239   -0.0470531   -0.135681   -0.991561   2.75244      -0.569837


If we take a look at the variable 'n', 'lda' and 'ldb' they have been changed after the execution of LAPACKE_dgesv. However, info is set to 0 and if I read the content of the array b, the result are absolutely correct. In my testing, I have added several variable in the main function (a1,a2,a3,a4). As we can see in the result, they also have been modified without the function even using them.

I then decided to try to use LAPACKE_dgetrf and LAPACKE_dgetrs, to get to the same result and unfortunately, LAPACKE_dgetrf is also producing a segmentation fault.

I have been investigating this for a while now and really don't know how to work around this. I compiled the revision 1370 of the lapack-trunk.

Any kind of help or advice will be much appreciated. I am also available to run additional tests or anything that could help solve this problem.
laurentberset
 
Posts: 1
Joined: Tue Nov 20, 2012 6:25 pm

Return to Bug report

Who is online

Users browsing this forum: No registered users and 1 guest