内存分配“错误:无法分配大小为 75.1 Mb 的向量"; [英] Memory Allocation "Error: cannot allocate vector of size 75.1 Mb"

查看:30
本文介绍了内存分配“错误:无法分配大小为 75.1 Mb 的向量";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对一些模拟代码进行矢量化的过程中,我遇到了内存问题.我在 Windows XP 下使用 32 位 R 版本 2.15.0(通过 RStudio 版本 0.96.122).我的机器有 3.46 GB 的内存.

In the course of vectorizing some simulation code, I've run into a memory issue. I'm using 32 bit R version 2.15.0 (via RStudio version 0.96.122) under Windows XP. My machine has 3.46 GB of RAM.

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Matrix_1.0-6   lattice_0.20-6 MASS_7.3-18   

loaded via a namespace (and not attached):
[1] grid_2.15.0  tools_2.15.0

这是问题的一个最小示例:

Here is a minimal example of the problem:

> memory.limit(3000)
[1] 3000
> rm(list = ls())
> gc()
          used (Mb) gc trigger  (Mb)  max used   (Mb)
Ncells 1069761 28.6    1710298  45.7   1710298   45.7
Vcells  901466  6.9   21692001 165.5 173386187 1322.9
> N <- 894993
> library(MASS)
> sims <- mvrnorm(n = N, mu = rep(0, 11), Sigma = diag(nrow = 11))
> sims <- mvrnorm(n = N + 1, mu = rep(0, 11), Sigma = diag(nrow = 11))
Error: cannot allocate vector of size 75.1 Mb

(在我的应用程序中,协方差矩阵 Sigma 不是对角线,但无论如何我都会得到相同的错误.)

(In my application the covariance matrix Sigma is not diagonal, but I get the same error either way.)

我花了一个下午的时间阅读 R 中的内存分配问题(包括 此处这里这里).从我读过的内容来看,我的印象是这不是可用 RAM 本身的问题,而是可用的连续地址空间的问题.不过,75.1Mb 对我来说似乎很小.

I've spent the afternoon reading about memory allocation issues in R (including here, here and here). From what I've read, I get the impression that it's not a matter of the available RAM per se, but of the available continuous address space. Still, 75.1Mb seems pretty small to me.

如果您有任何想法或建议,我将不胜感激.

I'd greatly appreciate any thoughts or suggestions that you might have.

推荐答案

R 已经到了操作系统无法为其分配另一个 75.1Mb RAM 块的地步.即执行下一个子操作所需的内存块大小.它不是关于完成整个过程所需的连续 RAM 量的声明.此时,您的所有可用 RAM 都已耗尽,但您需要更多内存才能继续运行,而且操作系统无法为 R 提供更多 RAM.

R has gotten to the point where the OS cannot allocate it another 75.1Mb chunk of RAM. That is the size of memory chunk required to do the next sub-operation. It is not a statement about the amount of contiguous RAM required to complete the entire process. By this point, all your available RAM is exhausted but you need more memory to continue and the OS is unable to make more RAM available to R.

对此的潜在解决方案是多方面的.显而易见的是,获得一台具有更多 RAM 的 64 位机器.我忘记了细节,但是 32 位 Windows 上的 IIRC,任何单个进程只能使用有限数量的 RAM(2GB?),并且不管 Windows 会为自己保留一块内存,因此 R 可用的 RAM 将比您拥有的 3.4Gb.在 64 位 Windows R 上将能够使用更多 RAM,并且您可以安装/安装的最大 RAM 量将增加.

Potential solutions to this are manifold. The obvious one is get hold of a 64-bit machine with more RAM. I forget the details but IIRC on 32-bit Windows, any single process can only use a limited amount of RAM (2GB?) and regardless Windows will retain a chunk of memory for itself, so the RAM available to R will be somewhat less than the 3.4Gb you have. On 64-bit Windows R will be able to use more RAM and the maximum amount of RAM you can fit/install will be increased.

如果这是不可能的,那么考虑另一种方法;也许分批进行模拟,每批的 n 远小于 N.这样你就可以绘制更少数量的模拟,做任何你想做的事情,收集结果,然后重复这个过程,直到你完成了足够的模拟.你没有显示 N 是什么,但我怀疑它很大,所以尝试较小的 N 多次,给你 N-全部.

If that is not possible, then consider an alternative approach; perhaps do your simulations in batches with the n per batch much smaller than N. That way you can draw a much smaller number of simulations, do whatever you wanted, collect results, then repeat this process until you have done sufficient simulations. You don't show what N is, but I suspect it is big, so try smaller N a number of times to give you N over-all.

这篇关于内存分配“错误:无法分配大小为 75.1 Mb 的向量";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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