超大二维数组的计算怎么解决

kobekiln 2013-06-26 07:24:59
之前在http://bbs.csdn.net/topics/390500903?page=1#post-394880178 中提出了我的一些蠢问题。就是:


求各位大神帮忙。
c++程序中需要定义几个 几万*几万的数组,例如a[30000][240000],来进行计算;

结果定义了之后,vs2010显示数组过大,但我又很想要实现这么大规模的运算,请问怎么解决呢?

具体情况补充一下:
是一个100*300的网络
(我将“田”字形网络,称为3*3的网络;“田”字形网络中,有9个节点单元和12个杆单元。),

每个节点单元、杆单元中都有一定的物理量信息,通过物理定律发生关系(实际上我使用这个网络来模拟多孔介质中的渗流过程,节点单元、杆单元中含有压强、流量、导流率等信息)。

已知物理量a和物理量b,要列方程组来求物理量c,此时这个由于节点数很大,这个方程组就很大了(100*300元一次方程组)。我需要解这个方程组,于是我就想到用数组来解。结果就出现了数组太大的问题。

系数矩阵是个稀疏阵。

求大神帮忙啊!
...全文
192 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-06-28
  • 打赏
  • 举报
回复
Sparse File Operations [This is preliminary documentation and subject to change.] You can determine whether a file system supports sparse files by calling the GetVolumeInformation function and examining the FILE_SUPPORTS_SPARSE_FILES bit flag. Most applications are not aware of sparse-files and will not create sparse files. The fact that an application is reading a sparse file is transparent to the application. An application that is aware of sparse-files should determine whether its data set is suitable to be kept in a sparse file. After that determination is made, the application must explicitly declare a file as sparse, using the FSCTL_SET_SPARSE operation. After an application has set a file to be sparse, the application can use the FSCTL_SET_ZERO_DATA operation to set a region of the file to zero. In addition, the application can use the FSCTL_QUERY_ALLOCATED_RANGES operation to speed searches for nonzero data in the sparse file. When you perform a write operation (with a function or operation other than FSCTL_SET_ZERO_DATA) whose data consists nothing but zeros, zeros will be written to the disk for the entire length of the write. To zero out a range of the file and maintain sparseness, use FSCTL_SET_ZERO_DATA. A sparse aware application may also set an existing file to be sparse. If an application sets an existing file to be sparse, it should then scan the file for regions which contain zeros, and use FSCTL_SET_ZERO_DATA to reset those regions, and possibly deallocate some physical disk storage. An application upgraded to sparse file awareness should perform this conversion. When you perform a read operation from a zeroed-out portion of a sparse file may not read from the hard drive. Instead, the system recognizes that the portion of the file to be read contains zeros, and it returns a buffer full of zeros without actually reading from the disk. As with any other file, the system can write data to or read data from any position in a sparse file. Nonzero data being written to a previously zeroed portion of the file may result in allocation of disk space. Zeros being written over nonzero data (with FSCTL_SET_ZERO_DATA) may result in a deallocation of disk space. Note It is up to the application to maintain sparseness by writing zeros with FSCTL_SET_ZERO_DATA. Note Defragmenting tools which handle compressed files on NTFS file systems will correctly handle sparse files on NTFS 5.0 volumes.
ri_aje 2013-06-28
  • 打赏
  • 举报
回复
最正规的解决方案是用稀疏矩阵,其他的都是不着调的凑合。退一步说,即便用非稀疏矩阵的方法暂时解决了存储问题,估计也没有 solver 会解这种变态的密集数组。
kobekiln 2013-06-28
  • 打赏
  • 举报
回复
引用 9 楼 ananluowei 的回复:
内存映射--稀疏调拨的内存映射文件 windows核心编程第五版的第17章内存映射文件中有介绍这种类似于电子表格的大规模稀疏数据如何实现。
好的
大尾巴猫 2013-06-28
  • 打赏
  • 举报
回复
内存映射--稀疏调拨的内存映射文件 windows核心编程第五版的第17章内存映射文件中有介绍这种类似于电子表格的大规模稀疏数据如何实现。
lm_whales 2013-06-28
  • 打赏
  • 举报
回复
分块计算吧!分割后就变小了;数据可以存放到文件里
kobekiln 2013-06-27
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
用文件读写模拟内存读写。 参考_lseeki64函数。
好的。我查一查
赵4老师 2013-06-27
  • 打赏
  • 举报
回复
用文件读写模拟内存读写。 参考_lseeki64函数。
kobekiln 2013-06-27
  • 打赏
  • 举报
回复
引用 4 楼 hui211314dd 的回复:
看错了,貌似需要的内存很多啊,那么可以考虑使用内存映射,最大支持16EB
好的,我去查一查,谢啦。
hui211314dd 2013-06-26
  • 打赏
  • 举报
回复
看错了,貌似需要的内存很多啊,那么可以考虑使用内存映射,最大支持16EB
hui211314dd 2013-06-26
  • 打赏
  • 举报
回复
忘了,我是火迷,火箭迷,不是热火迷!
hui211314dd 2013-06-26
  • 打赏
  • 举报
回复
建议加上抽象层,大致就是编写一个类,类的构造函数包括数组的X,和Y,既30000和240000,类的内部进行虚拟内存分配; 类的接口还包括对二维数组值的查询,更改等等,类的内部进行相应的操作等等; 个人愚见,仅供参考!
kobekiln 2013-06-26
  • 打赏
  • 举报
回复
其实就是对每个节点列方程,列出来就是有300*100个方程,300*100个未知数

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧