introduction to mpi and openmp
play

Introduction to MPI and OpenMP myson @ postech.ac.kr CSE700-PL @ - PowerPoint PPT Presentation

Introduction to MPI and OpenMP myson @ postech.ac.kr CSE700-PL @ POSTECH Programming Language Laboratory p.1/18 Outline MPI and OpenMP Definition Characteristics Flow models Examples Compiling and Execution Resources Programming


  1. Introduction to MPI and OpenMP myson @ postech.ac.kr CSE700-PL @ POSTECH Programming Language Laboratory – p.1/18

  2. Outline MPI and OpenMP Definition Characteristics Flow models Examples Compiling and Execution Resources Programming Language Laboratory – p.2/18

  3. What are MPI and OpenMP? Message Passing Interface (MPI) - MPI is a library specification for message-passing, proposed as a standard by a broadly based committee of vendors, implementors, and users. Programming Language Laboratory – p.3/18

  4. What are MPI and OpenMP? Open Multi Processing (OpenMP) - OpenMP is a specification for a set of compiler directives, library routines, and environment variables that can be used to specify shared memory parallelism in Fortran and C/C++ programs. Programming Language Laboratory – p.4/18

  5. MPI vs. OpenMP MPI OpenMP Distributed memory model Shared memory model on Distributed network on Multi-core processors Message based Directive based Flexible and expressive Easier to program and debug Programming Language Laboratory – p.5/18

  6. MPI Flow Model Message Passing - Send and Receive a message, size, type, source, dest, tag, communicator, status Programming Language Laboratory – p.6/18

  7. OpenMP Flow Model Directives (C/C++) - #pragma omp directives [clauses] directives - parallel, for, single, etc. Programming Language Laboratory – p.7/18

  8. A Simple Example A serial program #include<stdio.h> #define PID 0 main(){ int i; printf("Greetings from process %d!/n", PID); } Greetings from process 0 Programming Language Laboratory – p.8/18

  9. A Simple Example(cont.) A parallel program using MPI (cont.) #include<mpi.h> main(int argc, char** argv){ . . . MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_size(MPI_COMM_WORLD, &p); Parallel Region MPI_Finalize(); } Programming Language Laboratory – p.9/18

  10. A Simple Example(cont.) A parallel program using MPI if ( my_rank != 0){ sprintf(message, "Greetings from process %d!", my_rank); dest = 0; MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD); } else{ /* my_rank = 0 */ for (source = 1; source < p; source++){ MPI_Recv(message, 100, MPI_CHAR, source, tag, MPI_COMM_WORLD, &status); printf("%s/n", message); } } Programming Language Laboratory – p.10/18

  11. A Simple Example(cont.) A parallel program using MPI (cont.) Greetings from process 1 Greetings from process 2 Greetings from process 3 Programming Language Laboratory – p.11/18

  12. A Simple Example(cont.) A parallel program using OpenMP #include<stdio.h> #include<omp.h> main(){ int id; #pragma omp parallel { id = omp_get_thread_num(); printf("Greetings from process %d!/n", id); } } Programming Language Laboratory – p.12/18

  13. A Simple Example(cont.) A parallel program using OpenMP (cont.) Greetings from process 1 Greetings from process 0 Greetings from process 2 Greetings from process 3 Programming Language Laboratory – p.13/18

  14. Which is better? Programming Language Laboratory – p.14/18

  15. Compiling GCC and MPICH2 for MPI GCC-4.2 with library libgomp for OpenMP MPI mpicc -o example.out example.c OpenMP gcc-4.2 -o example.out example.c -fopenmp Programming Language Laboratory – p.15/18

  16. Execution ∼ /.mpd.conf for MPI execution vi(or emacs) ∼ /.mpd.conf secretword=<your secretword> chmod 600 ∼ /.mpd.conf MPI (using multi-core processors) mpdboot mpiexec -n #processes ./example.out mpdallexit OpenMP ./example.out Programming Language Laboratory – p.16/18

  17. Resources Machine (Plquad: plquad.postech.ac.kr) Intel Core 2 Quad Q6600 (quad-core) 1G DDR RAM If you want to use it, email the instructors. Materials - resource tab on the course web-page MPI & OpenMP install guides MPI & OpenMP tutorials . . . Programming Language Laboratory – p.17/18

  18. End Any Questions. . . ? Programming Language Laboratory – p.18/18

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend