



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A chapter from a textbook by sanjay rajopadhye of colorado state university, focusing on message passing interface (mpi) for parallel programming. The background and history of mpi, the spmd programming model, writing and compiling mpi programs, and example library calls. It also includes an example program for boolean circuit satisfiability.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




write a single program using a special library compile it with special compiler (that knows about the library) execute “it” in an environment created by the environment variables of your session (as on bassi) with a special command on your local machine (e.g., Lam MPI) multiple instances of the executable run in parallel Each instance has its own local data (distributed memory) MPI library provides functions for coordinating and communicating amongst the instances
Example library calls
Example program Contrived program: don’t take (too) seriously Boolean Circuit Satisfiability
Difficult problem in computer science (NP-complete) Solution (algorithm) NP Complete: no known polynomial time algorithm Accept approximate solutions Solve by “exhaustive” enumeration (exponential time)
Example Circuit
Communicators Rank and Size MPI_Comm_size(communicator comm, int &size) Communicator is input size is returned Number of processes in the communicator MPI_Comm_rank(communicator comm, int &rank) Communicator is input rank is returned id of the calling process in the communicator (integer between 0 and size)
Cyclic allocation of work main(int argc, char *argv[]) { int i, id, p; void check_circuit(int, int); MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_size(MPI_COMM_WORLD, &p); for (i = id; i < NUMREPS; i += p) check_circuit(id, i); printf("Process %d is done.\n", id); fflush(stdout); MPI_Finalize(); return 0;} Compiling and executing
http://www.cs.colostate.edu/~cs475/LabClass/circuit/instructions.html
Execution notes
Multiple prints by same process will always occur in the order they are executed. calls by different processes will be queued (importance of flush) the system may interleave the processing of the commands Extensions
Details Each process has a counter to maintain how many solutions it found modify check_circuit return 0 if not satisfiable return 1 if satisfiable Introduce your first (collective) communication call at the end of the loop MPI_Reduce: combines values in different processes into a single result Call after the for loop MPI_Reduce int MPI_Reduce ( void sendbuf, / ptr to first argument */ void recvbuf, / ptr to first result / int count, / number of values to combine / MPI_Datatype datatype, / type / MPI_Op op, / operator / int root, / destination */ MPI_Comm comm )