{"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":"\n
\n
<\/div>\n<\/div>\n\n
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<\/span> and\/or salloc<\/span> commands.<\/p>\n srun<\/span> is a command that simply runs a given command on the HPC cluster. The \u2010\u2010pty<\/span> flag will attach stdio<\/span> and stdout<\/span> to your current terminal, providing an interactive experience.<\/p>\n 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 Using salloc<\/span> can be compared to an sbatch script in the way that the line-by-line execution is handled. The primary difference between salloc<\/span> and sbatch<\/span> is that salloc<\/span> requires interactivity while sbatch<\/span> executes commands one after another.<\/p>\n An interactive job can be submitted by using the srun<\/span> command. However, there are specific arguments you must pass in order to have it become interactive. Here are some common flags you may want to use to request more resources:<\/p>\n Example: Once you are done with an interactive job, all that’s needed to end the job is to either use the exit command or to close your terminal. 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 malloc()<\/span>:<\/p>\n Allocating resources with Slurm is performed in a very similar manner, but there are multiple ways to use the resources you allocate.<\/p>\n The salloc<\/span> command will allocate resources that you specify for further use. The use of salloc<\/span> is: The majority of the flags used when using srun are available here. Some common ones include:<\/p>\n Note: It is not required to input a command into salloc<\/span>. If a command is not provided, then your default shell program will be ran (typically is bash).<\/em><\/p>\n Example: Note: 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 Once resources are allocated, commands can be ran on the allocated resources with the srun<\/span> command. Another way to use the allocated resources is to connect directly to the node containing the allocated resources with ssh<\/span>.<\/p>\n Example: Once you are done with an interactive job, there are two ways to deallocate your resources.<\/p>\n The first method would be to simply exit the subshell with the exit<\/span> command.Understanding srun and salloc<\/h2>\n
\n
Interactive Jobs with srun<\/h2>\n
\nsrun [options] --pty \/bin\/bash<\/code>
\nExample:
\n[abc123@wind]:~$ srun --pty \/bin\/bash
\nsrun: job 9977591 queued and waiting for resources
\nsrun: job 9977591 has been allocated resources
\n[abc123@cn59]:~$ hostname
\ncn59<\/code>
\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\n
\n[abc123@wind]:~$ srun -c 4 --mem=4GB --gres=gpu --pty \/bin\/bash<\/code>
\nNote: If your connection is lost while your job is active, your interactive job will end.<\/em><\/p>\nEnding an Interactive Job With srun<\/h3>\n
\n[abc123@cn59]:~$ exit<\/code><\/p>\nInteractive Jobs with salloc<\/h2>\n
\n
Allocating Resources<\/h3>\n
\nsalloc [options] [command [args]]<\/code>
\nIn the [options]<\/span> section, you MUST<\/em> specify the following resources. Otherwise, the commands you execute will run, but will not have any resources to work with.<\/p>\n\n
\n[abc123@wind]:~$ salloc -c 4 --mem=4GB --gres=gpu
\nsalloc: Granted job allocation <jobid>
\nsalloc: Nodes <nodelist> are ready for job<\/code>
\nOnce you have allocated the resources, you are ready to use them.<\/p>\nUsing Allocated Resources – srun<\/h3>\n
\n[abc123@wind]:~$ salloc -c1 --mem=4G
\nsalloc: Granted job allocation 9991364
\nsalloc: Nodes cn69 are ready for job
\n[abc123@wind]:~$ srun hostname
\ncn69
\n[abc123@wind]:~$ srun hostname
\ncn69
\n[abc123@wind]:~$ srun hostname
\ncn69<\/code><\/p>\nUsing Allocated Resources – ssh<\/h3>\n
\n[abc123@wind]:~$ salloc -c 4 --mem=4G
\nsalloc: Granted job allocation 9991277
\nsalloc: Nodes cn69 are ready for job
\n[abc123@wind]:~$ ssh cn69
\n[abc123@cn69]:~$ hostname
\ncn69<\/code>
\nOnce you see that the prompt shows a compute node, then you are ready to run your programs.<\/p>\nDeallocating salloc Resources<\/h3>\n
\n[abc123@wind]:~$ exit
\nexit
\nsalloc: Relinquishing job allocation 10027941
\n[abc123@wind]:~$<\/code>
\nHowever, if this method is unavailable, another method would be to run the scancel<\/span> command:
\n[abc123@cn51]:~$ exit
\nlogout
\nConnection to cn51 closed.
\n[abc123@wind]:~$ scancel 9991298
\nsalloc: Job allocation 9991298 has been revoked.<\/code>
\nNote: If you run the scancel<\/span> command while inside the salloc<\/span> subshell, you will remain in the subshell but will no longer have the resources provided by salloc<\/span>.<\/em><\/p>\nExample: Running Matlab in an Interactive Job<\/h2>\n