Re: [Lapackpp-devel] Memory Allocation
Status: Beta
Brought to you by:
cstim
From: kevin c. <kev...@gm...> - 2005-09-16 09:56:07
|
Hi, The code that I am using is below. The aim is to define a matrix, V, of size D_rows x D_rows and fill a diagonal band of width ~ M with values and then the rest with zeros. It is symmetric, so I calculate the diagonal and super-diagonal elements and then copy these into the correct sub-diagonal elements. #include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #include<math.h> #include<lapackpp.h>=20 int main() { ... int N =3D numberOfLines; //The value of numberOfLines is determined earlier //in the code by counting the number of lines in a //data file. int M =3D expDegree; //M is determined earlier in the file by user input int D_rows =3D N-M-1; LaGenMatDouble V(D_rows,D_rows); ... =09for(i=3D0;i<D_rows;i++) =09{ =09=09sum =3D 0.0; =09=09for(k=3D0;k<M;k++) =09=09{ =09=09=09sum +=3D p(k,0)*p(k,0)*y(i-k+M-1,1); =09=09} =09=09V(i,i) =3D y(i+M,1) + sum; =09=09if(!V(i,i)) =09=09{ =09=09=09V(i,i) =3D 1; =09=09} =09=09for(j=3Di+1;(j-i)<V_sd;j++) =09=09{ =09=09=09sum =3D 0.0; =09=09=09for(k=3D0;k<M-j;k++) =09=09=09{ =09=09=09=09sum +=3D p(k,0)*p(k+j-i,0)*y(i+M-k-1,1); =09=09=09} =09=09=09V(i,j) =3D -p(j-i-1,0)*y(i+M,1) + sum; =09=09=09if(!V(i,i)) =09=09=09{ =09=09=09=09V(i,i) =3D 1; =09=09=09} =09=09} =09=09for(j=3Di+V_sd;j<D_rows;j++) =09=09{ =09=09=09V(i,j) =3D 0.0; =09=09} =09} =09for(i=3D0;i<D_rows;i++) =09{ =09=09for(j=3D0;j<i;j++) =09=09{ =09=09=09V(i,j) =3D V(j,i); =09=09} =09} ... return 0; } This is the offending section of code. It will work fine until I get to N ~ 128 and then gives a segmentation fault. I can make the fault go away again by choosing a sufficiently large M (which reduces the size of D_rows), but this is not really practical, as M is a meaningful parameter in my model! Cheers, Kevin On 16/09/05, Christian Stimming <sti...@tu...> wrote: > Hi Kevin, >=20 > can you provide some example code that demonstrates the error? > Allocation itself usually is not a problem, even for much larger > matrices (can be verified by ./matrix/testing/tgd 200 200). >=20 > However, it is true that lapackpp unfortunately doesn't check for > successful allocation of a new matrix. I'll add this in CVS soon. >=20 > Regards, >=20 > Christian >=20 > kevin channon schrieb: > > Hi, > > > > I have used lapack++ to allocate memory for a 128x128 element > > matrix (LaGenMatDouble), which works fine. When I try to allocate > > values to the elements I get a segmentation fault. As I understand > > it, this means that my program is trying to access memory that has not > > been allocated to it. The error goes away if I use a smaller matrix > > (113x113, for example), so I think that the code works, it just runs > > out of memory. I was wondering if this is due to the memory being > > allocated on the stack instead of the heap, thus not giving much room > > for large arrays. If so, how can I get the memory allocated to the > > heap instead? If not, does anyone know what the problem could be? > |