I have a Bash script in which there is a loop to enter a specific directory and it does a certain calculation on a specific input file. After that, it exits from the directory and does the same thing within another directory with a different input file. The calculation needs a lot of time and I would like to parallelize it.
How I can modify my script? Is there an option an option to do that?
myscript.sh
cd MainDir
for dir in *
do
cd ${dir}
LD_LIBRARY_PATH="$software"/ "$software"/calc -i /home/files/"$dir.txt" -l /home/Str/Art.pdb -a 5.0 -rf /home/file/prot -cpu 1 opt -w ${dir}_res > ${dir}_WPA.log
cd ..
done
I use the command -cpu to indicate how cpu use. I have many CPUs to use so how can I parallelize more jobs?
e.g If I have three different input files I would like to run (in adifferent directory) together the following command:
cd 1
LD_LIBRARY_PATH="$software"/ "$software"/calc -i /home/files/1.txt -l /home/Str/Art.pdb -a 5.0 -rf /home/file/prot -cpu 1 opt -w 1_res > 1_WPA.log
-----------
cd 2
LD_LIBRARY_PATH="$software"/ "$software"/calc -i /home/files/2.txt -l /home/Str/Art.pdb -a 5.0 -rf /home/file/prot -cpu 1 opt -w 2_res > 2_WPA.log
-----------
cd 3
LD_LIBRARY_PATH="$software"/ "$software"/calc -i /home/files/3.txt -l /home/Str/Art.pdb -a 5.0 -rf /home/file/prot -cpu 1 opt -w 3_res > 3_WPA.log
Could someone help me please? Thanks.
-cpu 1
? – Philip Couling May 04 '22 at 17:14for dir in */
to ensure that it only matches directories, not any regular files that might be in your MainDir (and yes, you might be certain that there aren't any regular files in there at this moment in time...but you should still program defensively because things can change and that might not always be true). Also, curly braces are not a substitute for quotes. See $VAR vs ${VAR} and to quote or not to quote – cas May 05 '22 at 02:56