这是我的bash密码。
#!/bin/bash
#aggrs=(gcnconv gatconv sageconv ginconv)
aggrs=(gcnconv)
datasets=(HGBn-ACM HGBn-DBLP HGBn-Freebase HGBn-IMDB)
models=(homo_GNN relation_HGNN mp_GNN)
#models=(homo_GNN relation_HGNN)
ran=(1 2)
for aggr in ${aggrs[*]}; do
for i in ${ran[*]}; do
yaml="yamlpath: ${aggr}_${i}.yaml"
echo ${yaml}
# python space4hgnn/generate_yaml.py -a ${aggr} -s ${i}
for dataset in ${datasets[*]}; do
for model in ${models[*]}; do
{
para="-a ${aggr} -s ${i} -m ${model} -d ${dataset} -g $1 -t node_classification"
echo ${para}
# python run.py ${para}
}&
done
done
done
done
wait在我的代码中有很多for循环,但我只想并行执行最内部的for循环。但是我发现输出都是并行执行的。
产出:
yamlpath: gcnconv_1.yaml
-a gcnconv -s 1 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-Freebase -g -t node_classification
yamlpath: gcnconv_2.yaml
-a gcnconv -s 1 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-IMDB -g -t node_classification显然,最外层for循环中的代码也是并行执行的。
我想知道是否有一种方法可以并行地执行最内部的for循环中的代码?
输出可能如下:
yamlpath: gcnconv_1.yaml
-a gcnconv -s 1 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-IMDB -g -t node_classification
yamlpath: gcnconv_2.yaml
-a gcnconv -s 2 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-IMDB -g -t node_classification 有什么解决办法吗?还是有其他方法来达到我想要的结果?
谢谢你的帮忙!
发布于 2021-09-03 11:52:29
您可以在最内部的wait循环之后:
for model in ${models[*]}; do
{
para="-a ${aggr} -s ${i} -m ${model} -d ${dataset} -g $1 -t node_classification"
echo ${para}
python run.py ${para}
}&
done
wait发布于 2021-09-03 11:50:31
对不起,输出可能是这样的:
yamlpath: gcnconv_1.yaml
-a gcnconv -s 1 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 1 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 1 -m mp_GNN -d HGBn-IMDB -g -t node_classification
yamlpath: gcnconv_2.yaml
-a gcnconv -s 2 -m homo_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-ACM -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-DBLP -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-Freebase -g -t node_classification
-a gcnconv -s 2 -m homo_GNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m relation_HGNN -d HGBn-IMDB -g -t node_classification
-a gcnconv -s 2 -m mp_GNN -d HGBn-IMDB -g -t node_classification 发布于 2021-09-03 12:01:15
仅并行运行最内部的for循环。
只是:
for dataset in ${datasets[*]}; do
for model in ${models[*]}; do
para="-a ${aggr} -s ${i} -m ${model} -d ${dataset} -g $1 -t node_classification"
echo ${para}
done &
done输出可能如下所示:
并行运行并不同步输出。你可以:
for dataset in ${datasets[*]}; do
for model in ${models[*]}; do
para="-a ${aggr} -s ${i} -m ${model} -d ${dataset} -g $1 -t node_classification"
echo ${para}
done > "${dataset}_output.txt" &
done
....
for dataset in ${datasets[*]}; do
cat "${dataset}_output.txt"
rm "${dataset}_output.txt"
done这样,输出就会同步。
https://stackoverflow.com/questions/69044382
复制相似问题