Bashを使用して、プロセッサの複数のコアで同じプログラムを実行します。

Bashを使用して、プロセッサの複数のコアで同じプログラムを実行します。

私は8つのコアプロセッサを持ち、1つのインスタンスに対してC ++バイナリを実行する3つのコアに対して一連の実験を実行したいと思います。 Bashを使用して並列化できますが、コア数を3に制限することはできません。

これは私のbashスクリプトです。


run_graph_algo1(){
  ./../bin/graph_algo1_cpp "$1" > "${1}.algo1.log"
}
 

for file in *.txt
do
     run_graph_algo1 "$file" &
done

wait
echo "All Instances have finsihed running."

重要な場合はMacOSを使用し、追加のライブラリは使用しません。ありがとうございます!

ベストアンサー1

GNUパラレルがある場合:

run_graph_algo1(){
  ./../bin/graph_algo1_cpp "$1" > "${1}.algo1.log"
}
export -f  run_graph_algo1

parallel -j3 run_graph_algo1 ::: *.txt

echo "All Instances have finsihed running."

GNU Parallelはこのような作業のために作られています。

おすすめ記事