diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/BUILD-ARM64.md b/containers/2_ApplicationSpecific/R-Rocker_Project/BUILD-ARM64.md new file mode 100644 index 00000000..a4c9f52d --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/BUILD-ARM64.md @@ -0,0 +1,283 @@ +# Build the R_rocker container on ARM64 + + +## Building the container + +1. Start an interactive job on an ARM64 node + +You can use the `slimits` command to see what accounts and QOS settings you +have access to. + +To find which Slurm account you can use to run an interactive job in the "arm64" +partition: + +``` +slimits | grep "arm64" +``` + +sample output: + +> ``` +> ub-hpc SlurmAccountName CCRusername arm64,debug,general-compute,scavenger,viz +> ``` + +The second field in the Slurm account name, so my test account has access to +the "arm64" partition using the account "SlurmAccountName" + +Set the environment variable "SBATCH_ACCOUNT" to the Slurm account you want +to use. +e.g. + +``` +export SBATCH_ACCOUNT="SlurmAccountName" +``` + +You can now start an interactive job in the "arm64" partition with the +following: + +``` +tmp_file="$(mktemp)" +salloc --partition=arm64 --qos=arm64 --constraint=ARM64 --no-shell \ + --exclusive --time=1:00:00 2>&1 | tee "${tmp_file}" +SLURM_JOB_ID="$(head -1 "${tmp_file}" | awk '{print $NF}')" +rm "${tmp_file}" +srun --jobid="${SLURM_JOB_ID}" --export=HOME,TERM,SHELL --pty /bin/bash --login +``` + +sample outout: + +> ``` +> salloc: Pending job allocation 22171515 +> salloc: job 22171515 queued and waiting for resources +> salloc: job 22171515 has been allocated resources +> salloc: Granted job allocation 22171515 +> salloc: Nodes cpn-f06-38 are ready for job +> CCRusername@cpn-f06-38:~$ +> ``` + +2. Navigate to your build directory and use the Slurm job local temporary directory for cache + + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Then set the apptainer cache dir: + +``` +export APPTAINER_CACHEDIR=${SLURMTMPDIR} +``` + +The `R_rocker_4.5.1.def` file will already be in the directory if you have already built +on the x86_64 platform, if not, download the .def file: + +``` +test -f R_rocker_4.5.1.def || curl -o R_rocker_4.5.1.def https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/R_rocker_4.5.1.def +``` + +sample output: + +> ``` +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 6126 100 6126 0 0 103k 0 --:--:-- --:--:-- --:--:-- 104k +> ``` + + +3. Build your container + +Building the R container takes about ten minutes + +``` +apptainer build --fakeroot R_rocker_4.5.1-$(arch).sif R_rocker_4.5.1.def +``` + +sample truncated output: + +> ``` +> [....] +> INFO: Adding environment to container +> INFO: Creating SIF file... +> INFO: Build complete: R_rocker_4.5.1-aarch64.sif +> ``` + +Quick test of the new container .sif image + +``` +apptainer run \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + R_rocker_4.5.1-$(arch).sif \ + R --version +```` + +Sample output: + +> ``` +> R version 4.5.1 (2025-06-13) -- "Great Square Root" +> Copyright (C) 2025 The R Foundation for Statistical Computing +> Platform: x86_64-pc-linux-gnu +> +> R is free software and comes with ABSOLUTELY NO WARRANTY. +> You are welcome to redistribute it under the terms of the +> GNU General Public License versions 2 or 3. +> For more information about these matters see +> https://www.gnu.org/licenses/. +> +> ``` + +Exit the Slurm interactive session + +``` +exit +``` + +sample output: + +> ``` +> CCRusername@login1$ +> ``` + +End the Slurm job + +``` +scancel "${SLURM_JOB_ID}" +unset SLURM_JOB_ID SBATCH_ACCOUNT +``` + +4. Running the container + +Start an interactive job on an ARM64 node +Notes: + R uses only one core, unless you specifically use functions that take + advantage of multiple cores, such as the 'parallel' package. This example + allocates 6 cores, so apptainer has a thread for itself, plus a thread for + each bind mount, leaving one core for the R process. Request more cores if + you are running parallel code. + + If you use R packages that uses CUDA, add the Slurm directive to request + GPU(s) e.g. "--gpus-per-node=1" and add tht "--nv" opion to apptainer so the + requested GPU(s) are available inside the container. + +Set the Slurm account you want to use for this interactive job (see `slimits` +for the account(s) you can use + +``` +export SBATCH_ACCOUNT="SlurmAccountName" +``` + +You can now start an interactive job in the "arm64" partition with the +following: + +``` +tmp_file="$(mktemp)" +salloc --partition=arm64 --qos=arm64 --constraint=ARM64 --no-shell \ + --nodes=1 --ntasks-per-node=1 --cpus-per-task=6 --mem=32GB \ + --time=1:00:00 2>&1 | tee "${tmp_file}" +SLURM_JOB_ID="$(head -1 "${tmp_file}" | awk '{print $NF}')" +rm "${tmp_file}" +srun --jobid="${SLURM_JOB_ID}" --export=HOME,TERM,SHELL --pty /bin/bash --login +``` + +sample outout: + +> ``` +> salloc: Pending job allocation 22171524 +> salloc: job 22171524 queued and waiting for resources +> salloc: job 22171524 has been allocated resources +> salloc: Granted job allocation 22171524 +> salloc: Nodes cpn-f06-38 are ready for job +> CCRusername@cpn-f06-38:~$ +> ``` + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Start the R container instance + +``` +apptainer shell \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + ./R_rocker_4.5.1-$(arch).sif +``` + +All the following commands are run from the "Apptainer> " prompt +run R + +``` +R +``` + +Sampleoutput: + +> ``` +> +> R version 4.5.1 (2025-06-13) -- "Great Square Root" +> Copyright (C) 2025 The R Foundation for Statistical Computing +> Platform: x86_64-pc-linux-gnu +> +> R is free software and comes with ABSOLUTELY NO WARRANTY. +> You are welcome to redistribute it under certain conditions. +> Type 'license()' or 'licence()' for distribution details. +> +> Natural language support but running in an English locale +> +> R is a collaborative project with many contributors. +> Type 'contributors()' for more information and +> 'citation()' on how to cite R or R packages in publications. +> +> Type 'demo()' for some demos, 'help()' for on-line help, or +> 'help.start()' for an HTML browser interface to help. +> Type 'q()' to quit R. +> +> > +> ``` + +exit R from the ">" prompt with: + +``` +q() +``` + +Expected output + +> ``` +> Apptainer> +> ``` + +Exit the Apptainer container instance +From the "Apptainer>" prompt: + +``` +exit +``` + +sample output: +> ``` +> CCRusername@cpn-d01-39~$ +> ``` + +Exit the Slurm interactive session + +``` +exit +``` + +sample output: + +> ``` +> logout +> CCRusername@login1$ +> ``` + +End the Slurm job + +``` +scancel "${SLURM_JOB_ID}" +unset SLURM_JOB_ID SBATCH_ACCOUNT +``` + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/EXAMPLE.md b/containers/2_ApplicationSpecific/R-Rocker_Project/EXAMPLE.md new file mode 100644 index 00000000..1d7889a3 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/EXAMPLE.md @@ -0,0 +1,132 @@ +# R_rocker Example + +Start an interactive job in the "debug" partition + +You can use the `slimits` command to see what accounts and QOS settings you +have access to. + +To find which Slurm account you can use to run an interactive job in the debug +partition: + +``` +slimits | grep "debug" +``` + +sample output: + +> ``` +> ub-hpc SlurmAccountName CCRusername arm64,debug,general-compute,scavenger,viz +> ``` + +The second field in the Slurm account name, so this example has access to the +"debug" partition using the Slurm account "SlurmAccountName" + +Set the environment variable "SBATCH_ACCOUNT" to the Slurm account you want +to use. +e.g. + +``` +export SBATCH_ACCOUNT="SlurmAccountName" +``` + +You can now start an interactive job in the "debug" partition with the +following: + +``` +tmp_file="$(mktemp)" +salloc --cluster=ub-hpc --partition=debug --qos=debug --no-shell \ + --nodes=1 --cpus-per-task=1 --tasks-per-node=6 --mem=36GB \ + --time=1:00:00 2>&1 | tee "${tmp_file}" +SLURM_JOB_ID="$(head -1 "${tmp_file}" | awk '{print $NF}')" +rm "${tmp_file}" +srun --jobid="${SLURM_JOB_ID}" --export=HOME,TERM,SHELL --pty /bin/bash --login +``` + +sample outout: + +> ``` +> salloc: Pending job allocation 22172066 +> salloc: job 22172066 queued and waiting for resources +> salloc: job 22172066 has been allocated resources +> salloc: Granted job allocation 22172066 +> salloc: Nodes cpn-d01-39 are ready for job +> CCRusername@cpn-d01-39~$ +> ``` + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Start the R container instance + +``` +apptainer shell \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + ./R_rocker_4.5.1-$(arch).sif +``` + +Download the exmaple R script [estimate_pi.R](https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R) +This code is writen by Andrea Gustafsen - see: +https://rpubs.com/andrea_gustafsen/839901 + +``` +test -f estimate_pi.R || curl -o estimate_pi.R https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R +``` + +sample output: + +> ``` +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 874 100 874 0 0 7536 0 --:--:-- --:--:-- --:--:-- 7600 +> ``` + +Run the R script +Note: This script takes about 2 minutes to run, during which there is no output + +``` +Rscript estimate_pi.R +``` + +Sample output: + +> ``` +> 10 100 1000 10000 1e+05 1e+06 1e+07 1e+08 +> 2.400000 3.160000 3.184000 3.158400 3.138760 3.143816 3.141868 3.141650 +> 1e+09 +> 3.141679 +> ``` + +Exit the Apptainer container instance +From the "Apptainer>" prompt: + +``` +exit +``` + +sample output: +> ``` +> CCRusername@cpn-d01-39~$ +> ``` + +Exit the Slurm interactive session + +``` +exit +``` + +sample output: + +> ``` +> CCRusername@login1$ +> ``` + +End the Slurm job + +``` +scancel "${SLURM_JOB_ID}" +unset SLURM_JOB_ID SBATCH_ACCOUNT +``` + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/README.md b/containers/2_ApplicationSpecific/R-Rocker_Project/README.md new file mode 100644 index 00000000..8b76d305 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/README.md @@ -0,0 +1,341 @@ +# Example R container, based on the Rocker Project "r-ver" image + +The [Rocker Project](https://rocker-project.org) provides a number of [GPL 2 or later](https://opensource.org/license/gpl-2-0) licenced ["R" containers](https://rocker-project.org/images/) +This example is based on the [r-ver](https://rocker-project.org/images/versioned/r-ver.html) image which is, in turn, based on the [r-base](https://hub.docker.com/_/r-base) +offical R image +The [r-ver](https://rocker-project.org/images/versioned/r-ver.html) image uses Ubuntu LTS rather than Debian, with an emphasis on +reproducibility. + + +## Building the container + +A brief guide to building the R_rocker container follows:
+Please refer to CCR's [container documentation](https://docs.ccr.buffalo.edu/en/latest/howto/containerization/) for more detailed information on +building and using Apptainer. + +NOTE: for building on the ARM64 platform see [BUILD-ARM64.md](./BUILD-ARM64.md) + +1. Start an interactive job in the "debug" partition + +Apptainer is not available on the CCR login nodes and the compile nodes may not +provide enough resources for you to build a container. We recommend requesting +an interactive job on a compute node to conduct this build process.
+See CCR docs for more info on [running jobs](https://docs.ccr.buffalo.edu/en/latest/hpc/jobs/#interactive-job-submission) + +You can use the `slimits` command to see what accounts and QOS settings you +have access to. +For example, to find the Slurm accoun(s) you can use to run an interactive job +in the "debug" partition: + +``` +slimits | grep "debug" +``` + +sample output: + +> ``` +> ub-hpc SlurmAccountName CCRusername arm64,debug,general-compute,scavenger,viz +> ``` + +The second field in the Slurm account name, so this example has access to the +"debug" partition using the Slurm account "SlurmAccountName" + +Set the environment variable "SALLOC_ACCOUNT" to the Slurm account you want +to use. +e.g. + +``` +export SALLOC_ACCOUNT="SlurmAccountName" +``` + +The following variables will request exclusive use of a "debug" partition node +for an hour with the salloc comand that follows + +``` +export SALLOC_CLUSTERS="ub-hpc" +export SALLOC_PARTITION="debug" +export SALLOC_QOS="debug" +export SALLOC_EXCLUSIVE="" +export SALLOC_MEM_PER_NODE="0" +export SALLOC_TIMELIMIT="01:00:00" +``` + +You can now start an interactive job in the "debug" partition with the +following: + +``` +tmp_file="$(mktemp)" +salloc --nodes=1 --no-shell 2>&1 | tee "${tmp_file}" +SLURM_JOB_ID="$(head -1 "${tmp_file}" | awk '{print $NF}')" +rm "${tmp_file}" +srun --jobid="${SLURM_JOB_ID}" --export=HOME,TERM,SHELL --pty /bin/bash --login +``` + +sample outout: + +> ``` +> salloc: Pending job allocation 22171515 +> salloc: job 22171515 queued and waiting for resources +> salloc: job 22171515 has been allocated resources +> salloc: Granted job allocation 22171515 +> salloc: Nodes cpn-d01-39 are ready for job +> CCRusername@pn-d01-39:~$ +> ``` + +2. Navigate to your build directory and use the Slurm job local temporary directory for cache + +You should now be on the compute node allocated to you. +In this example we're using our project directory for our build directory. + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Then set the apptainer cache dir: + +``` +export APPTAINER_CACHEDIR=${SLURMTMPDIR} +``` + +Download the .def file + +``` +test -f R_rocker_4.5.1.def || curl -o R_rocker_4.5.1.def https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/R_rocker_4.5.1.def +``` + +sample output: + +> ``` +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 6126 100 6126 0 0 97501 0 --:--:-- --:--:-- --:--:-- 98806 +> ``` + +3. Build your container + +Building the R container takes about ten minutes + +``` +apptainer build --fakeroot R_rocker_4.5.1-$(arch).sif R_rocker_4.5.1.def +``` + +sample truncated output: + +> ``` +> [....] +> INFO: Adding environment to container +> INFO: Creating SIF file... +> INFO: Build complete: R_rocker_4.5.1-x86_64.sif +> ``` + +Quick test of the new container .sif image + +``` +apptainer run \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + R_rocker_4.5.1-$(arch).sif \ + R --version +```` + +Sample output: + +> ``` +> R version 4.5.1 (2025-06-13) -- "Great Square Root" +> Copyright (C) 2025 The R Foundation for Statistical Computing +> Platform: x86_64-pc-linux-gnu +> +> R is free software and comes with ABSOLUTELY NO WARRANTY. +> You are welcome to redistribute it under the terms of the +> GNU General Public License versions 2 or 3. +> For more information about these matters see +> https://www.gnu.org/licenses/. +> +> ``` + +Exit the Slurm interactive session + +``` +exit +``` + +sample output: + +> ``` +> CCRusername@login1$ +> ``` + +End the Slurm job and remove the environment variables set for the job + +``` +scancel "${SLURM_JOB_ID}" +unset SLURM_JOB_ID +eval $(set | grep ^SALLOC_ | awk -F= '{print "unset " $1}') +``` + +4. Running the container + +Start an interactive job - the following example uses the "general-compute" +partition + +To find which Slurm account you can use to run an interactive job in the +"general-compute" partition: + +``` +slimits | grep "general-compute" +``` + +sample output: + +> ``` +> ub-hpc SlurmAccountName CCRusername arm64,debug,general-compute,scavenger,viz +> ``` + + +The second field in the Slurm account name, so this example has access to the +"general-compute" partition using the Slurm account "SlurmAccountName" + +Set the environment variable "SALLOC_ACCOUNT" to the Slurm account you want +to use. +e.g. + +``` +export SALLOC_ACCOUNT="SlurmAccountName" +``` + +This example runs an interactive job in the "general-compute" partition, with +64GB RAM and 6 cores on a single node for 5 hours: + +``` +tmp_file="$(mktemp)" +salloc --cluster=ub-hpc --partition=general-compute --qos=general-compute \ + --no-shell --mem=64GB --nodes=1 --cpus-per-task=1 --tasks-per-node=6 \ + --time=5:00:00 2>&1 | tee "${tmp_file}" +SLURM_JOB_ID="$(head -1 "${tmp_file}" | awk '{print $NF}')" +rm "${tmp_file}" +srun --jobid="${SLURM_JOB_ID}" --export=HOME,TERM,SHELL --pty /bin/bash --login +``` + +sample outout: + +> ``` +> salloc: Pending job allocation 22171524 +> salloc: job 22171524 queued and waiting for resources +> salloc: job 22171524 has been allocated resources +> salloc: Granted job allocation 22171524 +> salloc: Nodes cpn-d01-19 are ready for job +> ``` + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Start the R container instance + +``` +apptainer shell \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + ./R_rocker_4.5.1-$(arch).sif +``` + +All the following commands are run from the "Apptainer> " prompt +run R + +``` +R +``` + +Sampleoutput: + +> ``` +> +> R version 4.5.1 (2025-06-13) -- "Great Square Root" +> Copyright (C) 2025 The R Foundation for Statistical Computing +> Platform: x86_64-pc-linux-gnu +> +> R is free software and comes with ABSOLUTELY NO WARRANTY. +> You are welcome to redistribute it under certain conditions. +> Type 'license()' or 'licence()' for distribution details. +> +> Natural language support but running in an English locale +> +> R is a collaborative project with many contributors. +> Type 'contributors()' for more information and +> 'citation()' on how to cite R or R packages in publications. +> +> Type 'demo()' for some demos, 'help()' for on-line help, or +> 'help.start()' for an HTML browser interface to help. +> Type 'q()' to quit R. +> +> > +> ``` + +exit R from the ">" prompt with: + +``` +q() +``` + +Expected output + +> ``` +> Apptainer> +> ``` + +Exit the Apptainer container instance +From the "Apptainer>" prompt: + +``` +exit +``` + +sample output: +> ``` +> CCRusername@cpn-d01-39~$ +> ``` + +Exit the Slurm interactive session + +``` +exit +``` + +sample output: + +> ``` +> logout +> CCRusername@login1$ +> ``` + +End the Slurm job and remove the environment variables set for the job + +``` +scancel "${SLURM_JOB_ID}" +unset SLURM_JOB_ID SALLOC_ACCOUNT +``` + + +See the [EXAMPLES file](./EXAMPLES.md) for more info. + +## Sample Slurm scripts + +Slurm script examples: + +### x86_64 example +[R x86_64 Slurm example script](https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_example.bash) +[Docs for running the R x86_64 Slurm example script](./SLURM_EXAMPLE.md) + +### ARM64 example +[R ARM64 Slurm example script](https://raw.githubusercontent.com/ubccr/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_ARM64_example.bash) +[Docs for running the R ARM64 Slurm example script](./SLURM_ARM64_EXAMPLE.md) + + +## Documentation Resources + +For more information on R see the [R project website](https://www.r-project.org), the [R Documentation](https://www.r-project.org/other-docs.html), +the [Rocker Project website](https://rocker-project.org), the [Rocker Project Images](https://rocker-project.org/images), +and the [Rocker Project Versioned 2 github repo](https://github.com/rocker-org/rocker-versioned2) + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/R_rocker_4.5.1.def b/containers/2_ApplicationSpecific/R-Rocker_Project/R_rocker_4.5.1.def new file mode 100644 index 00000000..a1f89abb --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/R_rocker_4.5.1.def @@ -0,0 +1,234 @@ +Bootstrap: docker +From: ghcr.io/rocker-org/r-ver:4.5.1 + +%post -c /bin/bash + # Set the timezone, if unset + test -h /etc/localtime || ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime + + cp /etc/apt/sources.list /etc/apt/sources.list~ + sed -E -i 's/^# deb-src /deb-src /' /etc/apt/sources.list + apt-get -y update + + # Install man & man pages - this section can be removed if not needed + # NOTE: Do this before installing anything else so their man pages are installed + sed -e '\|/usr/share/man|s|^#*|#|g' -i /etc/dpkg/dpkg.cfg.d/excludes + DEBIAN_FRONTEND=noninteractive apt-get -y install apt-utils groff dialog man-db manpages manpages-posix manpages-dev + rm -f /usr/bin/man + dpkg-divert --quiet --remove --rename /usr/bin/man + + # O/S package updates: + DEBIAN_FRONTEND=noninteractive apt-get -y upgrade + + DEBIAN_FRONTEND=noninteractive apt-get -y install \ + bash-completion \ + ca-certificates \ + tzdata \ + locales \ + zip \ + unzip \ + wget \ + git \ + libgit2-dev \ + subversion \ + gawk \ + file \ + gnupg2 \ + gpg \ + gpg-agent \ + libssh2-1-dev \ + libsasl2-dev \ + build-essential \ + autoconf \ + automake \ + pkg-config \ + cmake \ + cmake-data \ + cmake-extras \ + cmake-format \ + libclang-dev \ + python3 \ + python3-pip \ + python3-setuptools \ + python3-sphinx \ + python3-sphinx-rtd-theme \ + python3-dev \ + python-is-python3 \ + libpython3-dev \ + devscripts \ + perl \ + zstd \ + gnulib \ + libicu-dev \ + libssl-dev \ + zlib1g-dev \ + libzstd-dev \ + libbz2-dev \ + lbzip2 \ + xz-utils \ + libncurses5-dev \ + libncursesw5-dev \ + libreadline-dev \ + liblzma-dev \ + liblz4-tool \ + libcurl4-gnutls-dev \ + libdeflate-dev \ + libx11-dev \ + x11proto-core-dev \ + xfonts-base \ + xvfb \ + xauth \ + xtail \ + xzdec \ + libxt-dev \ + libxt6 \ + libxtst6 \ + xorg-dev \ + fonts-roboto \ + fonts-texgyre \ + gsfonts \ + ghostscript \ + libpng-dev \ + libtiff5-dev \ + libfreetype6-dev \ + libjpeg-dev \ + libjpeg-turbo8-dev \ + libjq-dev \ + liblzma-dev \ + texinfo \ + texlive \ + texlive-base \ + texlive-fonts-recommended \ + texlive-fonts-extra \ + texlive-font-utils \ + texlive-lang-all \ + texlive-extra-utils \ + texlive-latex-recommended \ + texlive-latex-extra \ + libpcre2-posix3 \ + libpcre2-dev \ + openjdk-21-jdk-headless \ + nvidia-cuda-dev \ + nvidia-cuda-toolkit \ + libxml2-dev \ + libudunits2-dev \ + libgdal-dev \ + libharfbuzz-dev \ + libfribidi-dev \ + libmagick++-dev \ + libgsl-dev \ + libfftw3-dev \ + libcairo2-dev \ + libpango1.0-dev \ + libgmp-dev \ + tk-dev \ + tcl-dev \ + libmpfr-dev \ + libnetcdf-dev \ + libhdf4-alt-dev \ + libhdf5-dev \ + libhts3 \ + libhts-dev \ + libhtscodecs2 \ + libhtscodecs-dev \ + libopenblas64-0 \ + libopenblas64-dev \ + libopenblas-dev \ + libopenblas64-dev \ + liblapack3 \ + liblapack-dev \ + liblapacke-dev \ + libscalapack-openmpi-dev \ + openmpi-bin \ + openmpi-common \ + libopenmpi-dev \ + libpmix2t64 \ + libpmix-dev \ + libgl1-mesa-dev \ + libglpk-dev \ + libglu1-mesa-dev \ + libgmp3-dev \ + libgsl0-dev \ + gdebi-core \ + libgeos-dev \ + libhunspell-dev \ + libpq-dev \ + libproj-dev \ + libprotobuf-dev \ + protobuf-compiler \ + libsqlite3-dev \ + unixodbc-dev \ + sqlite3 \ + libv8-dev \ + libzmq3-dev \ + postgis \ + psmisc \ + hugo \ + swig \ + curl \ + jq \ + nano \ + vim \ + less \ + apt-file + + # NOTE: apt-file is generally not needed to run, but can be useful during development + apt-file update + + # These steps are necessary to configure Perl and can cause issues with Python if omitted + sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen + dpkg-reconfigure --frontend=noninteractive locales + update-locale LANG=en_US.UTF-8 + + # Libraries in /usr/local/lib + # Include files in /usr/local/include + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" + export CFLAGS="${CFLAGS} -I/usr/local/include" + export CPPFLAGS="${CPPFLAGS} -I/usr/local/include" + export CXXFLAGS="${CXXFLAGS} -I/usr/local/include" + export FFLAGS="${FFLAGS} -I/usr/local/include" + export LDFLAGS="${LDFLAGS} -L/usr/local/lib -Xlinker -rpath -Xlinker \"/usr/local/lib\"" + export CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)" + pip_install_dir="$(python3 -c 'import sys; print("/usr/local/lib/python" + str(sys.version_info.major) + "." + str(sys.version_info.minor) + "/dist-packages")')" + export PYTHONPATH="${pip_install_dir}:${PYTHONPATH}" + export PATH="${PATH}:${pip_install_dir}/bin" + + # distro from the Ubuntu package clashes with the one from pip + DEBIAN_FRONTEND=noninteractive apt-get -y remove python3-distro + pip install --prefix="/usr" distro setuptools + + # make sure TMPDIR is on a local filesystem + export TMPDIR="${SLURMTMPDIR:-/var/tmp}" + # container setting required from some builds: + export container="oci" + # CUDA installed with Ubuntu packages, so set CUDA_HOME to /usr + export CUDA_HOME="/usr" + + R --version + +### # Sample code to add R packages from CRAN inside this container +### for package in \ +### Rcpp \ +### RcppEigen +### do +### R -e "install.packages(pkgs = \"${package}\", repos = \"https://cran.r-project.org\", +### lib = \"/usr/local/lib/R/library\", type = \"source\", dependencies = TRUE)" +### done + +%environment + # make sure TMPDIR is on a local filesystem + export TMPDIR="${SLURMTMPDIR:-/var/tmp}" + # container setting required from some builds: + export container="oci" + # CUDA installed with Ubuntu packages, so set CUDA_HOME to /usr + export CUDA_HOME="/usr" + export LANG=en_US.UTF-8 + export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib" + export PYTHONPATH="$(python3 -c 'import sys; print("/usr/local/lib/python" + str(sys.version_info.major) + "." + str(sys.version_info.minor) + "/dist-packages")'):${PYTHONPATH}" + export PATH="$(python3 -c 'import sys; print("/usr/local/lib/python" + str(sys.version_info.major) + "." + str(sys.version_info.minor) + "/dist-packages/bin")'):${PATH}" + +%runscript + #!/bin/bash + export PS1="rocker-R> " + # Exec passed command (required for Modal ENTRYPOINT compatibility) + exec "$@" + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_ARM64_EXAMPLE.md b/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_ARM64_EXAMPLE.md new file mode 100644 index 00000000..cca1d276 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_ARM64_EXAMPLE.md @@ -0,0 +1,84 @@ +# R_rocker ARM64 Slurm example + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Download the slurm sample scrip and the exmaple R script [estimate_pi.R](https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R) +The example code is writen by Andrea Gustafsen - see: +https://rpubs.com/andrea_gustafsen/839901 + +``` +test -f estimate_pi.R || curl -o estimate_pi.R https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R +test -f slurm_ARM64_example.bash || curl -o slurm_ARM64_example.bash https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_ARM64_example.bash +``` + +sample output: + +> ``` +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 874 100 874 0 0 14616 0 --:--:-- --:--:-- --:--:-- 14813 +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 1268 100 1268 0 0 9810 0 --:--:-- --:--:-- --:--:-- 9829 +> ``` + +Modify the Slurm script - change the account to one that has access to the +"arm64" partition (see `slimits | grep arm64`) + +For example: + +``` +slimits | grep arm64 +``` + +sample output: + +> ``` +> ub-hpc SlurmAccountName CCRusername arm64,debug,general-compute,scavenger,viz +> ``` + +The second field in the Slurm account name, so this example has access to the +"arm64" partition using the Slurm account "SlurmAccountName" + +``` +cat slurm_ARM64_example.bash +``` + +abridged sample output: + +> ``` +> [...] +> #SBATCH --account="SlurmAccountName" +> [...] +> ``` + +Submit the Slurm script + +``` +sbatch ./slurm_ARM64_example.bash +``` + +sample output: + +> ``` +> Submitted batch job 22179954 on cluster ub-hpc +> ``` + +The Slurm output file in this case is slurm-22179954.out +Once this Slurm job completed: + +``` +cat slurm-22179954.out +``` + +> ``` +> 10 100 1000 10000 1e+05 1e+06 1e+07 1e+08 +> 2.400000 3.160000 3.184000 3.158400 3.138760 3.143816 3.141868 3.141650 +> 1e+09 +> 3.141679 +> ``` + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_EXAMPLE.md b/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_EXAMPLE.md new file mode 100644 index 00000000..323b09c7 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/SLURM_EXAMPLE.md @@ -0,0 +1,75 @@ +# R_rocker Slurm example + +Change to your R directory + +``` +cd /projects/academic/[YourGroupName]/R +``` + +Download the slurm sample scrip and the exmaple R script [estimate_pi.R](https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R) +The example code is writen by Andrea Gustafsen - see: +https://rpubs.com/andrea_gustafsen/839901 + +``` +test -f estimate_pi.R || curl -o estimate_pi.R https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R +test -f slurm_example.bash || curl -o slurm_example.bash https://raw.githubusercontent.com/tonykew/ccr-examples/refs/heads/R-Rocker_Project/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_example.bash +``` + +sample output: + +> ``` +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 874 100 874 0 0 14577 0 --:--:-- --:--:-- --:--:-- 14813 +> % Total % Received % Xferd Average Speed Time Time Time Current +> Dload Upload Total Spent Left Speed +> 100 1434 100 1434 0 0 12964 0 --:--:-- --:--:-- --:--:-- 13036 +> ``` + +Modify the Slurm script - change the cluster, partition, qos and account +You can use the `slimits` command to see what accounts and QOS settings you +have access to. + +For example: + +``` +cat slurm_example.bash +``` + +abridged sample output: + +> ``` +> [...] +> #SBATCH --cluster="ub-hpc" +> #SBATCH --partition="debug" +> #SBATCH --qos="debug" +> #SBATCH --account="SlurmAccountName" +> [...] +> ``` + +Submit the Slurm script + +``` +sbatch ./slurm_example.bash +``` + +sample output: + +> ``` +> Submitted batch job 22173265 on cluster ub-hpc +> ``` + +The Slurm output file in this case is slurm-22173265.out +Once this Slurm job completed: + +``` +cat slurm-22173265.out +``` + +> ``` +> 10 100 1000 10000 1e+05 1e+06 1e+07 1e+08 +> 2.400000 3.160000 3.184000 3.158400 3.138760 3.143816 3.141868 3.141650 +> 1e+09 +> 3.141679 +> ``` + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R b/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R new file mode 100644 index 00000000..78636356 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/estimate_pi.R @@ -0,0 +1,30 @@ +# +# Estimating Pi Using Monte Carlo Simulation in R +# by Andrea Gustafsen +# +# https://rpubs.com/andrea_gustafsen/839901 +# +estimate_pi <- function(seed = 28, iterations = 1000){ + # set seed for reproducibility + set.seed(seed) + + # generate the (x, y) points + x <- runif(n = iterations, min = 0, max = 1) + y <- runif(n = iterations, min = 0, max = 1) + + # calculate + sum_sq_xy <- sqrt(x^2 + y^2) + + # see how many points are within circle + index_within_circle <- which(sum_sq_xy <= 1) + points_within_circle = length(index_within_circle) + + # estimate pi + pi_est <- 4 * points_within_circle / iterations + return(pi_est) +} +no_of_iterations <- c(10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000) +res <- sapply(no_of_iterations, function(n)estimate_pi(iterations = n)) +names(res) <- no_of_iterations +res + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_ARM64_example.bash b/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_ARM64_example.bash new file mode 100755 index 00000000..5850b589 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_ARM64_example.bash @@ -0,0 +1,36 @@ +#!/bin/bash -l + +## This file is intended to serve as a template to be downloaded and modified for your use case. +## For more information, refer to the following resources whenever referenced in the script- +## README- https://github.com/ubccr/ccr-examples/tree/main/slurm/README.md +## DOCUMENTATION- https://docs.ccr.buffalo.edu/en/latest/hpc/jobs + +#SBATCH --cluster="ub-hpc" +#SBATCH --partition="arm64" +#SBATCH --qos="arm64" +## Make sure the x86_64 (head node) environment is not used on the ARM64 node +#SBATCH --export=HOME,TERM,SHELL + +## Select an account that has access to the arm64 partition (see "slimits | grep arm64") +#SBATCH --account="[SlurmAccountName]" + +## Job runtime limit, the job will be canceled once this limit is reached. Format- dd-hh:mm:ss +#SBATCH --time=00:20:00 + +## NOTE: R uses only one core, unless you specifically use functions that take +## advantage of multiple cores, such as the 'parallel' package. +## This example allocates 6 cores, so apptainer has a thread for itself, +## plus a thread for each bind mount, leaving one core for the R process +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --cpus-per-task=6 +#SBATCH --mem=36GB + +R_version="4.5.1" + +# Run containerized R +apptainer run \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + R_rocker_${R_version}-$(arch).sif \ + Rscript estimate_pi.R + diff --git a/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_example.bash b/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_example.bash new file mode 100755 index 00000000..3ee0a945 --- /dev/null +++ b/containers/2_ApplicationSpecific/R-Rocker_Project/slurm_example.bash @@ -0,0 +1,35 @@ +#!/bin/bash -l + +## This file is intended to serve as a template to be downloaded and modified for your use case. +## For more information, refer to the following resources whenever referenced in the script- +## README- https://github.com/ubccr/ccr-examples/tree/main/slurm/README.md +## DOCUMENTATION- https://docs.ccr.buffalo.edu/en/latest/hpc/jobs + +## Select a cluster, partition, qos and account that is appropriate for your use case +## Available options and more details are provided in CCR's documentation: +## https://docs.ccr.buffalo.edu/en/latest/hpc/jobs/#slurm-directives-partitions-qos +#SBATCH --cluster="[cluster]" +#SBATCH --partition="[partition]" +#SBATCH --qos="[qos]" +#SBATCH --account="[SlurmAccountName]" + +## Job runtime limit, the job will be canceled once this limit is reached. Format- dd-hh:mm:ss +#SBATCH --time=00:20:00 + +## NOTE: R uses only one core, unless you specifically use functions that take +## advantage of multiple cores, such as the 'parallel' package. +## This example allocates 6 cores, so apptainer has a thread for itself, +## plus a thread for each bind mount, leaving one core for the R process +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --cpus-per-task=6 +#SBATCH --mem=36GB + +R_version="4.5.1" + +# Run containerized R +apptainer run \ + -B /projects:/projects,/scratch:/scratch,/util:/util,/vscratch:/vscratch \ + R_rocker_${R_version}-$(arch).sif \ + Rscript estimate_pi.R + diff --git a/containers/2_ApplicationSpecific/README.md b/containers/2_ApplicationSpecific/README.md index 144a5b81..c80f6a09 100644 --- a/containers/2_ApplicationSpecific/README.md +++ b/containers/2_ApplicationSpecific/README.md @@ -19,6 +19,7 @@ Please refer to CCR's [container documentation](https://docs.ccr.buffalo.edu/en/ | [OpenFF-Toolkit](./Open_Force_Field_toolkit) | Open Force Field toolkit container with steps for building and running via Apptainer | | [OpenFOAM](./OpenFOAM) | OpenFOAM container with steps for building and running via Apptainer and Slurm | | [OpenSees](./OpenSees) | OpenSees container with steps for building and running via Apptainer | +| [R - Rocker Project](./R-Rocker_Project) | R container based on the Rocker Project "r-ver" image - Apptainer build, run and Slurm scripts | | [SAS](./sas) | Guide for running SAS using Apptainer via Slurm batch script, command line, and GUI access | | [Seurat](./seurat) | Seurat container with example scRNA analysis | | [VASP](./vasp) | Example VASP container with steps for building and running via Apptainer |