# performance / computing time optimization for dealing with huge tables

I'm currently coding a Finite Element Method (FEM) program in Mathematica. For the so called stiffness matrix I need a very large table preferably around the size of 10^6 x 10^6 cells that are all zero at first.

For a smaller Table 10^4 x 10^4, I used the following code:

Timing[k=Table[0, {i, 1, 10^4}, {j, 1, 10^4}];]


and got results around 0.9 - 1.0 seconds

since ((10^6)^2)/((10^4)^2) = 10^4 I would expect a computing time of roughly 10000 seconds (~2.7 hours) for a 10^6 x 10^6 table which is frankly put, too slow.

I tried ParallelTable as well, but it's only like 30% faster

Is there a faster way to generate such a big array?

• k = ConstantArray[0, {10^6, 10^6}, SparseArray] Commented Jul 3, 2018 at 9:35
• .. or k = SparseArray[{}, {10^6, 10^6}]?
– kglr
Commented Jul 3, 2018 at 9:43
• @Coolwater, kglr exactly what I was looking for, thanks!
– p4di
Commented Jul 3, 2018 at 10:46

k = ConstantArray[0, {10^6, 10^6}, SparseArray]