Skip to content

Instantly share code, notes, and snippets.

@arm2arm
Last active February 22, 2021 20:38
Show Gist options
  • Save arm2arm/533b108f7a23cde71a6f93624ec7d6e8 to your computer and use it in GitHub Desktop.
Save arm2arm/533b108f7a23cde71a6f93624ec7d6e8 to your computer and use it in GitHub Desktop.
python MPI on with conda
# HPC MPI enviroment for python jobs
```
conda create -n mpi
conda activate mpi
conda install openmpi openmpi-mpicc mpi4py matplotlib astropy scikit-learn pandas pytables
```
# testing
```
from mpi4py import MPI
import numpy
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
if rank == 0:
data = [i*i for i in range(size)]
print('I am Rank 0 ')
else:
data = None
data=comm.scatter(data,root=0)
print(f'On process {rank}, data is {data}')
```
mpirun -np 4 python test.mpi.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment