PageSourceSearch

https://www.bsc.es/supportkc/assets/js/9c06cfca.a3f5793f.js

js bsc.es collected 2026-09-24 08:44:25 UTC 9,759 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunksupportkc_new=self.webpackChunksupportkc_new||[]).push([[3544],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>d});var i=n(67294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,i,a=function(e,t){if(null==e)return{};var n,i,a={},o=Object.keys(e);for(i=0;i<o.length;i++)n=o[i],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)n=o[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=i.createContext({}),p=function(e){var t=i.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):r(r({},t),e)),n},u=function(e){var t=p(e.components);return i.createElement(l.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},h=i.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,l=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),c=p(n),h=a,d=c["".concat(l,".").concat(h)]||c[h]||m[h]||o;return n?i.createElement(d,r(r({ref:t},u),{},{components:n})):i.createElement(d,r({ref:t},u))}));function d(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,r=new Array(o);r[0]=h;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[c]="string"==typeof e?e:a,r[1]=s;for(var p=2;p<o;p++)r[p]=n[p];return i.createElement.apply(null,r)}return i.createElement.apply(null,n)}h.displayName="MDXCreateElement"},83213:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>p});var i=n(87462),a=(n(67294),n(3905));const o={slug:"mpi-singularity-guide",title:"Running MPI apps on Singularity",authors:["wchiodi"],tags:["guide","singularity"]},r=void 0,s={permalink:"/supportkc/blog/mpi-singularity-guide",source:"@site/blog/2022-07-25-singularity-report/mpi-singularity-guide.md",title:"Running MPI apps on Singularity",description:"Running MPI programs in singularity is fairly simple, the only pre-requisite is that a version of MPI compatible with the host's is installed within the container. Doing this is easy, since you can stage an MPI installation in a Singularity definition file. Singularity supports both OpenMPI and MPICH; in the following example, based on the official documentation, we will install OpenMPI 4.1.2 in a container:",date:"2022-07-25T00:00:00.000Z",formattedDate:"July 25, 2022",tags:[{label:"guide",permalink:"/supportkc/blog/tags/guide"},{label:"singularity",permalink:"/supportkc/blog/tags/singularity"}],readingTime:2.895,hasTruncateMarker:!1,authors:[{name:"Wenceslao Chiodi Calo",title:"First Level HPC Support",url:"https://www.bsc.es/chiodi-calo-wenceslao",imageURL:"https://www.bsc.es/sites/default/files/public/personal_photo/wchiodi.jpeg",key:"wchiodi"}],frontMatter:{slug:"mpi-singularity-guide",title:"Running MPI apps on Singularity",authors:["wchiodi"],tags:["guide","singularity"]},prevItem:{title:"EuroHPC AI Factory: Technical Guide for Proposals",permalink:"/supportkc/blog/eurohpc-ai-factory-technical-guide-proposals"},nextItem:{title:"We have a new documentation!",permalink:"/supportkc/blog/new-documentation"}},l={authorsImageUrls:[void 0]},p=[],u={toc:p},c="wrapper";
1function m(e){let{components:t,...n}=e;return(0,a.kt)(c,(0,i.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("p",null,"Running MPI programs in singularity is fairly simple, the only pre-requisite is that a version of MPI compatible with the host's is installed within the container. Doing this is easy, since you can stage an MPI installation in a Singularity definition file. Singularity supports both OpenMPI and MPICH; in the following example, based on the ",(0,a.kt)("a",{parentName:"p",href:"https://docs.sylabs.io/guides/3.10/user-guide/mpi.html"},"official documentation"),", we will install OpenMPI 4.1.2 in a container:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},'Bootstrap: docker\nFrom: ubuntu:18.04\n\n%files\n    mpitest.c /opt\n\n%environment\n    # Point to OPENMPI binaries, libraries man pages\n    export OPENMPI_DIR=/opt/openmpi-4.1.2\n    export PATH="$OPENMPI_DIR/bin:$PATH"\n    export LD_LIBRARY_PATH="$OPENMPI_DIR/lib:$LD_LIBRARY_PATH"\n    export MANPATH=$OPENMPI_DIR/share/man:$MANPATH\n\n%post\n    echo "Installing required packages..."\n    export DEBIAN_FRONTEND=noninteractive\n    apt-get update && apt-get install -y wget git bash gcc gfortran g++ make\n\n    # Information about the version of OPENMPI to use\n    export OPENMPI_VERSION=4.1.2\n    export OPENMPI_MINOR=4.1\n    export OPENMPI_URL="https://download.open-mpi.org/release/open-mpi/v$OPENMPI_MINOR/openmpi-$OPENMPI_VERSION.tar.gz"\n    export OPENMPI_DIR=/opt/openmpi-$OPENMPI_VERSION\n\n    echo "Installing OPENMPI..."\n    mkdir -p /tmp/openmpi\n    mkdir -p /opt\n    # Download\n    cd /tmp/openmpi && wget -O openmpi-$OPENMPI_VERSION.tar.gz $OPENMPI_URL && tar xzf openmpi-$OPENMPI_VERSION.tar.gz\n    # Compile and install\n    cd /tmp/openmpi/openmpi-$OPENMPI_VERSION && ./configure --prefix=$OPENMPI_DIR && make install\n\n    # Set env variables so we can compile our application\n    export PATH=$OPENMPI_DIR/bin:$PATH\n    export LD_LIBRARY_PATH=$OPENMPI_DIR/lib:$LD_LIBRARY_PATH\n\n    echo "Compiling the MPI application..."\n    cd /opt && mpicc -o mpitest mpitest.c\n\n')),(0,a.kt)("p",null,"As you can see, the image is taken from the docker hub, and uses the Ubuntu 18.04 distribution.\nThis definition file has three separate sections, the first one being the ",(0,a.kt)("a",{parentName:"p",href:"https://docs.sylabs.io/guides/3.10/user-guide/definition_files.html#files"},(0,a.kt)("strong",{parentName:"a"},"%files"))," section, which copies the specified file from the host system into the container's file system. Then the ",(0,a.kt)("a",{parentName:"p",href:"https://docs.sylabs.io/guides/3.10/user-guide/definition_files.html#environment"},(0,a.kt)("strong",{parentName:"a"},"%environment"))," section, which sets environment variables at runtime, in this case it adds the corresponding paths to the MPI installation to the ",(0,a.kt)("em",{parentName:"p"},"PATH"),", ",(0,a.kt)("em",{parentName:"p"},"LD_LIBRARY_PATH")," and ",(0,a.kt)("em",{parentName:"p"},"MANPATH")," variables. Finally the ",(0,a.kt)("a",{parentName:"p",href:"https://docs.sylabs.io/guides/3.10/user-guide/definition_files.html#post"},(0,a.kt)("strong",{parentName:"a"},"%post"))," section, where most of the stuff is done, since it's where you usually install programs."),(0,a.kt)("p",null,"The OpenMPI installation is a fairly straight-forward source code installation, you may see that a lot of environment variables are declared here, these help make the rest of the commands more generic, to facilitate a possible future installation using a different version, and will not be exported at runtime.\nThe rest of the installation consists on the usual steps: download and untar the source code, create a build directory, run the configure script and set the prefix to the desired directory, and finally run make install."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"username@laptop$ sudo singularity build mpi-image1.sif mpi-image1.def\n")),(0,a.kt)("p",null,"The singularity build command must be executed using root privileges, and may take a short while, but after the installation is done the final step will be to compile the provided program and voila! The image has been built."),(0,a.kt)("p",null,"Now to actually run this container in an HPC cluster you should copy to the desired cluster, in this case Marenostrum 4:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"username@laptop$ scp mpi-image1.sif [email protected]:/desired/directory/\n")),(0,a.kt)("p",null,"Now it's time to load the required modules. Any version of Singularity should do the job, so the lastest one installed works just fine. As for OpenMPI, it should, as mentioned before, be a ver
1sion compatible with the one installed in the container. Since OpenMPI 4.1.2 is available, it will be the best choice:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"username@login1$ module load openmpi/4.1.2 singularity/3.7.3\n")),(0,a.kt)("p",null,"Finally, it's time to run the container with the MPI application. Singularity uses the hybrid approach for MPI executions, meaning you should execute mpirun or the equivalent command to the singularity command, and then both MPI will work in tandem to instantiate the corresponding jobs. The final command should look something like this:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"username@login1$ mpirun -np 4 singularity exec mpi-image1.sif /opt/mpitest\n")),(0,a.kt)("p",null,"For more general information about Singularity don't forget to check the ",(0,a.kt)("a",{parentName:"p",href:"/docs-utilities/singularity"},"user guide"),"."))}m.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.