从R下到Julia的紧密连接 [英] Close connections to Julia from under R

查看:60
本文介绍了从R下到Julia的紧密连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的R代码中,我使用MixedModels Julia包.
我使用JuliaCall软件包将Julia集成到了R中.
我使用非常大的数据集(~1 GB~4x10^6观测值),并且在建模步骤(mixed models)分配了很多RAM(~80 GB),大多数内存在结束后不会返回系统计算.

R环境中获取建模结果后,如何从R 下关闭与Julia的连接(或者关闭Julia)?同时, R会话不应中断,因为在计算混合模型之后,其他功能应在管道中执行.
此操作可以帮助释放一定数量的内存到系统(我在纯Julia上运行代码,并且在Julia退出后将大约70 GB返回到OS.当我在R上运行代码时,经过管道计算后,Julia占用的RAM不会返回到OS完成)
(平台:x86_64-pc-linux-gnu).

In my R code, I use the MixedModels Julia package.
I integrate Julia in R using the JuliaCall package.
I work with very large datasets (~1 GB, ~4x10^6 observations) and at the modeling step (mixed models) a lot of RAM is allocated (~80 GB), most of it does not return to the system after the end of calculations.

How can I close the connections to Julia from under R (or maybe close Julia) after obtaining the modeling results in the R environment? At the same time, the R session should not be interrupted, since after calculating the mixed models, other functions should be executed in pipeline.
This action can help release certain amount of memory to the system (I ran code on pure Julia and after Julia exit about 70 GB was returned to OS. When I run code on R, RAM occupied by Julia is not returned to OS after pipeline calculations are completed)
(Platform: x86_64-pc-linux-gnu).

推荐答案

如果从R中调用Julia代码作为函数,则可以将已计算的参数的元组返回给R,而无需数据.如果是这样,那么在从Julia返回之前,您可以将对数据的所有引用以及其他大内存引用变量设置为0,然后收集垃圾.如果

If you called the Julia code from R as a function, you can return a tuple of the parameters you have calculated to R without the data. If so, then, prior to returning from Julia, you can set all of the references to the data and other large memory referencing variables to 0 and then collect garbage, eg. if

a = rand(1000, 1000, 100)
a = 0  # destroy reference since Julia reference counts

然后手动调用垃圾收集器:

then call the garbage collector manually:

GC.gc()

这假定您不再需要Julia变量引用的内部数据,这可能是您想要的只是模型的参数.

This assumes that you don't need the internal data that the Julia variables reference any more, which is likely if all you wanted was the model's parameters.

这篇关于从R下到Julia的紧密连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆