如何使用tasket将cpu核心分配给带有参数的程序的多个实例

时间:2016-01-21 16:02:48

标签: linux multithreading bash unix parallel-processing

问题描述

我正在尝试在 6 核心计算机上运行{strong> 7 models_test个实例。为此,我使用以下脚本。任务编号 7 是计算方面要求最高的。

#!/bin/bash

./models_test tfidf.db output/ input/ 1 10 &
./models_test tfidf.db output/ input/ 11 20 &
./models_test tfidf.db output/ input/ 21 30 &
./models_test tfidf.db output/ input/ 31 40 &
./models_test tfidf.db output/ input/ 41 50 &
./models_test tfidf.db output/ input/ 51 60 &
./models_test tfidf.db output/ input/ 61 70

./models_test需要 5 参数:

  1. 数据库
  2. 输出路径
  3. 输入路径
  4. id 1
  5. id 2
  6. 使用taskset

    我希望使用taskset命令运行相同的 7 实例,如下所示:

    #!/bin/bash
    
    # Cpus are identified by `{0, 1, 2, 3, 4, 5}`
    
         taskset -c 0 ./models_test tfidf.db output/ input/ 1 10 &
         taskset -c 1 ./models_test tfidf.db output/ input/ 11 20 &
         taskset -c 2 ./models_test tfidf.db output/ input/ 21 30 &
         taskset -c 3 ./models_test tfidf.db output/ input/ 31 40 &
         taskset -c 3 ./models_test tfidf.db output/ input/ 41 50 &
         taskset -c 4 ./models_test tfidf.db output/ input/ 51 60 &
         taskset -c 5 ./models_test tfidf.db output/ input/ 61 70
    

    问题

    • 我是否通过在 6 核心上划分 7 任务在taskset中正确完成工作?
    • 第一个脚本是否会在 6 核心上自动分配 7 七个任务?

1 个答案:

答案 0 :(得分:1)

我经常遇到类似的问题。我没有使用任务集,而是使用nice:

parallel --nice 11 ./models_test tfidf.db output/ input/ {} '{= $_+=9 =}' ::: {1..60..10} &
./models_test tfidf.db output/ input/ 61 70
wait