0

I am doing a project that requires me to create 15 double arrays of dimensions 100000*100000. All of them are lower triangular matrix. So it's not a surprise that ran out of memory just for 1 such array giving an error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

How should I remove the zeros in those matrices and code them like this

#define WIDTH 100000
#define HEIGHT 100000
int jimmy [HEIGHT * WIDTH];
int n,m;

int main ()
{
  for (n=0; n<HEIGHT; n++)
    for (m=0; m<WIDTH; m++)
   {
     jimmy[n*WIDTH+m]=(n+1)*(m+1);
  }
}

This is a snippet of the code that I am working on. I have used the following matrices which I haven't shown. All of them are Lower triangular. I don't need all of them at once.

double T  = 0.3;   // final time.
double iN = 100; // samples(I want it 100000) 
double h  = T/N;   // step-size

double a_i11[iN][iN],a_i12[iN][iN],a_i13[iN][iN];
double a_i21[iN][iN],a_i22[iN][iN],a_i23[iN][iN];
double a_i31[iN][iN],a_i32[iN][iN],a_i33[iN][iN];
double a_f[iN][iN];

double b_i12[iN][iN],b_i13[iN][iN];
double b_i22[iN][iN],b_i23[iN][iN];
double b_p[iN][iN];

This answer shows the best efficient way to store a lower triangular matrix. Can anyone please tell me the most efficient way to combine these two methods? My last goal is to convert this C++ code to CUDA code.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Hellblazer
  • 11
  • 4
  • 1
    That code would be running out of stack space, but whatever. Why to you actually need to store the arrays at all? That example could *easily* be replaced by a function with zero memory requirements – talonmies Feb 15 '21 at 08:40
  • 3
    One triangular 100000 x 100000 matrix of doubles is over 40 GB of data. If this matrix is dense (like shown in your example) there's no way to store it in much smaller amount of space. You basically have following options: a) generate matrix parametrically on the fly instead of storing it; b) represent your matrix as a product of smaller matrices or c) if the matrix is sparce (most of its entries are zeros), use an appropriate sparse matrix storage formal like Compressed Sparse Rows – Sergei Ozerov Feb 15 '21 at 08:42
  • 2
    Fifteen half-matrices of that size would require ~600 gigabytes of RAM. Unless the matrices are very sparse, or you have a truly massive machine, this is the time to either give up or think harder about the problem. Perhaps you don't really need all that data, and perhaps you don't need all the matrices simultaneously. – molbdnilo Feb 15 '21 at 08:56
  • I have now put a snippet of my actual code. I hope you can see my problem. Thanks for the help!! – Hellblazer Feb 15 '21 at 08:56
  • I have now removed the CUDA tag twice from this question. This is in no way a CUDA programming question at this point and it serves no purpose to tag it as one. Please don't re-add the tag – talonmies Feb 15 '21 at 09:22
  • I am sorry for that. I am new to this, I didn't know someone else can remove the tag. – Hellblazer Feb 15 '21 at 09:25

0 Answers0