Apptainer/en: Difference between revisions

Jump to navigation Jump to search
Updating to match new version of source page
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 81: Line 81:
Another important option is the <code>-W</code> or <code>--workdir</code> option. On our clusters and on most Linux systems, <code>/tmp</code> and similar filesystems use RAM, not disk space. Since jobs typically run on our clusters with limited RAM amounts, this can result in jobs getting killed because they consume too much RAM relative to what was requested for the job. A suitable workaround for this is to tell Apptainer to use a real disk location for its working directory (<code>workdir</code>). This is done by passing the <code>-W</code> option followed by a path to a disk location where Apptainer can read/write temporary files For example, to run a command called <code>myprogram</code> in an Apptainer container image called <code>myimage.sif</code> with its working directory set to <code>/path/to/a/workdir</code> in the filesystem, you would use
Another important option is the <code>-W</code> or <code>--workdir</code> option. On our clusters and on most Linux systems, <code>/tmp</code> and similar filesystems use RAM, not disk space. Since jobs typically run on our clusters with limited RAM amounts, this can result in jobs getting killed because they consume too much RAM relative to what was requested for the job. A suitable workaround for this is to tell Apptainer to use a real disk location for its working directory (<code>workdir</code>). This is done by passing the <code>-W</code> option followed by a path to a disk location where Apptainer can read/write temporary files For example, to run a command called <code>myprogram</code> in an Apptainer container image called <code>myimage.sif</code> with its working directory set to <code>/path/to/a/workdir</code> in the filesystem, you would use


<source lang="console">$ mkdir -p $HOME/aworkdir
<source lang="console">apptainer run -C -B /project -W /path/to/a/workdir myimage.sif myprogram</source>
$ apptainer run -C -B /home -W /path/to/a/workdir myimage.sif myprogram</source>


where:
where:
Line 145: Line 144:
* <code>g++ -O2 -march=broadwell ./myprog.cpp</code> is the command you want to run inside the container
* <code>g++ -O2 -march=broadwell ./myprog.cpp</code> is the command you want to run inside the container


On our clusters, you will want to use a number of additional options (that appear after <code>run</code>, but before <code>your-container-name.sif</code>). These options will include <code>-C</code>, <code>-c</code>, <code>-e</code>, <code>-W</code> as well as various bind mount options to make your disk space available to the programs that run in your container. For example:
On our clusters, you will want to use a number of additional options (that appear after <code>run</code>, but before <code>your-container-name.sif</code>). These options include <code>-C</code>, <code>-c</code>, <code>-e</code>, <code>-W</code> as well as various bind mount options to make your disk space available to the programs that run in your container. For example:


   apptainer run -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
   apptainer run -C -W $SLURM_TMPDIR -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
   apptainer run -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch ./a.out
   apptainer run -C -W $SLURM_TMPDIR -B /project -B /scratch ./a.out


For more information on these options see the following sections on this page:
For more information on these options see the following sections on this page:
Line 222: Line 221:
While one can have multiple bind mounts specified, it is often easier to specify the top directories of the filesystems one wishes to access. For example, on our clusters one might want to use
While one can have multiple bind mounts specified, it is often easier to specify the top directories of the filesystems one wishes to access. For example, on our clusters one might want to use


  apptainer run -C -B /home -B /project -B /scratch -W $SLURM_TMPDIR a-container.sif wc -l ./my_data_file.txt
  apptainer run -C -B /project -B /scratch -W $SLURM_TMPDIR a-container.sif wc -l ./my_data_file.txt


where:
where:
* <code>-B /home</code> mounts the home filesystem
* <code>-B /project</code> mounts the project filesystem
* <code>-B /project</code> mounts the project filesystem
* <code>-B /scratch</code> mounts the scratch filesystem
* <code>-B /scratch</code> mounts the scratch filesystem
38,760

edits

Navigation menu