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

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

问题描述

在向量化一些仿真代码的过程中,我遇到了内存问题.我正在Windows XP下使用32位R版本2.15.0(通过RStudio版本0.96.122).我的机器有3.46 GB的RAM.

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位计算机.我忘记了细节,但是IIRC在32位Windows上,任何单个进程只能使用有限数量的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天全站免登陆