# How to run OpenMC with MPI? Tutorial of OpenMC in Parallel

**URL:** <https://openmc.discourse.group/t/how-to-run-openmc-with-mpi-tutorial-of-openmc-in-parallel/3987>\
**Category:** User Support\
**Created:** [March 1, 2024, 4:31am UTC](https://openmc.discourse.group/t/how-to-run-openmc-with-mpi-tutorial-of-openmc-in-parallel/3987 "2024-03-01T04:31:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![campagnani](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/campagnani/32/3201_2.png) [@campagnani](https://openmc.discourse.group/u/campagnani)\
**Post date:** [June 25, 2024, 4:36pm UTC](https://openmc.discourse.group/t/how-to-run-openmc-with-mpi-tutorial-of-openmc-in-parallel/3987/4 "2024-06-25T16:36:05Z")

</div>

Finally find a solution!

The problem is with the package parallel HDF5 (hdf5-openmpi package).

The solution is simply compile the OpenMC with serial HDF5 (hdf5 package).

Source: [Depletion simulation on supercomputer gets stuck between depletion steps.](https://openmc.discourse.group/t/depletion-simulation-on-supercomputer-gets-stuck-between-depletion-steps/606)  
And: [Allow depletion with MPI and serial HDF5 by paulromano · Pull Request #1566 · openmc-dev/openmc · GitHub](https://github.com/openmc-dev/openmc/pull/1566)

My new package build is:

```auto
pkgname=openmc-ompi-nopy
pkgver=v0.15.0
pkgrel=1
pkgdesc="OpenMC build with OpenMPI but without hdf5-openmpi, and without python env."
arch=('x86_64')
url="https://github.com/openmc-dev/openmc"
license=('MIT')

source=("${pkgname}::git+${url}.git")

pkgver() {
    cd "$pkgname"
    git checkout master > /dev/null # Change to brench master (last version stable)
    git describe --tags | sed 's/-.*//'
}

md5sums=('SKIP')

depends=( 
    hdf5
    openssh
    fmt
)

makedepends=(
    hdf5
    base-devel
    cmake
    git
    fmt
)

conflicts=(
    openmc-git
    hdf5-openmpi
)

provides=("${pkgname%-pkgver}")

build() {
    cd $srcdir/${pkgname}
    rm -rf build
    mkdir build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENMC_USE_MPI=ON -DCMAKE_INSTALL_PREFIX=/opt/openmc

    _ccores=$(nproc)
    # check if _ccores is a positive integer, if not, serial build
    if [["${_ccores}" =~ ^[1-9][0-9]*$ ]]; then
        make -j ${_ccores}
    else
        make
    fi
}

package() {
    cd $srcdir/${pkgname}/build
    make DESTDIR="$pkgdir/" install
    rm -rf $srcdir/${pkgname}/build
    mkdir $pkgdir/opt/openmc/openmc-src
    cp -r $srcdir/${pkgname}/* $pkgdir/opt/openmc/openmc-src
    rm -rf $srcdir
    mkdir -p $pkgdir/usr/bin
    ln -s /opt/openmc/bin/openmc $pkgdir/usr/bin
}

```

Save this as a file called PKGBUILD. To compile and install on ArchLinux family (Manjaro, etc) run this command in the same folder of PKGBUILD file:

```auto
makepkg -si #or use just -s to just compile

```

To create a python envrolvment in your user:

```auto
cd ~
python -m venv openmc-env
source openmc-env/bin/activate
cp -r /opt/openmc/openmc-src/ ~/
cd openmc-src/
python -m pip install .
rm -rf ~/openmc-src/

```

In the cluster you need the python envrolvment just in the father computer.

You need run the comand below every time you open the terminal in the father computer before run openmc python:

```auto
source openmc-env/bin/activate

```

Or you can put this command in the ~/.bashrc file.

---

_[View the full topic](https://openmc.discourse.group/t/how-to-run-openmc-with-mpi-tutorial-of-openmc-in-parallel/3987)._
