Master/slave
Master/slave
Master/slave Message passing is well-suited to handling computations where a task is divided up into subtasks with most of the processes used to compute the subtasks and a few processes (often just one process) managing the tasks. The manager is called the"master and the others the workers or the slaves In this example, it is to build an Input/Output master/slave system. This will allow you to relatively easily arrange for different kinds of input and output from the program, including Ordered output (process 2 after process 1) Duplicate removal (a single instance of "Hello world"instead of one from each process) Input to all processes from a terminal
Master/slave • Message passing is well-suited to handling computations where a task is divided up into subtasks, with most of the processes used to compute the subtasks and a few processes (often just one process) managing the tasks. The manager is called the "master" and the others the "workers" or the "slaves". • In this example, it is to build an Input/Output master/slave system. This will allow you to relatively easily arrange for different kinds of input and output from the program, including – Ordered output (process 2 after process 1) – Duplicate removal (a single instance of "Hello world" instead of one from each process) – Input to all processes from a terminal
Master/slave This will be accomplished by dividing the processes in MPI COMM WORLd into two sets: The master (who will do all of the l/ o)and the slaves(who will do all of their l/0 by contacting the master) The slaves will also do any other computation that they might desire; for example, they might implement the Jacobi iteration The master should accept messages from the slaves(of type MPl CHAR) and print them in rank order( that is first from slave 0, then from slave 1, etc. ) The slaves should each send 2 mess ages to the master. For simplicity, Have the slaves send the messages Hello from slave 3 Goodbye from slave 3 You may want to use these mpi routines in your solution MPI Comm split, MPI Send, MPI Recv
Master/slave • This will be accomplished by dividing the processes in MPI_COMM_WORLD into two sets: – The master (who will do all of the I/O) and the slaves (who will do all of their I/O by contacting the master). – The slaves will also do any other computation that they might desire; for example, they might implement the Jacobi iteration. • The master should accept messages from the slaves (of type MPI_CHAR) and print them in rank order (that is, first from slave 0, then from slave 1, etc.). The slaves should each send 2 messages to the master. For simplicity, Have the slaves send the messages Hello from slave 3 Goodbye from slave 3 • You may want to use these MPI routines in your solution: MPI_Comm_split, MPI_Send, MPI_Recv
Master/slave Source casestudy/io/io.c casestudy/io/Makefile Sample Output %% mpICC-0 1010. C mpirun-np 4 ic Hello from slave 0 Hello from slave 1 Hello from slave 2 Goodbye from slave 0 Goodbye from slave 1 Goodbye from slave 2
Master/slave Source casestudy/io/io.c casestudy/io/Makefile Sample Output % mpicc -o io io.c % mpirun -np 4 io Hello from slave 0 Hello from slave 1 Hello from slave 2 Goodbye from slave 0 Goodbye from slave 1 Goodbye from slave 2
A simple output server
A simple output server