---
tags:
  - General
title: Connect MPI system over SSH for Dummy
description: How to setup MPI system over SSH
date: 2025-01-01
author: Nikola Petrov
draft: false
---

1. On all computers
```bash
sudo apt install openssh-client
sudo apt install openssh-server
sudo apt install openmpi-bin libopenmpi-dev
```

2. Disable firewall
```bash
sudo ufw status
sudo ufw disable
```

3. Try connecting master to every slave ( you will need password )
```bash
ssh user@ipslave1
ssh user@ipslave2
```

4. On master generate a key and put it on the slaves
```bash
ssh-keygen -t rsa

ssh-copy-id user@ipslave1
ssh-copy-id user@ipslave2
```

5. Try connecting master to every slave ( you will not need password )
```bash
ssh user@ipslave1
ssh user@ipslave2
```

6. Compile program 
```bash
mpicc main.c -o main
mpic++ main.cpp -o main
```

7. Copy main in to /tmp folder for easy same location ( program needs to be in the same path on all computers )
```bash
cp /path/to/main /tmp/mympiprogram/
```

8. Copy program to all computers
	- Could use NFS server for auto copy
```bash
scp <source> <destination>
scp /tmp/mympiprogram/main user@ipslave1:/tmp/mympiprogram/main
scp /tmp/mympiprogram/main user@ipslave2:/tmp/mympiprogram/main
```


9. Run program
	- `num < c1 + c2 + c3` 
	- c1 is number of processes that can run on the computer
	- num is number of processes that are needed for the program
```bash
mpirun -np <num> --host 127.0.0.1:<c1>,ipslave1:<c2>,ipslave2<c3> /tmp/mympiprogram/main
```

10. Enable firewall
```bash
sudo ufw status
sudo ufw enable
```




