R 只在 Linux 中的某个 CPU 上运行 [英] R only ever runs on a certain CPU in Linux

查看:69
本文介绍了R 只在 Linux 中的某个 CPU 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台运行 R 4.0.2 的 8 核 RHEL Linux 机器.

I have an 8-core RHEL Linux machine running R 4.0.2.

如果我向 R 询问内核数量,我可以确认有 8 个可用.

If I ask R for the number of cores, I can confirm that 8 are available.

> print(future::availableWorkers())

[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost"

> print(parallel::detectCores())

[1] 8

但是,如果我运行这个简单的例子

However, if I run this simple example

f <- function(out=0) {
    for (i in 1:1e10) out <- out + 1
}

output <- parallel::mclapply(1:8, f, mc.cores = 8)

my top 表示只使用了 1 个内核(因此每个 worker 使用该内核的 1/8,或整个机器的 1/64).

my top indicates that only 1 core is being used (so that each worker is using 1/8th of that core, or 1/64th of the entire machine).

%Cpu0  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  2.0 us,  0.0 sy,  0.0 ni, 98.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 32684632 total, 28211076 free,  2409992 used,  2063564 buff/cache
KiB Swap: 16449532 total, 11475052 free,  4974480 used. 29213180 avail Mem

  PID USER  PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 3483 user  20   0  493716  57980    948 R  1.8  0.2   0:18.09 R
 3479 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R
 3480 user  20   0  493716  57980    948 R  1.5  0.2   0:18.08 R
 3481 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R
 3482 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R
 3484 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R
 3485 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R
 3486 user  20   0  493716  57980    948 R  1.5  0.2   0:18.09 R

有人知道这里会发生什么吗?另一个记录类似行为的 StackOverflow 问题是 这里.很明显,我以某种方式搞砸了安装.我按照 RHEL 7 的 这些安装说明进行操作.我猜有依赖性失踪,但我不知道在哪里看.如果有人对运行诊断等有任何想法,他们将不胜感激.

Does anyone know what might be going on here? Another StackOverflow question that documents similar behavior is here. It's clear that I messed up the install somehow. I followed these install instructions for RHEL 7. I'm guessing there is a dependency missing, but I have no idea where to look. If anyone has any ideas of diagnostics to run, etc., they would be most appreciated.

为了进一步了解,我的机器上还安装了 R 3.4.1,当我运行此代码时,一切正常.(我通过 yum 安装了那个版本.)

For further context, I have R 3.4.1 also installed on my machine, and when I run this code, everything works fine. (I installed that version through yum.)

我昨天还使用上面链接的相同说明安装了 R 4.0.3,但它遇到了同样的问题.

I also installed R 4.0.3 yesterday using the same instructions linked above, and it suffers from the same problem.

推荐答案

首次运行

system(sprintf("taskset -p 0xffffffff %d", Sys.getpid()))

那么你的简单例子

f <- function(out=0) { for (i in 1:1e10) out <- out + 1 }
output <- parallel::mclapply(1:8, f, mc.cores = 8)

适用于所有 8 个内核.

works on all 8 cores.

这篇关于R 只在 Linux 中的某个 CPU 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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