进行矩阵计算时出现内存不足异常 [英] out of memory exception when doing matrix calculations

查看:558
本文介绍了进行矩阵计算时出现内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在大型矩阵上进行计算时,我不断出现内存异常

150,000,000 x 2.该值未保存。有什么问题?在没有异常的情况下,对超大型矩阵进行操作的最佳方法是什么?





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?


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;
       }

推荐答案

希望这会有所帮助..

C#中的矩阵乘法
Hope this will help..
Matrix Multiplication in C#






非常好的问题...



现在的问题是,CLR不支持任何大小超过2GB的单个对象。

所以你需要改变你的计算方法



解决方案1.



你可以创建自己的类,它将采用单个数组,但内部将它分成多个部分,然后CLR会很高兴你可以完成操作而不会出现任何错误。



解决方案2.



内存映射文件供参考: MSDN [ ^ ]



您可以通过此链接清除您的想法。 http://msdn.microsoft.com/en-us/magazine/cc163995.aspx [ ^ ]



谢谢

Suvabrata
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


这篇关于进行矩阵计算时出现内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆