并行bash循环 [英] bash loop in parallel

查看:49
本文介绍了并行bash循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试并行运行此脚本,因为每组中i <= 4. runspr.py 本身是并行的,这样就可以了.我想做的是在任何情况下都只运行4个i循环.

I am trying to run this script in parallel, for i<=4 in each set. The runspr.py is itself parallel, and thats fine. What I am trying to do is running only 4 i loop in any instance.

在我当前的代码中,它将运行所有内容.

In my present code, it will run everything.

#!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/问题/35416/四个任务如何并行执行但无法并行执行代码.

I have followed https://www.biostars.org/p/63816/ and https://unix.stackexchange.com/questions/35416/four-tasks-in-parallel-how-do-i-do-that but unable to impliment the code in parallel.

推荐答案

您不需要使用 for 循环.您可以将 gnu parallel 找到:

You don't need to use for loop. You can use gnu parallel like this with find:

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

这篇关于并行bash循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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