This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create new run_jobs.sh file | |
echo "#!/bin/bash" > run_jobs.sh | |
# Add entries for each permutation (1-1000) in groups of 8 (ie: number of cores) | |
for i in {1..125} | |
do | |
for j in {7..0} | |
do | |
echo "python permutation.py $(($i*8-$j)) &" >> run_jobs.sh | |
done | |
echo "wait" >> run_jobs.sh | |
done | |
# Submit program | |
qsub -l nodes=1,walltime=4:00:00 run_jobs.sh | |
wait | |
# Remove run list | |
rm run_jobs.sh |
This will run a script with the following commands:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
python permutation.py 1 & | |
python permutation.py 2 & | |
python permutation.py 3 & | |
python permutation.py 4 & | |
python permutation.py 5 & | |
python permutation.py 6 & | |
python permutation.py 7 & | |
python permutation.py 8 & | |
wait | |
python permutation.py 9 & | |
python permutation.py 10 & | |
python permutation.py 11 & | |
python permutation.py 12 & | |
python permutation.py 13 & | |
python permutation.py 14 & | |
python permutation.py 15 & | |
python permutation.py 16 & | |
wait | |
... | |
... | |
... | |
... | |
... | |
... | |
... | |
... | |
wait | |
python permutation.py 993 & | |
python permutation.py 994 & | |
python permutation.py 995 & | |
python permutation.py 996 & | |
python permutation.py 997 & | |
python permutation.py 998 & | |
python permutation.py 999 & | |
python permutation.py 1000 & | |
wait |
There is one more thing you can do:
ReplyDeleteLets say you are doing 800 permutations and you have 1 node with 8 cores. to make it more efficient you can put 100 commands "; separated" on 8 lines and then put wait at the end of 8 lines. this way you won't wait for every 8 commands to finish, but wait only once at the end. if all the permutations are taking the same time then what you have done is good, but if they takes unequal amount of time, this little trick can save some more time.
Good tip, but I think parallelization is much easier to achieve using Linux Makefiles.
ReplyDeleteGreat tip, Christian! Can you provide a link in the comments to a resource on how to do the Linux makefiles approach? Thanks.
Delete