You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R 4.3.0(Apple M1平台)mclapply返回序列化对象大小限制异常

mclapply在64位Apple M1 Pro的R 4.3.0中仍存在大对象序列化限制问题

R的mclapply帮助文档说明:“在R 3.4.0之前及32位平台上,每个分叉进程的序列化结果限制为2^31 - 1字节。”但在64位Apple M1 Pro笔记本的R 4.3.0版本中,仍出现该问题。测试显示:输入对象超过该大小可正常运行,但返回对象超过该大小时,多核心mclapply执行失败,单核心模式(实际为lapply)则正常。

测试代码与结果

1. 多核心(2核)下返回对象未超限制:正常运行

library(parallel)

## 将numeric转为integer以测试对象大小变化
test_function <- function(input) {return(as.integer(input))}  

# 构造测试对象,输入大小约4.24GB(远超2^31字节)
test_object <- rep(1.0, 5.3e8)
as.numeric(object.size(test_object))/1e9  # 输出约4.24

# 多核心执行mclapply
out <- mclapply(list(test_object, test_object), test_function, mc.cores=2)
as.numeric(object.size(out[[1]]))/1e9  # 每个返回对象约2.12GB(略小于2^31字节)

此段代码可正常运行,无报错。

2. 单核心下返回对象超限制:正常运行

# 增大测试对象,输入大小约4.32GB(远超2^31字节)
test_object <- rep(1.0, 5.4e8)
as.numeric(object.size(test_object))/1e9  # 输出约4.32

# 单核心执行mclapply(实际调用lapply)
out <- mclapply(list(test_object, test_object), test_function, mc.cores=1)
as.numeric(object.size(out[[1]]))/1e9  # 每个返回对象约2.16GB(略大于2^31字节)

此段代码可正常运行,无报错。

3. 多核心(2核)下返回对象超限制:执行失败

# 同样使用大小约4.32GB的测试对象
test_object <- rep(1.0, 5.4e8)
as.numeric(object.size(test_object))/1e9  # 输出约4.32

# 多核心执行mclapply
out <- mclapply(list(test_object, test_object), test_function, mc.cores=2)

执行后出现警告:

Warning message:
In mclapply(list(test_object, test_object), test_function, mc.cores = 2) :
  scheduled cores 1, 2 did not deliver results, all values of the jobs will be affected

内容的提问来源于stack exchange,提问作者H. Johnson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 20:50:11