简体   繁体   English

Shell脚本,并行和多线程?

[英]Shell script, parallel and multithreaded?

I have a shell script which actually has file/folder locations and command to run a javascript. 我有一个shell脚本,它实际上具有文件/文件夹位置以及运行javascript的命令。 I am running the job on a linux cluster with 8 processors and 4 CPU cores per processor. 我在具有8个处理器和每个处理器4个CPU内核的Linux集群上运行该作业。 I want to run this on multiple processors, at the same time each job accessing multiple threads to reduce the total runtime of the script. 我想在多个处理器上运行它,同时每个作业访问多个线程以减少脚本的总运行时间。 My question is: Is such a thing possible? 我的问题是:这可能吗? If yes what would be the command or code snippet for this? 如果是,此命令或代码段是什么?

You may be able to use GNU parallel . 您可能可以使用GNU parallel Example: 例:

parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz

"This will recompress all files in the current directory with names ending in .gz using bzip2, running one job per CPU (-j+0) in parallel." “这将使用bzip2重新压缩当前目录中所有名称以.gz结尾的文件,每个CPU(-j + 0)并行运行一个作业。”


If you don't have parallel, then you can roll your own coordinator in a couple of ways: 如果没有并行处理,则可以通过以下两种方式来滚动自己的协调器:

  1. Use make -j 使用make -j
  2. Use bash in-built backgrounding ( & ) 使用bash内置背景( &

You can use ssh for running commands on remote machines, and you can use nfs or its ilk for networked storage. 您可以使用ssh在远程计算机上运行命令,也可以使用nfs或它的ilk进行网络存储。 However you do it, you will need to think about how to partition your jobs so that they can cooperate and, as needed, coalesce results. 无论您这样做是什么,您都需要考虑如何划分您的工作,以便他们可以合作并根据需要合并结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM