Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用bash'进行并行处理&';命令_Linux_Bash_Shell_Unix_Parallel Processing - Fatal编程技术网

Linux 使用bash'进行并行处理&';命令

Linux 使用bash'进行并行处理&';命令,linux,bash,shell,unix,parallel-processing,Linux,Bash,Shell,Unix,Parallel Processing,我试图使用不同的参数同时多次运行单个R文件GNU Parallel不是我的选择,因为我在一台服务器上运行它,而我无权安装Parallel。所以我选择了bash命令& command1 & command2 & command3 ..... command30 然而,当我运行这个程序时,它的行为并不像预期的那样。在命令中,我将每个命令的输出保存到一个新文件中,我注意到一些文件是空的。实际上大部分都是。因此,我猜测,仅通过编写上述内容,一些进程正在被终止 然而,当我给 comman

我试图使用不同的参数同时多次运行单个R文件
GNU Parallel
不是我的选择,因为我在一台服务器上运行它,而我无权安装Parallel。所以我选择了bash命令&

command1 & command2 & command3 ..... command30
然而,当我运行这个程序时,它的行为并不像预期的那样。在命令中,我将每个命令的输出保存到一个新文件中,我注意到一些文件是空的。实际上大部分都是。因此,我猜测,仅通过编写上述内容,一些进程正在被终止

然而,当我给

command1 &
command2 &
command3 &
command4 &

wait &

command5 &
command6 &
command7 &
command8 &

wait 

.
.
.
它工作正常,但问题是它比只运行
command1
要多花5倍的时间,因为它要等到前面的命令完成。在这里,时间是非常重要的因素,我希望所有命令都能在同一时间(几乎)运行,就像只运行一个命令一样

  • 为什么没有
    等待
    它会“崩溃”
  • 是否有任何方法可以改进时间,以便所有命令都可以在一个命令占用的时间内运行
  • 我有没有办法不用
    wait
    来实现这一点
(从技术上讲,我知道
&
不会使进程并行运行,但它会为每个命令创建不同的进程)

提前谢谢

我的原始代码:

Rscript svmRScript_v2.r 0.05 1 > output/out0.1-10.txt &
Rscript svmRScript_v2.r 0.05 2 > output/out0.05-2.txt &
Rscript svmRScript_v2.r 0.05 5 > output/out0.05-5.txt &
Rscript svmRScript_v2.r 0.05 10 > output/out0.05-10.txt &

wait &

Rscript svmRScript_v2.r 0.05 50 > output/out0.05-50.txt &
Rscript svmRScript_v2.r 0.05 100 > output/out0.05-100.txt &
Rscript svmRScript_v2.r 0.05 500 > output/out0.05-500.txt &
Rscript svmRScript_v2.r 0.01 1 > output/out0.1-10.txt &

wait &

Rscript svmRScript_v2.r 0.01 2 > output/out0.01-2.txt &
Rscript svmRScript_v2.r 0.01 5 > output/out0.01-5.txt &
Rscript svmRScript_v2.r 0.01 10 > output/out0.01-10.txt &
Rscript svmRScript_v2.r 0.01 50 > output/out0.01-50.txt &

wait &

Rscript svmRScript_v2.r 0.01 100 > output/out0.01-100.txt &
Rscript svmRScript_v2.r 0.01 500 > output/out0.01-500.txt &
Rscript svmRScript_v2.r 0.005 1 > output/out0.1-10.txt &
Rscript svmRScript_v2.r 0.005 2 > output/out0.005-2.txt

当你检查这些文件时,它们还没有被写出来。通过输出重定向,shell会在启动作业时创建输出文件,但输出缓冲通常会将文件保留为空或至少不完整,直到进程完成。等待迫使你推迟,直到工作真正完成

除非单个作业主要在等待某些外部资源,否则期望并行处理在可以执行一个作业的同时执行两个作业是非常不合理的。更多的工作需要更多的时间


如果启动太多后台进程,实际上完成作业的速度会变慢,因为任务切换占用了可用处理能力的很大一部分。只测试几个,特别是当它们严重受限于CPU时。五个作业的批处理可能是一个合理的起点,但瓶颈显然完全取决于这些脚本实际执行的操作。

&
不是命令。从技术上讲,它是一个命令分隔符;但您也可以将其视为后缀运算符。
wait
的参数应该是进程ID。如果您的进程获得PID 5,则任何进程都不太可能获得。@Sheller是的,但xargs进程会一个接一个地执行命令,这就是我的经历。您是否知道,如果您被授权编写自己的perl脚本,那么您就被授权运行GNU并行程序?有没有什么方法可以不使用wait来实现这一点?我的意思是,我只是随机使用了
wait 5
,这不是很符合逻辑。最后一个大的
wait
(没有参数)将正确地等待所有后台进程完成。但是如上所述,一次运行几个进程可能比一次启动所有进程效率更高,只是为了争夺有限的系统资源。我尝试将
wait
放在最后,结果成功了。但这几乎是一个命令所需时间的3倍。问题是我正在准备一个需要2小时或更长时间才能执行的命令。这就是为什么我需要在同一时间完成并行处理。如果你的CPU不是100%,你仍然有一些问题需要解决。如果是这样的话,你的钱就值了,你需要买一台更大的电脑,让它运行得更快。