Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I keep getting an out of memory exception when I do calculations on large matrices
150,000,000 x 2. The value is not saved. What is wrong?What is the best way to do operations on extremely large matrices without getting oom exceptions?


C#
public double[,] MultiplyMatricesSequential2(double[,] matA, double[,] matB)
       {

           double[,] result = new double[matA.GetLongLength(0), 2];

           int matARows = matA.GetLength(0);

           for (int i = 0; i < matARows; i++)
           {
               result[i, 0] = matB[i, 0];
               if (i == 2560)
               {
                   int test3 = 0;
               }
               double test2 = 3 * matA[i, 1];
               double geometricMean = matA[i, 1] * matB[i, 1];
               if (geometricMean == 0 || matB[i, 1] > test2)
               {
                  result[i, 1] += matB[i,1];
               }


           }

           return result;
       }
Posted
Comments
Jibesh 13-Dec-12 0:52am    
whats your input to this method. the OOM exception is depends on your data you are processing.

Hope this will help..
Matrix Multiplication in C#
 
Share this answer
 
v2
Hi,

Very good question...

now the problem is, CLR doesn't support any single object of size greater than about 2GB.
So you need change you way of calculation

Solution 1.

you can make your own class which will take an single array but internally split it in multiple parts, then CLR will be happy and you can do the operation with out any error.

Solution 2.

Memory Mapped files for reference : MSDN[^]

You can go through this link it will clear you idea. http://msdn.microsoft.com/en-us/magazine/cc163995.aspx[^]

Thanks
Suvabrata
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900