a) 我想并行运行 2 个脚本
b) 我想在这些脚本中并行执行我的 for 循环。
在我有这段代码之前:
for year in 2000 2001 2002 2003; do
echo $year" LST data being merged"
cd $base_data_dir/$year
# this is the part that takes a long time
cdo -f nc2 mergetime *.nc $output_dir/LST_$year.nc
done
我想使用 GNU Parallel 来尝试并行运行它。
我尝试了以下内容:a) 创建一个调用其他脚本的“ Controller ”脚本
b) 传入一个数组作为 GNU parallel 的参数
Controller 脚本
# 1. Create monthly LST for each year
cd $working_dir
seq 2000 2003 | parallel 'bash create_yearly_LST_files.sh {}'
# 2. Create monthly NDVI for each year
cd $working_dir
seq 2000 2003 | parallel 'bash create_yearly_NDVI_files.sh {}'
这应该并行运行以下内容:
bash create_yearly_LST_files.sh 2000
bash create_yearly_LST_files.sh 2001
...
bash create_yearly_NDVI_files.sh 2000
bash create_yearly_NDVI_files.sh 2001
...
处理脚本(NDVI同理)
year="$1"
echo $year" LST data being merged"
cd $base_data_dir/$year
cdo -f nc2 mergetime *.nc $output_dir/LST_$year.nc
所以命令应该是:
cd $base_data_dir/2000
cdo -f nc2 mergetime *.nc $output_dir/LST_2000.nc
cd $base_data_dir/2001
cdo -f nc2 mergetime *.nc $output_dir/LST_2001.nc
...
cd $base_data_dir/2000
cdo -f nc2 mergetime *.nc $output_dir/NDVI_2000.nc
cd $base_data_dir/2001
cdo -f nc2 mergetime *.nc $output_dir/NDVI_2001.nc
...
我的问题:
这些进程在我的新代码中仍然有效,但没有性能提升。
任何人都可以帮助我了解如何通过每年并行运行吗?
同时运行两个脚本(create_yearly_LST_files.sh
和 create_yearly_NDVI_files.sh
)
最佳答案
使用 GNU Parallel:
cd $working_dir
parallel 'cd {}; cdo -f nc2 mergetime *.nc xxx/LST_{}.nc' ::: {2000..2003}
关于bash - 将数组传递给 GNU Parallel 以替换 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50932321/