【问题标题】:bash loop in parallelbash 并行循环
【发布时间】:2023-03-27 04:55:01
【问题描述】:

我正在尝试并行运行此脚本,因为每组 irunspr.py 本身是并行的,这很好。我想要做的是在任何情况下只运行 4 i 循环。

在我目前的代码中,它会运行一切。

#!bin/bash
for i in *
do 
  if [[ -d $i ]]; then
    echo "$i id dir"
    cd $i
      python3 ~/bin/runspr.py SCF &
  cd ..
  else
    echo "$i nont dir"
  fi
done

我关注了https://www.biostars.org/p/63816/https://unix.stackexchange.com/questions/35416/four-tasks-in-parallel-how-do-i-do-that 但无法并行实现代码。

【问题讨论】:

    标签: bash gnu-parallel


    【解决方案1】:

    您不需要使用for 循环。你可以像这样使用gnu parallelfind

    find . -mindepth 1 -maxdepth 1 -type d ! -print0 |
    parallel -0 --jobs 4 'cd {}; python3 ~/bin/runspr.py SCF'
    

    【讨论】:

    • 也可以试试:parallel 'cd {}; python3 ~/bin/runspr.py SCF' ::: */
    【解决方案2】:

    另一种可能的解决方案是:

    find . -mindepth 1 -maxdepth 1 -type d ! -print0 |
    xargs -I {} -P 4 sh -c 'cd {}; python3 ~/bin/runspr.py SCF'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 2021-05-09
      • 1970-01-01
      相关资源
      最近更新 更多