运行 对于每个并行循环
run for each loop in parallel
如果我有这样的每个语句:
for i in 1 2 3 4
do
fairly large script here with lots of logic and stuff and $i is in many areas..the code in ehre also needs to run in a sequence...
done
如何并行生成 4 个循环而不是 运行 串行生成
使用 &
运算符(运行 在后台)
for i in 1 2 3 4
do
echo "test 1 $i" &
echo "test 2 $i" &
done
我想我现在明白你的意思了。您希望 4 对作业并行 运行,每对作业的两半需要按顺序 运行。所以,本质上,你有
Job 1A followed sequentially by Job 1B
Job 2A followed seuqentially by Job 2B
Job 3A followed sequentially by Job 3B
Job 4A followed sequentially by Job 4B
以上4行都可以运行并行
如果是这样,您需要:
for i in 1 2 3 4 ; do
( echo $i A start; sleep 5; echo $i A end; echo $i B start; sleep 5; echo $i B end ) &
done
如果我有这样的每个语句:
for i in 1 2 3 4
do
fairly large script here with lots of logic and stuff and $i is in many areas..the code in ehre also needs to run in a sequence...
done
如何并行生成 4 个循环而不是 运行 串行生成
使用 &
运算符(运行 在后台)
for i in 1 2 3 4
do
echo "test 1 $i" &
echo "test 2 $i" &
done
我想我现在明白你的意思了。您希望 4 对作业并行 运行,每对作业的两半需要按顺序 运行。所以,本质上,你有
Job 1A followed sequentially by Job 1B
Job 2A followed seuqentially by Job 2B
Job 3A followed sequentially by Job 3B
Job 4A followed sequentially by Job 4B
以上4行都可以运行并行
如果是这样,您需要:
for i in 1 2 3 4 ; do
( echo $i A start; sleep 5; echo $i A end; echo $i B start; sleep 5; echo $i B end ) &
done