r - Memory management / cannot allocate vector of size n Mb -
i running issues trying use large objects in r. example:
> memory.limit(4000) > = matrix(na, 1500000, 60) > = matrix(na, 2500000, 60) > = matrix(na, 3500000, 60) error: cannot allocate vector of size 801.1 mb > = matrix(na, 2500000, 60) error: cannot allocate vector of size 572.2 mb # can't go smaller anymore > rm(list=ls(all=true)) > = matrix(na, 3500000, 60) # works > b = matrix(na, 3500000, 60) error: cannot allocate vector of size 801.1 mb # there room
i understand related difficulty of obtaining contiguous blocks of memory (from here):
error messages beginning cannot allocate vector of size indicate failure obtain memory, either because size exceeded address-space limit process or, more likely, because system unable provide memory. note on 32-bit build there may enough free memory available, not large enough contiguous block of address space map it.
how can around this? main difficulty point in script , r can't allocate 200-300 mb object... can't pre-allocate block because need memory other processing. happens when dilligently remove unneeded objects.
edit: windows xp sp3, 4gb ram, r 2.12.0:
> sessioninfo() r version 2.12.0 (2010-10-15) platform: i386-pc-mingw32/i386 (32-bit) locale: [1] lc_collate=english_caribbean.1252 lc_ctype=english_caribbean.1252 [3] lc_monetary=english_caribbean.1252 lc_numeric=c [5] lc_time=english_caribbean.1252 attached base packages: [1] stats graphics grdevices utils datasets methods base
consider whether need data explicitly, or can matrix sparse? there support in r (see matrix
package e.g.) sparse matrices.
keep other processes , objects in r minimum when need make objects of size. use gc() clear unused memory, or, better only create object need in 1 session.
if above cannot help, 64-bit machine ram can afford, , install 64-bit r.
if cannot there many online services remote computing.
if cannot memory-mapping tools package ff
(or bigmemory
sascha mentions) build new solution. in limited experience ff
more advanced package, should read high performance computing
topic on cran task views.
Comments
Post a Comment