0

While I understand that for large matrices, there may not be enough ram space. However in this case the value is relatively small (9999). The value is a double (4.0) and thus contains, according to my resources, 8 bytes of data (per double). So in theory, a matrix with n = 9999 (n = number of both the number of columns and rows) would need (9999^2 * 8) bytes in Java (not including any overheads) which is significantly less than my current ram, even if there happened to be a couple of matrices (2-3). The error occurs when matrixA is initialized.

Why is the error happening?

int n = 9999;

double[][] matrixA = new double[n][n];
double[][] matrixB = new double[n][n];

// Matrix Multiply uses standard ijk algorithm to multiply matrixA and matrixB
// and returns a 2d double array (matrix)

double[][] matrixC = MatrixMultiply(matrixA, matrixB);

Urmzd
  • 682
  • 4
  • 17

2 Answers2

2

9999x9999x8 = 799840008 bytes of data.

Are you setting your JVM memory settings? Default for client JVM is 256 meg. It doesn't matter if your system memory is high enough if the JVM isn't set properly.

More details on setting the JVM heap settingshere: What are the -Xms and -Xmx parameters when starting JVM?

Jeremy Smith
  • 311
  • 2
  • 13
1

8 bytes per double, 10,000 x 10,000 matrix yields 800Mb per matrix. 2 or 3 of these is 2-3Gb. Pretty soon, we're talking real memory.

To figure out how much memory Java thinks it has on startup, run this:

java -XX:+PrintFlagsFinal -version | grep MaxHeapSize

and then, increase the amount of memory given to java at runtime:

java -Xmx16G ...
iluxa
  • 6,941
  • 18
  • 36