【问题标题】:Error: C stack usage is too close to the limit in Windows environment错误:C 堆栈使用量太接近 Windows 环境中的限制
【发布时间】:2013-05-28 15:59:23
【问题描述】:

我在 R 中对 5600 x 5700 矩阵进行地统计插值,尽管有可用内存,但我收到错误“C 堆栈使用量太接近限制”。

有一些与此问题相关的 SO 问题,包括 this onethis one。这些资料和我在网上看到的其他资料表明,更改堆栈大小通常可以解决此问题。有人建议进行此更改:文件“Rinterface.h”中的R_CStackLimit = (uintptr_t)-1。但是我在 Windows 7 (x64) 上,通过 Python 2.7 中的Rpy2 模块(v 2.3.6 x64 通过Christoph Gohlke)使用 R 2.15.3 (x64),并且“Rinterface.h”不是被发现。我如何才能更改 R 的有效堆栈限制?

我为插值运行的代码如下(除了我把它包装在一个函数中):

  d <- read.table(wd,header=TRUE,sep=',')
  d <- na.omit(d)
  coordinates(d) <- ~ longdd+latdd ## convert simple data frame into a spatial data frame object
  proj4string(d) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
  stations <- spTransform(d, CRS(utm19))
  names(stations@data)[1] <- "stations"

  grids <- readGDAL("dem.asc")
  names(grids) <- "dem"
  grids$dsea <- readGDAL("dsea.asc")$band1
  proj4string(grids) <- CRS(utm19)
  ov <- overlay(grids, stations)
  stations$dem = ov$dem
  stations$dsea = ov$dsea

  stations <- stations[!is.na(stations$dsea),]

  vgm <- vgm(model="Sph",range=25000)

  v <- variogram(air_temp_max_c~dem+dsea,stations) 
  vgm_max_r<-fit.variogram(v, model=vgm)
  temp_uk <- krige(air_temp_max_c~dem+dsea, locations=stations, newdata=grids, model=vgm_max_r)
  write.asciigrid(temp_uk[1],outmax)
  max_cv <- krige.cv(air_temp_max_c~dem+dsea, locations=stations, vgm_max_r)

  max_cv <-data.frame(max_cv)
  max_cv["date"] <- dt
  max_cv["gs"] <- gs
  max_cv["parameter"] <- "air_temp_max_c"
  write.table(max_cv,file=<outFile>,sep=",",row.names=F)

【问题讨论】:

  • 您的代码中可能有一些效率低下的地方:它可能比重新编译 R 更容易修复(尤其是在 Windows 上)。你是怎么做这些插值的?
  • 这个值已经是默认值(bitbucket.org/lgautier/rpy2/src/…)。顺便说一句,您使用的是哪个版本的 rpy2? (import rpy2; print(rpy2.__version__))
  • @lgautier - 这是否意味着代码优化是我应该关注的工作?我已经更新了我的答案以包括 rpy2 版本:v2.3.6 x64 by Christoph Gohlke
  • @metasequoia - 您还可以向 Christoph 检查堆栈限制是否是我认为在 Windows 上的限制(其设置在 rpy2 的 C 代码中是有条件的)。否则,是的。我认为,这意味着仅在 R 中运行时也会达到限制。

标签: windows r stack-overflow rpy2


【解决方案1】:

您可以使用#include "Rinterface.h" 并将文件 Rinterface.h 放在与您的 C 或 R 代码相同的文件中。

“Rinterface.h”位于: https://svn.r-project.org/R/trunk/src/include/Rinterface.h

【讨论】:

    猜你喜欢
    • 2017-10-01
    • 2018-05-09
    • 2021-01-12
    • 2020-05-04
    • 2021-02-17
    • 1970-01-01
    • 2022-01-03
    • 2020-08-12
    • 2017-12-26
    相关资源
    最近更新 更多