{"id":7719,"date":"2022-01-18T16:26:21","date_gmt":"2022-01-18T16:26:21","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=7719"},"modified":"2022-02-01T17:36:50","modified_gmt":"2022-02-01T17:36:50","slug":"simplify-your-life-with-slurm-and-sync","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2022\/01\/simplify-your-life-with-slurm-and-sync\/","title":{"rendered":"Simplify your life with SLURM and sync"},"content":{"rendered":"\n<p>For my first blog post of the year, we&#8217;re talking about SLURM, everyone&#8217;s favorite job manager. If like me, you have the joy of running a literal boat-load of jobs with all kinds of parameters and command-line arguments you\u2019ll know there are a few tips and tricks that make the process of managing these tasks and results as painless as possible. Now, I do expect most people reading this will already be aware of these tricks but for those who don\u2019t, I hope this is helpful. After all, it\u2019s impossible to know what you don\u2019t know you need to know, you know? Any alternatives, improvements, or suggestions are welcome!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"array-jobs\"><strong>Array Jobs<\/strong><\/h2>\n\n\n\n<p>Job arrays are perfect for the times you want to run the same job several times with slight differences each time. Imagine you need to repeat a job 10 times with slightly different arguments with each run. Rather than submit 10 (slightly different) batch scripts you can submit 1 script with all the information needed to complete all 10 jobs.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>To do this, include the array command either when submitting the job:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sbatch --array=0-9%2 example_slurm_script.sh<\/pre>\n\n\n\n<p>or in the slurm script itself:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#SBATCH --array=0-9%2<\/pre>\n\n\n\n<p>In the examples above the slurm script will run 10 jobs (0 to 9) but will only ever run 2 at a time (denoted by the %2) so you don\u2019t hog all the resources. Besides a range of jobs to run, you can also provide a list of indexes. This is useful if you only need to run a selection of jobs.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">batch --array=0,2,4,6%2 example_slurm_script.sh<\/pre>\n\n\n\n<p>In the examples above the slurm script will run 10 jobs (0 to 9) but will only ever run 2 at a time (denoted by the %2) so you don\u2019t hog all the resources. Besides a range of jobs to run, you can also provide a list of indexes. This is useful if you only need to run a selection of jobs.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sbatch --array=0,2,4,6%2 example_slurm_script.sh<\/pre>\n\n\n\n<p>Each time you run submit an array, each job will have a different task ID (SLURM_ARRAY_TASK_ID). This value is unique to each job, unlike the job ID (SLURM_ARRAY_JOB_ID) which is the same for all. Therefore, since each job has a unique SLURM_ARRAY_TASK_ID, you can use it in your slurm script to reference variables you wish to change each time.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># define a dict of parameters (you could also use a list instead).\ndeclare -A dict_1=([0]=10 [1]=20 [2]=30 [3]=40)\ndeclare -A dict_2=([0]=2 [1]=4 [2]=6 [3]=8)\n\nnum_1=${dict_1[${SLURM_ARRAY_TASK_ID}]} #get the number with key equal to task ID.\nnum_2=${dict_2[${SLURM_ARRAY_TASK_ID}]} #get the number with key equal to task ID.\n\npython add_numbers.py $num_1 $num_2 #script adds the two numbers together and prints the results<\/pre>\n\n\n\n<p>In this example, the num_1 and num_2 arguments are referenced from the initial dictionaries and change with the task ID. This is a very simple example but hopefully, you get the idea and this will save you some time moving forward.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rsync\"><strong>Rsync<\/strong><\/h2>\n\n\n\n<p>Life a little easier is rsync. Rsync (remote sync) is is a remote\/local file synchronization tool and allows you to keep a remote and local dir up to date and only send\/receive files that have changed. In almost all cases some kind of version control is the best way to keep your files in check, however, rsync has come in clutch. <br><br>A really simple example use-case below could be used after a job has you have updated a remote copy of a file but would like to sync that with pegasus.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">rysnc -a \/remove\/file\/path.py @:\/local\/file\/path.py<\/pre>\n\n\n\n<p>Rsync has a lot more to offer, I found the linked article very helpful when getting started: [<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-rsync-to-sync-local-and-remote-directories\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-rsync-to-sync-local-and-remote-directories<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my first blog post of the year, we&#8217;re talking about SLURM, everyone&#8217;s favorite job manager. If like me, you have the joy of running a literal boat-load of jobs with all kinds of parameters and command-line arguments you\u2019ll know there are a few tips and tricks that make the process of managing these tasks [&hellip;]<\/p>\n","protected":false},"author":75,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[296,14],"tags":[],"ppma_author":[553],"class_list":["post-7719","post","type-post","status-publish","format-standard","hentry","category-hints-and-tips","category-howto"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":553,"user_id":75,"is_guest":0,"slug":"maranga","display_name":"Maranga Mokaya","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1fdf4dab73e0e7c801c72c921e529f4827e4af020e7f9124bde0a4adc1cb861b?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=7719"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7719\/revisions"}],"predecessor-version":[{"id":7756,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7719\/revisions\/7756"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=7719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=7719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=7719"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=7719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}