{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MPI support"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PySM 3 can be executed in parallel over multiple nodes of a supercomputer with MPI.\n",
    "\n",
    "The requirements to run with MPI are `mpi4py` and, just for distributed smoothing, `libsharp`.\n",
    "\n",
    "The input maps are read from the first process in order to prevent overloading the filesystem, and then maps are distributed rings by rings across all processes, not overlapping.\n",
    "\n",
    "The `pysm.MapDistribution` object takes care of handling the metadata about how the data are distributed.\n",
    "\n",
    "When the emission is requested, each process independently computes the emission just on its own portion of the sky.\n",
    "\n",
    "When smoothing is applied, `libsharp` is used to efficiently perform a distributed spherical harmonics transform.\n",
    "\n",
    "Check [`pysm3_mpi.py`](https://github.com/healpy/pysm/blob/master/mpi_examples/pysm3_mpi.py) from the repository as an example.\n",
    "\n",
    "Execute with (remove `#` to actually execute it):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!mpirun -np 3 python pysm3_mpi.py"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "PySM 3",
   "language": "python",
   "name": "pysm3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
