Data.table: R-偏差变化; 并行区域内的R-API

创建于 2018-11-30  ·  4评论  ·  资料来源: Rdatatable/data.table

卢克·蒂尔尼(Luke Tierney)与我联系了有关R-devel中的内存问题。 CRAN和Travis / Appveyor上都通过了测试,但是在某些情况下,内存使用率更高。 和以前一样,垃圾收集器关闭。
不知道何时准确更改了R-devel,但不确定上个月的某个时间。 可能是R-devel更改导致了新的内存问题,或者R-devel更改揭示了已经存在的问题(甚至在R-release上甚至有data.table-release)。 无论如何,都需要修复它。

卢克写道:

I distilled the issue in 'constellation' down to the attached file
from the examples. If I run this the memory usage is much bigger than
previously and the gc() output is garbled. It's a
multi-threading issue again; everything looks fine with
OMP_NUM_THREADS=1. With mutlipe threads you are
calling DATAPTR from threads other than the main one and that creates
a race on setting the R_GCEnabled flag, so eventually it is getting
stuck on off. I instrumented the places where the GC is disabled and
tracked this as the first one from a thread other than the main one:

#4  0x00007ffff78ba9d5 in DATAPTR (x=x@entry=0x1167458)
     at ../../../R/src/include/Rinlinedfuns.h:106
#5  0x00007fffea02c4c8 in subsetVectorRaw (target=0x4529590, source=0x1167458,
     idx=0x4175210, any0orNA=FALSE) at subset.c:44
#6  0x00007fffea02c7a6 in subsetDT (x=<optimized out>, rows=<optimized out>,
     cols=<optimized out>) at subset.c:272

给出了Luke的细节,无需重现就可以很容易地在代码中看到问题。 所有R API的使用都需要按照Luke的要求将所有并行区域都排除在外。 由于时间紧迫,我上次延迟执行此操作,现在需要解决。 上一次,我只是第一步,就是要确保并行区域内的DATAPTR不会收到ALTREP。

这保证了1.12.0的加速发布,尤其是因为它会影响Luke。

$ grep "omp.*parallel" *.c

  • [x]子集
  • [x] reorder.c
  • [x] fwrite.c
  • [x] fread.c
  • [x] fsort.c
  • [x] forder.c
  • [x]之间

$ grep ALTREP *.c

  • [x]之间
  • [x] fsort.c
  • [x] reorder.c
  • [x] wrappers.c
R-devel bug

最有用的评论

卢克(Luke)非常努力地找出原因! 💯

所有4条评论

卢克(Luke)非常努力地找出原因! 💯

我正在与卢克(Luke)确认问题已解决,然后再关闭...

确认固定。 感谢@ltierney的帮助。


为了完整性,我们需要回头...
我无法用如下编译的R-devel重现该问题。 (我需要确认可以用1.11.8重现该问题,然后才能确认1.11.9已修复该问题。)

./configure --without-recommended-packages --disable-byte-compiled-packages --enable-strict-barrier CC="gcc -fsanitize=address -fno-sanitize=float-divide-by-zero -fno-omit-frame-pointer" CFLAGS="-O0 -g -Wall -pedantic"

即使使用Luke提供的脚本:

library(data.table)
library(constellation)
temp <- as.data.table(vitals[VARIABLE == "TEMPERATURE"])
pulse <- as.data.table(vitals[VARIABLE == "PULSE"])
resp <- as.data.table(vitals[VARIABLE == "RESPIRATORY_RATE"])
temp[, RECORDED_TIME := as.POSIXct(RECORDED_TIME,
  format = "%Y-%m-%dT%H:%M:%SZ", tz = "UTC")]
pulse[, RECORDED_TIME := as.POSIXct(RECORDED_TIME,
  format = "%Y-%m-%dT%H:%M:%SZ", tz = "UTC")]
resp[, RECORDED_TIME := as.POSIXct(RECORDED_TIME,
  format = "%Y-%m-%dT%H:%M:%SZ", tz = "UTC")]
gc()
for (i in 1:10) {
  cat("i=",i,"\n")
  b1 <- bundle(temp, pulse, resp,
    bundle_names = c("PLATELETS", "INR"), window_hours_pre = 24,
    window_hours_post = c(6, 6), join_key = "PAT_ID",
    time_var = "RECORDED_TIME", event_name = "CREATININE", mult = "all")
}
gc()

从长远来看,我更简单地重新编译R-devel,如下所示,仍然使用--enable-strict-barrier ,这很重要:
./configure --without-recommended-packages --enable-strict-barrier
重新安装了星座及其所有依赖项和data.table 1.11.8,这次Luke的脚本正确地失败了:

Fatal error: Wrong thread calling 'RunFinalizers'

将data.table-dev(1.11.9)安装到此R-devel中并重新运行,可以正常工作。 重新安装data.table 1.11.8再次失败。 因此,确实已由1.11.9修复。 在我最初的R-devel编译中,也许有些东西可以使1.11.8正常工作(禁用字节编译器,-00,ASAN等)。 无论如何,需要一个更简单的R-devel编译,值得尝试。

@jangorecki如果时间允许,最好在CI管道中使用的R-devel中添加--enable-strict-barrier 。 我不知道您是否为CI管道编译R-devel。

@mattdowle是的,我每天编译R-devel,将在此添加该标志。 添加到不要忘记#3147

此页面是否有帮助?
0 / 5 - 0 等级