message passing model is a type of parallel programming model.
- https://curc.readthedocs.io/en/latest/programming/MPI-C.html#setup-and-hello-world
- https://manual.cs50.io/
To run any of the scripts in this project you need to have the MPI compiler installed.
sudo apt-get install mpich
Functions under the <mpi.h>
include:
- MPI_Init(&argc, &argv) - Startsup a Virtual Machine.
- MPI_Comm_size(MPI_COMM_WORLD, &p) - Gets the Virtual Machine Size
- MPI_Comm_rank(MPI_COMM_WORLD, &id) - Gets the Process Id / rank in Virtual Machine.
- MPI_Get_processor_name(MPI_COMM_WORLD, &namelen) - get the name of the processor.
- MPI_Comm_split() - split the MPI_COMM_WORLD communicator into sub-communicators.
- MPI_Finalize() - Shutsdown Virtual Machine.
To build src/hello-simple.c
and run it. you can change the number of processes by change the number 4 in the command.
mpicc -Wall -O -o bin/hello-simple src/hello-simple.c && mpirun -np 4 bin/hello-simple
To build src/hello-advanced.c
and run it use the command below.
you can change the number of processes by changing the number 4 in the command.
NOTE: The paylaod has been change in this implementation.
mpicc -Wall -O -o bin/hello-advanced src/hello-advanced.c && mpirun -np 4 bin/hello-advanced
You can also specify a machinefile to run the logic of the get the new paylaod.
mpirun -machinefile resources/mpi04 -np 4 bin/hello-advanced
MPI organises processors into groups called connectors.
MPI_COMM_WORLD is the top level communicator consisting of all processors allocated by mpirun -np
MPI offers two basic point to point communication functions:
- MPI_Send(message, count, datatype, dest, tag, comm)
- MPI_Recv(message, count, datatype, source, tag, comm, status)
- MPI_Ssend(message, count, datatype, dest, tag, comm)
- MPI_Bsend(message, count, datatype, dest, tag, comm)
Many parallel programs can be written using just the basic MPI_Send and MPI_Recv and the other functions we used in hello-simple and hello-advanced programs.
pass MPI_ANY_SOURCE
to MPI_Recv
if the source is irrelevant.
pass MPI_ANY_TAG
to MPI_Recv
if the tag is also irrelevant.
MPI_CHAR : char MPI_DOUBLE : double MPI_FLOAT : float MPI_INT : int MPI_LONG : long MPI_LONG_DOUBLE : long double MPI_UNSIGNED_CHAR : unsigned char MPI_UNSIGNED_INT : unsigned int - ????? MPI_UNSIGNED_LONG : unsigned long MPI_UNSIGNED_SHORT : unsigned short
The Number guessing Game is a 2 player game with two actors: thinker and guesser
- Thinker - thinks of a number between 1 and 100
- Guesser - guesses the number the thinker has chosen.
- Thinker - replies whether the guess is low,high or correct.
- idf not correct, the guesser trys again and so on.
Implement this program as an MPI Program running on two processors Thinker is on processor 0 1. Recieves Integer guesses. 2. Sends replies as characters h, l or c. Guesser is on processor 1 1. Sends integer guesses 2. Recieves characters.
NOTE: This is a distributed, non-parallel program, because the game is turn-based and thus inherently sequential.