如何使用多核以更快地完成gganimate [英] How to use multiple cores to make gganimate faster
问题描述
我的问题是我如何利用iMac的多个内核来使gganimate更快.还有另一个问题(下面还有更多链接)问同样的事情- 我的问题是关于该问题的答案 :stackoverflow.com/questions/57425622/speed-up-gganimate-rendering>加快gganimate渲染.
My question is how can I utilize multiple cores of my iMac in order to make gganimate go faster. There is another question (and more linked to below) that asks this same thing—my question is about an answer to this question: Speed Up gganimate Rendering.
在该答案中,Roman和mhovd指出了 GitHub评论中的示例(另请参见此GitHub帖子):
In that answer, Roman and mhovd point out an example from this GitHub comment (see also this GitHub post):
library(gganimate)
library(future)
anim <- ggplot(mtcars, aes(mpg, disp)) +
transition_states(gear, transition_length = 2, state_length = 1) +
enter_fade() +
exit_fade()
future::plan("sequential") ## default
t0 <- system.time(animate(anim))
print(t0)
future::plan("multiprocess", workers = 4L)
t1 <- system.time(animate(anim))
print(t1)
我已经尝试过,但是得到的时间彼此非常接近:
I have tried this, but get times that are very close to each other:
user system elapsed
1.0041475 0.9775679 0.9995509
除了此代码外,我还需要做其他事情吗?根据前面提到的 StackOverflow 答案或 GitHub 页面,我无法判断此代码是否应该按原样工作,或者是否在幕后进行了其他修改.
Is there something else I need to do beyond this code? Based on the aforementioned StackOverflow answer or from the GitHub pages, I can't tell if this code is supposed to work as is or if there was other modifications behind the scene that were done.
如果有帮助,我正在将iMac与8核Intel处理器配合使用.我也在R中运行它,因为RStudio说了一些关于它不支持多核的信息.
If it helps, I am using an iMac with an 8-Core Intel processor. I am also running this in R because RStudio said something about how it doesn't support multi-core.
还请注意,我的问题还与过去三个问题有关:
Note also that my question also broadly relates to these three past questions:
推荐答案
这是请求请求,表示该代码可在GitHub 上作为分支使用,但尚未在 gganimate
主版本中合并.
This is a pull request, meaning that the code is available on GitHub as a branch, but hasn't yet been merged in gganimate
master.
您可以克隆它或复制修改后的包目录.
然后:
- 确保已安装
devtools
软件包 - 打开
gganimate.Rproj
- 运行
devtools :: load_all("..")
并行版本可以运行了:
anim <- ggplot(mtcars, aes(mpg, disp)) +
transition_states(gear, transition_length = 2, state_length = 1) +
enter_fade() +
exit_fade()
future::plan("sequential") ## default
t0 <- system.time(animate(anim))
print(t0)
# user system total
# 4.384615 1.360656 1.893855
future::plan("multiprocess", workers = 4L)
t1 <- system.time(animate(anim))
# user system total
# 1.30 0.61 3.58
print(t0 / t1)
# user system total
# 4.384615 1.360656 1.893855
为避免 load_all
,您可以打开 DESCRIPTION
文件并重命名包:
To avoid load_all
you could open the DESCRIPTION
file and rename the package :
Package: gganimateparallel
Type: Package
Title: A Grammar of Animated Graphics
...
由于小插图似乎难以构建,因此您只需删除 vignettes
目录.
As vignettes seem to have difficulties to build, you can just remove the vignettes
directory.
然后 RStudio/Build/Install and restart
或从软件包目录中
Rcmd.exe INSTALL --no-multiarch --with-keep.source .
gganimateparallel
现在可以在您的系统上作为库使用.
gganimateparallel
is now available on your system as a library.
@HenrikBengtsson的成就是在未来
上所做的令人难以置信的工作!
Credits @HenrikBengtsson for the incredible job done on future
!
这篇关于如何使用多核以更快地完成gganimate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!