<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Hi Hafedh,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Your job script has the sbatch directive “—gpus-per-node=4” set.  I suspect that if you look at what’s allocated to the running job by doing “scontrol show job <jobid>” and
 looking at the TRES field, it’s been allocated 4 GPUs instead of one.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">                --Troy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> slurm-users <slurm-users-bounces@lists.schedmd.com>
<b>On Behalf Of </b>Kherfani, Hafedh (Professional Services, TC)<br>
<b>Sent:</b> Thursday, January 18, 2024 9:38 AM<br>
<b>To:</b> Slurm User Community List <slurm-users@lists.schedmd.com><br>
<b>Subject:</b> Re: [slurm-users] Need help with running multiple instances/executions of a batch script in parallel (with NVIDIA HGX A100 GPU as a Gres)<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">Hi Noam and Matthias, Thanks both for your answers. I changed the “#SBATCH --gres=gpu:</span><span style="font-size:1.0pt;font-family:"Arial",sans-serif;color:white"> </span><span style="font-size:1.0pt;color:white">4</span><span style="font-size:1.0pt;color:white">“</span><span style="font-size:1.0pt;color:white">
 directive (in the batch script) with </span><span style="font-size:1.0pt;color:white">“</span><span style="font-size:1.0pt;color:white">#SBATCH --gres=gpu:</span><span style="font-size:1.0pt;font-family:"Arial",sans-serif;color:white"> </span><span style="font-size:1.0pt;color:white">1</span><span style="font-size:1.0pt;color:white">“</span><span style="font-size:1.0pt;color:white">
 as you suggested, but it didn</span><span style="font-size:1.0pt;color:white">’</span><span style="font-size:1.0pt;color:white">t make a difference, as running
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white"></span><span style="font-size:1.0pt;font-family:"Calibri",sans-serif;color:white"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="FR" style="font-size:11.0pt">Hi Noam and Matthias,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks both for your answers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I changed the “#SBATCH --gres=gpu:4“ directive (in the batch script) with “#SBATCH --gres=gpu:1“ as you suggested, but it didn’t make a difference, as running this batch script 3 times will result in the first
 job to be in a running state, while the second and third jobs will still be in a pending state …
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ cat gpu-job.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#!/bin/bash<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --job-name=gpu-job<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --partition=gpu<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --nodes=1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --gpus-per-node=4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --gres=gpu:1                            # <<<< Changed from ‘4’ to ‘1’
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --tasks-per-node=1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --output=gpu_job_output.%j  
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#SBATCH --error=gpu_job_error.%j    
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">hostname<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">date<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">sleep 40<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">pwd<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ sbatch gpu-job.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Submitted batch job <b>217</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ squeue<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">             JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">               217       gpu  gpu-job slurmtes  R       0:02      1 c-a100-cn01<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ sbatch gpu-job.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Submitted batch job <b>218</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ sbatch gpu-job.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Submitted batch job <b>219</b><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[slurmtest@c-a100-master test-batch-scripts]$ squeue<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">             JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">               219       gpu  gpu-job slurmtes
<b>PD</b>       0:00      1 (Priority)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">               218       gpu  gpu-job slurmtes
<b>PD</b>       0:00      1 (Resources)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">               217       gpu  gpu-job slurmtes 
<b>R</b>       0:07      1 c-a100-cn01<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Basically I’m seeking for some help/hints on how to tell Slurm, from the batch script for example: “I want only 1 or 2 GPUs to be used/consumed by the job”, and then I run the batch script/job a couple of
 times with sbatch command, and confirm that we can indeed have multiple jobs using a GPU and running in parallel, at the same time.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Makes sense ? <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black;mso-ligatures:standardcontextual">Best regards,<o:p></o:p></span></p>
<p class="MsoNormal" style="page-break-after:avoid"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></b></p>
<p class="MsoNormal" style="page-break-after:avoid"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">Hafedh
</span></b><span lang="EN-GB" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:standardcontextual"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="FR"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> slurm-users <<a href="mailto:slurm-users-bounces@lists.schedmd.com">slurm-users-bounces@lists.schedmd.com</a>>
<b>On Behalf Of </b>Bernstein, Noam CIV USN NRL (6393) Washington DC (USA)<br>
<b>Sent:</b> jeudi 18 janvier 2024 2:30 PM<br>
<b>To:</b> Slurm User Community List <<a href="mailto:slurm-users@lists.schedmd.com">slurm-users@lists.schedmd.com</a>><br>
<b>Subject:</b> Re: [slurm-users] Need help with running multiple instances/executions of a batch script in parallel (with NVIDIA HGX A100 GPU as a Gres)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="FR"><o:p> </o:p></span></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span lang="FR">On Jan 18, 2024, at 7:31 AM, Matthias Loose <<a href="mailto:m.loose@mindcode.de">m.loose@mindcode.de</a>> wrote:<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="FR"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span lang="FR">Hi Hafedh,<br>
<br>
Im no expert in the GPU side of SLURM, but looking at you current configuration to me its working as intended at the moment. You have defined 4 GPUs and start multiple jobs each consuming 4 GPUs each. So the jobs wait for the ressource the be free again.<br>
<br>
I think what you need to look into is the MPS plugin, which seems to do what you are trying to achieve:<br>
<a href="https://urldefense.com/v3/__https:/slurm.schedmd.com/gres.html*MPS_Management__;Iw!!KGKeukY!y8lBvIzVTUcjaJKXNVaSGxEyG-AgFP9NRgOW7uAUJNfWzKHN1Bc9YwXNuwlXGigW0JBn6IzA-XrgVsuHFf2E$">https://slurm.schedmd.com/gres.html#MPS_Management</a><o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span lang="FR"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span lang="FR">I agree with the first paragraph.  How many GPUs are you expecting each job to use? I'd have assumed, based on the original text, that each job is supposed to use 1 GPU, and the 4 jobs were supposed to be running side-by-side
 on the one node you have (with 4 GPUs).  If so, you need to tell each job to request only 1 GPU, and currently each one is requesting 4.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="FR"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="FR">If your jobs are actually supposed to be using 4 GPUs each, I still don't see any advantage to MPS (at least in what is my usual GPU usage pattern): all the jobs will take longer to finish, because they are sharing the fixed
 resource. If they take turns, at least the first ones finish as fast as they can, and the last one will finish no later than it would have if they were all time-sharing the GPUs.  I guess NVIDIA had something in mind when they developed MPS, so I guess our
 pattern may not be typical (or at least not universal), and in that case the MPS plugin may well be what you need.<o:p></o:p></span></p>
</div>
</div>
</body>
</html>