{"id":3439,"date":"2024-04-25T13:27:04","date_gmt":"2024-04-25T20:27:04","guid":{"rendered":"https:\/\/in.nau.edu\/arc\/?page_id=3439"},"modified":"2024-08-14T09:05:25","modified_gmt":"2024-08-14T16:05:25","slug":"interactive-jobs","status":"publish","type":"page","link":"https:\/\/in.nau.edu\/arc\/overview\/using-the-cluster-advanced\/interactive-jobs\/","title":{"rendered":"Interactive Jobs"},"content":{"rendered":"<!-- shortcode-right-column -->\n<div class=\"shortcode-right-column\" >\n    <div class=\"shortcode-right-column__container\"><\/p>\n<p><!-- shortcode-contact -->\n<div class=\"shortcode-contact\">\n    <div class=\"contact-header\">\n        <h3>Contact Advanced Research Computing<\/h3>\n    <\/div>\n    <div class=\"contact-body\">\n                <a href=\"mailto:ask-arc@nau.edu\" aria-label=\"Contact Advanced Research Computing: Email Address\" title=\"Email Address\">\n            <div class=\"contact-icon-container\">\n                <i class=\"fas fa-envelope\" aria-hidden=\"true\"><\/i>\n                <span class=\"sr-only\">Email:<\/span>\n            <\/div>\n            <div class=\"contact-email\">ask-arc&#8203;@nau.edu<\/div>\n        <\/a>\n                    <\/div>\n<\/div>\n\n<\/p>\n<p><\/div>\n<\/div>\n\n<h1>Interactive Jobs<\/h1>\n<p>In addition to standard batch job use of compute resources via a slurm job script, researchers have access to to compute resources in an interactive mode as well by utilizing <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">srun<\/span> and\/or <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> commands.<\/p>\n<h2>Understanding srun and salloc<\/h2>\n<p><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">srun<\/span> is a command that simply runs a given command on the HPC cluster. The <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010pty<\/span> flag will attach <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">stdio<\/span> and <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">stdout<\/span> to your current terminal, providing an interactive experience.<\/p>\n<p><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> is a command that allows you to simply allocate resources on the cluster for you to do whatever with. The typical flow for using this is:<\/p>\n<ol>\n<li>Allocate HPC resources<\/li>\n<li>Use the HPC resources with srun or ssh<\/li>\n<li>Deallocate HPC resources<\/li>\n<\/ol>\n<p>Using <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> can be compared to an sbatch script in the way that the line-by-line execution is handled. The primary difference between <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> and <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">sbatch<\/span> is that <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> requires interactivity while <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">sbatch<\/span> executes commands one after another.<\/p>\n<h2>Interactive Jobs with srun<\/h2>\n<p>An interactive job can be submitted by using the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">srun<\/span> command. However, there are specific arguments you must pass in order to have it become interactive.<br \/>\n<code>srun [options] --pty \/bin\/bash<\/code><br \/>\nExample:<br \/>\n<code>[abc123@wind]:~$ srun --pty \/bin\/bash<br \/>\nsrun: job 9977591 queued and waiting for resources<br \/>\nsrun: job 9977591 has been allocated resources<br \/>\n[abc123@cn59]:~$ hostname<br \/>\ncn59<\/code><br \/>\nThis will start a job via Slurm to run bash and connect your terminal session over to the new bash instance. However, using the srun command without any additional provisioning arguments will run your job with the default job resource allocations and time limits.<\/p>\n<p>Here are some common flags you may want to use to request more resources:<\/p>\n<ul>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">-c [num]<\/span>: Number of CPU cores to allocate.<\/li>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010mem=[size]<\/span>: Amount of memory to allocate. Size can be filled as a human-readable format, such as 5GB for 5 Gigabytes.<\/li>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010gres=[list]<\/span>: List of specific resources to request, separated by a colon &#8216;:&#8217;. View our page on <a href=\"https:\/\/servicenow.nau.edu\/sp?id=kb_article&amp;article=KB0018520\">GPU-Accelerated Jobs<\/a> for valid entries.<\/li>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010x11<\/span>: Enables X11 forwarding. See our page on <a href=\"https:\/\/in.nau.edu\/arc\/x11-forwarding\/\">X11 forwarding<\/a> to set it up.<\/li>\n<\/ul>\n<p>Example:<br \/>\n<code>[abc123@wind]:~$ srun -c 4 --mem=4GB --gres=gpu --pty \/bin\/bash<\/code><br \/>\n<em>Note: If your connection is lost while your job is active, your interactive job will end.<\/em><\/p>\n<h3>Ending an Interactive Job With srun<\/h3>\n<p>Once you are done with an interactive job, all that&#8217;s needed to end the job is to either use the exit command or to close your terminal.<br \/>\n<code>[abc123@cn59]:~$ exit<\/code><\/p>\n<h2>Interactive Jobs with salloc<\/h2>\n<p>If you are familiar with certain low-level programming languages such as C, you may be familiar with the typical memory allocation flow when using <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">malloc()<\/span>:<\/p>\n<ol>\n<li>Allocate the memory<\/li>\n<li>Use the memory<\/li>\n<li>Deallocate the memory when done<\/li>\n<\/ol>\n<p>Allocating resources with Slurm is performed in a very similar manner, but there are multiple ways to use the resources you allocate.<\/p>\n<h3>Allocating Resources<\/h3>\n<p>The <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> command will allocate resources that you specify for further use. The use of <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> is:<br \/>\n<code>salloc [options] [command [args]]<\/code><br \/>\nIn the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">[options]<\/span> section, you <em>MUST<\/em> specify the following resources. Otherwise, the commands you execute will run, but will not have any resources to work with.<\/p>\n<p>The majority of the flags used when using srun are available here. Some common ones include:<\/p>\n<ul>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">-c [num]<\/span>: Number of CPU cores to allocate.<\/li>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010mem=[size]<\/span>: Amount of memory to allocate. Size can be filled as a human-readable format, such as 5GB for 5 Gigabytes.<\/li>\n<li><span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">\u2010\u2010gres=[list]<\/span>: List of specific resources to request, separated by a colon <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">:<\/span>. View our page on <a href=\"https:\/\/servicenow.nau.edu\/sp?id=kb_article&amp;article=KB0018520\">GPU-Accelerated Jobs<\/a> for valid entries.<\/li>\n<\/ul>\n<p><em>Note: It is not required to input a command into <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span>. If a command is not provided, then your default shell program will be ran (typically is bash).<\/em><\/p>\n<p>Example:<br \/>\n<code>[abc123@wind]:~$ salloc -c 4 --mem=4GB --gres=gpu<br \/>\nsalloc: Granted job allocation &lt;jobid&gt;<br \/>\nsalloc: Nodes &lt;nodelist&gt; are ready for job<\/code><br \/>\nOnce you have allocated the resources, you are ready to use them.<\/p>\n<p><em>Note: <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> will bring you into a nested bash shell on a login node. If you exit this shell normally, then the resources will immediately be deallocated.<\/em><\/p>\n<h3>Using Allocated Resources &#8211; srun<\/h3>\n<p>Once resources are allocated, commands can be ran on the allocated resources with the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">srun<\/span> command.<br \/>\n<code>[abc123@wind]:~$ salloc -c1 --mem=4G<br \/>\nsalloc: Granted job allocation 9991364<br \/>\nsalloc: Nodes cn69 are ready for job<br \/>\n[abc123@wind]:~$ srun hostname<br \/>\ncn69<br \/>\n[abc123@wind]:~$ srun hostname<br \/>\ncn69<br \/>\n[abc123@wind]:~$ srun hostname<br \/>\ncn69<\/code><\/p>\n<h3>Using Allocated Resources &#8211; ssh<\/h3>\n<p>Another way to use the allocated resources is to connect directly to the node containing the allocated resources with <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">ssh<\/span>.<\/p>\n<p>Example:<br \/>\n<code>[abc123@wind]:~$ salloc -c 4 --mem=4G<br \/>\nsalloc: Granted job allocation 9991277<br \/>\nsalloc: Nodes cn69 are ready for job<br \/>\n[abc123@wind]:~$ ssh cn69<br \/>\n[abc123@cn69]:~$ hostname<br \/>\ncn69<\/code><br \/>\nOnce you see that the prompt shows a compute node, then you are ready to run your programs.<\/p>\n<h3>Deallocating salloc Resources<\/h3>\n<p>Once you are done with an interactive job, there are two ways to deallocate your resources.<\/p>\n<p>The first method would be to simply exit the subshell with the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">exit<\/span> command.<br \/>\n<code>[abc123@wind]:~$ exit<br \/>\nexit<br \/>\nsalloc: Relinquishing job allocation 10027941<br \/>\n[abc123@wind]:~$<\/code><br \/>\nHowever, if this method is unavailable, another method would be to run the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">scancel<\/span> command:<br \/>\n<code>[abc123@cn51]:~$ exit<br \/>\nlogout<br \/>\nConnection to cn51 closed.<br \/>\n[abc123@wind]:~$ scancel 9991298<br \/>\nsalloc: Job allocation 9991298 has been revoked.<\/code><br \/>\n<em>Note: If you run the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">scancel<\/span> command while inside the <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span> subshell, you will remain in the subshell but will no longer have the resources provided by <span style=\"font-size: 16px; font-family: monospace; border: 1px solid; border-radius: 4px; padding: 0px 4px 0px; border-color: #BBBBBB;\">salloc<\/span>.<\/em><\/p>\n<h2>Example: Running Matlab in an Interactive Job<\/h2>\n<p>This example shows that you can have GUI applications run in an interactive job. For this to work, you must have <a href=\"https:\/\/in.nau.edu\/arc\/x11-forwarding\/\">X11 forwarding<\/a> set up.<\/p>\n<h3>Using srun<\/h3>\n<p><code>[abc123@wind]:~$ srun -c4 --mem=4GB --x11 --pty bash<br \/>\n[abc123@cn51]:~$ module load matlab<br \/>\n[abc123@cn51]:~$ matlab<br \/>\nMATLAB is selecting SOFTWARE OPENGL rendering.<br \/>\n[abc123@cn51]:~$ exit<br \/>\nexit<br \/>\n[abc123@wind]:~$<\/code><\/p>\n<h3>Using salloc<\/h3>\n<p><code>[abc123@wind]:~$ salloc -c4 --mem=4GB<br \/>\nsalloc: Granted job allocation 9991312<br \/>\nsalloc: Nodes cn51 are ready for job<br \/>\n[abc123@cn51]:~$ module load matlab<br \/>\n[abc123@cn51]:~$ matlab<br \/>\nMATLAB is selecting SOFTWARE OPENGL rendering.<br \/>\n[abc123@cn51]:~$ exit<br \/>\nexit<br \/>\nConnection to cn51 closed.<br \/>\n[abc123@wind]:~$ scancel 9991312<br \/>\nsalloc: Job allocation 9991312 has been revoked.<\/code><br \/>\n<img decoding=\"async\" class=\"alignnone wp-image-3452 size-landscape-image\" src=\"https:\/\/in.nau.edu\/wp-content\/uploads\/sites\/208\/Screenshot-from-2024-04-26-16-20-43-obfuscated.png\" alt=\"Demonstration image of MatLab GUI running over X11-Forwarding\" width=\"800\" srcset=\"https:\/\/in.nau.edu\/wp-content\/uploads\/sites\/208\/Screenshot-from-2024-04-26-16-20-43-obfuscated.png 1393w, https:\/\/in.nau.edu\/wp-content\/uploads\/sites\/208\/Screenshot-from-2024-04-26-16-20-43-obfuscated-768x533.png 768w, https:\/\/in.nau.edu\/wp-content\/uploads\/sites\/208\/Screenshot-from-2024-04-26-16-20-43-obfuscated-600x417.png 600w, https:\/\/in.nau.edu\/wp-content\/uploads\/sites\/208\/Screenshot-from-2024-04-26-16-20-43-obfuscated-300x208.png 300w\" sizes=\"(max-width: 1393px) 100vw, 1393px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interactive Jobs In addition to standard batch job use of compute resources via a slurm job script, researchers have access to to compute resources in an interactive mode as well by utilizing srun and\/or salloc commands. Understanding srun and salloc srun is a command that simply runs a given command on the HPC cluster. The [&hellip;]<\/p>\n","protected":false},"author":2758,"featured_media":0,"parent":71,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","ring_central_script_selection":"","footnotes":""},"class_list":["post-3439","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/pages\/3439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/users\/2758"}],"replies":[{"embeddable":true,"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/comments?post=3439"}],"version-history":[{"count":16,"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/pages\/3439\/revisions"}],"predecessor-version":[{"id":3606,"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/pages\/3439\/revisions\/3606"}],"up":[{"embeddable":true,"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/pages\/71"}],"wp:attachment":[{"href":"https:\/\/in.nau.edu\/arc\/wp-json\/wp\/v2\/media?parent=3439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}