7. Cooperation with job scheduler

As we’ve seen, running an application with Singularity doesn’t really need to be aware that it’s a container. In particular, the image with %runscript set can be executed as an application as it is. Therefore, nothing special is required to execute a job using the scheduler. In other container implementations such as docker, the environment is separated between the container and the host side, and it is necessary to consider the start of the container and the start of the application in it separately, which may cause difficulty in cooperation.

Also, being able to embed run-time processing and settings in an image means that routine processing can be used without writing it in a job script or command line. This prevents script writing mistakes and contributes to ease of support when sharing apps.

7.1. Simple execution

As shown below, specify the image that built the environment, write the description to execute the command in the job script, and submit it.

$ cat job.sh
#!/bin/bash
#PJM -L "node=1"
#PJM -L "rscunit=rscunit_ft01"
#PJM -L "rscgrp=small"
#PJM -L "elapse=15:00"

export OMP_NUM_THREADS=8
export MYCODE_CONFIG=/usr/share/MyApps/config.json
singularity exec ~/ubuntu2004.sif python3 ~/mycode/test.py

$ pjsub ./job.sh

In this example, a container is launched with an image of my Ubuntu 20.04 environment using the image in my home directory, and running mycode/test.py in python3, which is also in my home directory.

7.2. Embedding the execution method in the image

You can make your job script even simpler by setting %environment and %runscript as you set in the image creation above and incorporating more of the description into the image. For example, suppose you create an sif image using the following definition file.

Bootstrap: docker
From: ubuntu:focal

%environment
    export OMP_NUM_THEADS=8
    export MYCODE_CONFIG=/usr/share/MyApps/hoge.json

%runscript
    cat $MYCODE_CONFIG
    python3 /usr/share/MyApps/hoge.py $*

Save the created SIF image with the file name 'hoge' into a directory included in command PATH. Singularity set executable attributes by default when creating a SIF image, but be sure to check. the job script can be described as follows.

$ cat job.sh
#!/bin/bash
#PJM -L "node=1"
#PJM -L "rscunit=rscunit_ft01"
#PJM -L "rscgrp=small"
#PJM -L "elapse=15:00"

hoge input.txt

$ pjsub ./job.sh

At this point, users may feel that they are using the application directly without being aware that they are using Singularity.

7.3. Interactive execution

As we did in the section Creating an image, you can run an interactive job and use the methods introduced so far.

$ pjsub --interact -L "rscunit=rscunit_ft01,rscgrp=int,node=1,elapse=0:30:00"
[INFO] PJM 0000 pjsub Job XXXXXXX submitted.
[INFO] PJM 0081 ..connected.
[INFO] PJM 0082 pjsub Interactive job XXXXXXX started.
[uXXXXX@b31-3208c ~]$ singularity shell ubuntu2004.sif
Singularity>