mirror of
https://github.com/RustyRaptor/parallel-programming.git
synced 2026-12-03 23:55:23 -07:00
README
Tutorial
Connecting to the machines
Connect to your head node
- SSH into a machine that has MPI Working.
- One such example is
gojiro.cs.nmsu.edu
- One such example is
- Now let's refer to this machine as your head node.
- How to tell if the machine has mpi?
- Connect to the machine
- try to run the command
mpirun --versionormpicc --version - It should print out the version number. If not it probably doesn't
- However sometimes your
PATHis broken.- To check this run this command
/usr/lib64/mpi/gcc/openmpi4/bin/mpicc --version- If this command returns the version number of mpicc then your
PATHis broken.- You don't have to fix it.
- From now on you can just use
/usr/lib64/mpi/gcc/openmpi4/bin/mpiccinstead ofmpicc
- From now on you can just use
- If you want to try fixing it you just need to add
/usr/lib64/mpi/gcc/openmpi4/bin/to yourPATH
- You don't have to fix it.
- To check this run this command
Connect to and setup your worker nodes
Find worker nodes that have mpi working.
- Find at least 1 other worker that has mpi working.
- Here is a list of known nodes (append
.cs.nmsu.eduif you need to)krakengojirotsunamikaijugray- (
grayhad issues when I used it but if you use it as your head node it should work.)
- (
Setup your worker nodes for no-password ssh login
- This is necessary for mpi to be able to login to each node and execute commands without passwords
- Don't worry this only allows your head node to do this. It is completely safe.
- Steps
- Generate a local ssh key
ssh-keygen- Press enter for default options
- Copy the ssh key to one of the nodes you want to use
ssh-copy-id yourusername@yournode.cs.nmsu.edu- You only need to copy it to one node because the CS machines share the same files so copying it to one node will allow passwordless login on all of them.
- Test the ssh connection to each node
- for each node in your hostfile run this command
ssh yourusername@nodename.cs.nmsu.edu
- each one should work without a password.
- for each node in your hostfile run this command
- Generate a local ssh key
Create your "hosts" file
- Create a plain text file in your code directory
touch mynodes.txt- You can name it anything you like
- Put the hostnames of each of your nodes including your head node line-by-line (example below)
Example hosts file
kraken
gojiro
tsunami
kaiju
Compile and run your code
Compile
- compile your c program that uses mpi using
mpicc mpicc -o hello hello.c
Run
- Run your code using
mpirunand determine the number of processor slots mpirun --hostfile remotes.txt -np 2 ./hello- If you setup enough hosts at least 2 processors should work.
- Slowly increase the number after
-npuntil it stops working.- This will tell you the max number of processor slots your node cluster can provide.
- In my case I was able to reach 100 slots with 5 machines
Troubleshooting
Duplicate hosts in hostfile
- If you have duplicates in your hostfile or you included
localhostas well as the public name of your head host your code will break
The infamous newline issue
- Sometimes having a newline at the bottom of your hosts file can break or fix things
- Try with and without a blank line at the bottom of your hosts file
My code is just stuck
- Some nodes are broken like this.
- Try removing hosts from your hostsfile one by one until you find the bad egg
How to use my code...
usage
- Open your terminal and navigate to the directory containing the Makefile.
- To compile the program, use the command:
make - To run the program across multiple nodes, use the command:
make run - To clean up the compiled files after you're done, use the command:
make clean
using the python script to setup hosts
- Open your terminal and navigate to the directory containing the
setup_remotes.pyscript. - Ensure you have the
paramikolibrary installed. If not, install it using pip:pip install paramiko - Run the script with the following command:
python setup_remotes.py <hostsfile> <your-username> <your-password>
using the other python script to check if the hosts have mpi
- it will output the hosts that have it to a new file
python check_mpicc host_file username password output_file- this also depends on
paramiko