MPI and Hybrid Programming Models. William Gropp www.cs.illinois.edu/~wgropp

Similar documents
Introduction to Hybrid Programming

OpenMP & MPI CISC 879. Tristan Vanderbruggen & John Cavazos Dept of Computer & Information Sciences University of Delaware

Petascale Software Challenges. William Gropp

Comparing the OpenMP, MPI, and Hybrid Programming Paradigm on an SMP Cluster

Advanced MPI. Hybrid programming, profiling and debugging of MPI applications. Hristo Iliev RZ. Rechen- und Kommunikationszentrum (RZ)

Multi-core Programming System Overview

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

Parallel Algorithm Engineering

Parallel Computing. Parallel shared memory computing with OpenMP

Parallel Computing. Benson Muite. benson.

Scheduling Task Parallelism" on Multi-Socket Multicore Systems"

Designing and Building Applications for Extreme Scale Systems CS598 William Gropp

Parallel Programming Survey

Performance Analysis of a Hybrid MPI/OpenMP Application on Multi-core Clusters

Getting OpenMP Up To Speed

Performance Evaluation of NAS Parallel Benchmarks on Intel Xeon Phi

Parallel Programming at the Exascale Era: A Case Study on Parallelizing Matrix Assembly For Unstructured Meshes

Workshare Process of Thread Programming and MPI Model on Multicore Architecture

UTS: An Unbalanced Tree Search Benchmark

Multi-Threading Performance on Commodity Multi-Core Processors

PMI: A Scalable Parallel Process-Management Interface for Extreme-Scale Systems

An Introduction to Parallel Computing/ Programming

BSC vision on Big Data and extreme scale computing

Multicore Parallel Computing with OpenMP

reduction critical_section

PART IV Performance oriented design, Performance testing, Performance tuning & Performance solutions. Outline. Performance oriented design

Parallel Computing. Shared memory parallel programming with OpenMP

Scalability evaluation of barrier algorithms for OpenMP

MAQAO Performance Analysis and Optimization Tool

End-user Tools for Application Performance Analysis Using Hardware Counters

Agenda. Enterprise Application Performance Factors. Current form of Enterprise Applications. Factors to Application Performance.

The Fastest Way to Parallel Programming for Multicore, Clusters, Supercomputers and the Cloud.

Parallel Computing for Data Science

Chapter 18: Database System Architectures. Centralized Systems

Lecture 4. Parallel Programming II. Homework & Reading. Page 1. Projects handout On Friday Form teams, groups of two

Chapter 2 Parallel Architecture, Software And Performance

What is Multi Core Architecture?

McMPI. Managed-code MPI library in Pure C# Dr D Holmes, EPCC dholmes@epcc.ed.ac.uk

Introduction to Cloud Computing

OpenMP Programming on ScaleMP

HPC Wales Skills Academy Course Catalogue 2015

PARALLEL PROGRAMMING

COMP/CS 605: Introduction to Parallel Computing Lecture 21: Shared Memory Programming with OpenMP

A Case Study - Scaling Legacy Code on Next Generation Platforms

Parallel and Distributed Computing Programming Assignment 1

High Performance Computing in CST STUDIO SUITE

IMCM: A Flexible Fine-Grained Adaptive Framework for Parallel Mobile Hybrid Cloud Applications

GPU File System Encryption Kartik Kulkarni and Eugene Linkov

Load Imbalance Analysis

Overlapping Data Transfer With Application Execution on Clusters

Hybrid Programming with MPI and OpenMP

Optimizing Shared Resource Contention in HPC Clusters

The Double-layer Master-Slave Model : A Hybrid Approach to Parallel Programming for Multicore Clusters

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

Course Development of Programming for General-Purpose Multicore Processors

BLM 413E - Parallel Programming Lecture 3

How to control Resource allocation on pseries multi MCM system

PeerMon: A Peer-to-Peer Network Monitoring System

ScaAnalyzer: A Tool to Identify Memory Scalability Bottlenecks in Parallel Programs

Making Multicore Work and Measuring its Benefits. Markus Levy, president EEMBC and Multicore Association

Parallel Scalable Algorithms- Performance Parameters

A Flexible Cluster Infrastructure for Systems Research and Software Development

Debugging with TotalView

22S:295 Seminar in Applied Statistics High Performance Computing in Statistics

Why Threads Are A Bad Idea (for most purposes)

Cluster, Grid, Cloud Concepts

OpenACC 2.0 and the PGI Accelerator Compilers

CHAPTER 1 INTRODUCTION

HPC Deployment of OpenFOAM in an Industrial Setting

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Application and Micro-benchmark Performance using MVAPICH2-X on SDSC Gordon Cluster

Running applications on the Cray XC30 4/12/2015

Evaluation of CUDA Fortran for the CFD code Strukti

5MD00. Assignment Introduction. Luc Waeijen

Program Optimization for Multi-core Architectures

Intro to GPU computing. Spring 2015 Mark Silberstein, , Technion 1

Parallel Computing using MATLAB Distributed Compute Server ZORRO HPC

Parallelization of video compressing with FFmpeg and OpenMP in supercomputing environment

A Simultaneous Solution for General Linear Equations on a Ring or Hierarchical Cluster

Centralized Systems. A Centralized Computer System. Chapter 18: Database System Architectures

Trends in High-Performance Computing for Power Grid Applications

OpenACC Programming and Best Practices Guide

FPGA-based Multithreading for In-Memory Hash Joins

BIG CPU, BIG DATA. Solving the World s Toughest Computational Problems with Parallel Computing. Alan Kaminsky

Performance Analysis and Optimization Tool

Multicore Programming with LabVIEW Technical Resource Guide

Transcription:

MPI and Hybrid Programming Models William Gropp www.cs.illinois.edu/~wgropp

2 What is a Hybrid Model? Combination of several parallel programming models in the same program May be mixed in the same source May be combinations of components or routines, each of which is in a single parallel programming model MPI + Threads or MPI + OpenMP is the most familiar hybrid model (that involves MPI) There are other interesting choices for which we should prepare

3 Why a Hybrid Model? Note that in some ways MPI is already a hybrid programming model (MPI + C; MPI + Fortran) Adding a third programming model is not a major change Also note that many applications are multilingual, built from pieces in C, C++, Python, Matlab, Developers use the best tool for each part of their program Scale of machines to come encourage the use of different programming models to address issues such as Declining memory per core Multiple threads/core Load balance Algorithmic issues

4 MPI and Threads MPI describes parallelism between processes (with separate address spaces) Thread parallelism provides a shared-memory model within a process OpenMP and Pthreads are common models OpenMP provides convenient features for loop-level parallelism. Threads are created and managed by the compiler, based on user directives. Pthreads provide more complex and dynamic approaches. Threads are created and managed explicitly by the user.

5 Programming for Multicore Almost all chips are multicore these days Today s clusters often comprise multiple CPUs per node sharing memory, and the nodes themselves are connected by a network Common options for programming such clusters All MPI Use MPI to communicate between processes both within a node and across nodes MPI implementation internally uses shared memory to communicate within a node MPI + OpenMP (or MPI + OpenACC) Use OpenMP within a node and MPI across nodes MPI + Pthreads Use Pthreads within a node and MPI across nodes The latter two approaches are known as hybrid programming

6 Myths About the MPI + OpenMP Hybrid Model 1. Never works Examples from FEM assembly, others show benefit 2. Always works Examples from NAS, EarthSim, others show MPI everywhere often as fast (or faster!) as hybrid models 3. Requires a special thread-safe MPI In many cases does not; in others, requires a level defined in MPI-2 4. Harder to program Harder than what? Really the classic solution to complexity - divide problem into separate problems 10000-fold coarse-grain parallelism + 100-fold fine-grain parallelism gives 1,000,000-fold total parallelism

7 Special Note Because neither 1 nor 2 are true, and 4 isn't entirely false, it is important for applications to engineer codes for the hybrid model. Applications must determine their: Memory bandwidth requirements Memory hierarchy requirements Load Balance Don't confuse problems with getting good performance out of OpenMP with problems with the Hybrid programming model See Using OpenMP by Barbara Chapman, Gabriele Jost and Ruud van der Pas, Chapters 5 and 6, for programming OpenMP for performance See pages 207-211 where they discuss the hybrid model

MPI s Four Levels of Thread Safety MPI defines four levels of thread safety. These are in the form of commitments the application makes to the MPI implementation. MPI_THREAD_SINGLE: only one thread exists in the application MPI_THREAD_FUNNELED: multithreaded, but only the main thread makes MPI calls (the one that called MPI_Init or MPI_Init_thread) MPI_THREAD_SERIALIZED: multithreaded, but only one thread at a time makes MPI calls MPI_THREAD_MULTIPLE: multithreaded and any thread can make MPI calls at any time (with some restrictions to avoid races see next slide) 8 8

Specifying the Level of Thread Safety MPI defines an alternative to MPI_Init MPI_Init_thread(argc, argv, requested, provided) Application indicates what level it needs; MPI implementation returns the level it supports Many (not all) builds of MPICH exploit this runtime control If you don t need thread safety, there is little extra cost 9

Specification of MPI_THREAD_MULTIPLE When multiple threads make MPI calls concurrently, the outcome will be as if the calls executed sequentially in some (any) order Blocking MPI calls will block only the calling thread and will not prevent other threads from running or executing MPI functions It is the user's responsibility to prevent races when threads in the same application post conflicting MPI calls e.g., accessing an info object from one thread and freeing it from another thread User must ensure that collective operations on the same communicator, window, or file handle are correctly ordered among threads e.g., cannot call a broadcast on one thread and a reduce on another thread on the same communicator 10 10

Threads and MPI in MPI-2 (and MPI-3) An implementation is not required to support levels higher than MPI_THREAD_SINGLE; that is, an implementation is not required to be thread safe A fully thread-safe implementation will support MPI_THREAD_MULTIPLE A program that calls MPI_Init (instead of MPI_Init_thread) should assume that only MPI_THREAD_SINGLE is supported 11 11

12 The Current Situation All MPI implementations support MPI_THREAD_SINGLE (duh). They probably support MPI_THREAD_FUNNELED even if they don t admit it. Does require thread-safe malloc Probably OK in simple OpenMP programs Many (but not all) implementations support THREAD_MULTIPLE Hard to implement efficiently though (lock granularity issue) Easy OpenMP programs (loops parallelized with OpenMP, communication in between loops) only need FUNNELED So don t need thread-safe MPI for many hybrid programs But watch out for Amdahl s Law!

13 What MPI s Thread Safety Means in the Hybrid MPI+OpenMP Context MPI_THREAD_SINGLE There is no OpenMP multithreading in the program. MPI_THREAD_FUNNELED All of the MPI calls are made by the master thread. i.e. all MPI calls are Outside OpenMP parallel regions, or Inside OpenMP master regions, or Guarded by call to MPI_Is_thread_main MPI call. - (same thread that called MPI_Init_thread) MPI_THREAD_SERIALIZED #pragma omp parallel #pragma omp single { MPI calls allowed here } MPI_THREAD_MULTIPLE Any thread may make an MPI call at any time

14 Some Things to Watch for in OpenMP No standard way to manage memory affinity First touch (have intended owning thread perform first access) provides initial static mapping of memory Next touch (move ownership to most recent thread) could help No portable way to reassign affinity reduces the effectiveness of OpenMP when used to improve load balancing. Memory model can require explicit memory flush operations Defaults allow race conditions Humans notoriously poor at recognizing all races It only takes one mistake to create a hard-to-find bug

15 Some Things to Watch for in MPI + OpenMP No interface for apportioning resources between MPI and OpenMP On an SMP node, how many MPI processes and how many OpenMP Threads? Note the static nature assumed by this question Note that having more threads than cores can be important for hiding latency Requires very lightweight threads Competition for resources Particularly memory bandwidth and network access Apportionment of network access between threads and processes is also a problem, as we ve already seen.

16 Where Does the MPI + OpenMP Hybrid Model Work Well? Compute-bound loops Many operations per memory load Fine-grain parallelism Algorithms that are latency-sensitive Load balancing Similar to fine-grain parallelism; ease of Memory bound loops

17 Compute-Bound Loops Loops that involve many operations per load from memory This can happen in some kinds of matrix assembly, for example. Life update partially compute bound (all of those branches) Jacobi update not compute bound

18 Fine-Grain Parallelism Algorithms that require frequent exchanges of small amounts of data E.g., in blocked preconditioners, where fewer, larger blocks, each managed with OpenMP, as opposed to more, smaller, single-threaded blocks in the all-mpi version, gives you an algorithmic advantage (e.g., fewer iterations in a preconditioned linear solution algorithm). Even if memory bound

19 Load Balancing Where the computational load isn't exactly the same in all threads/ processes; this can be viewed as a variation on fine-grained access. More on this later (OpenMP currently not well-suited, unfortunately. An option is to use Pthreads directly.)

20 Memory-Bound Loops Where read data is shared, so that cache memory can be used more efficiently. Example: Table lookup for evaluating equations of state Table can be shared If table evaluated as necessary, evaluations can be shared

Where is Pure MPI Better? Trying to use OpenMP + MPI on very regular, memory-bandwidth-bound computations is likely to lose because of the better, programmer-enforced memory locality management in the pure MPI version. Another reason to use more than one MPI process - if a single process (or thread) can't saturate the interconnect - then use multiple communicating processes or threads. Note that threads and processes are not equal - see next slides 21

Tests with Multiple Threads versus Processes Consider these two cases: Nodes with 4 cores 1 process with four threads sends to 1 process with four threads, each thread sending, or 4 processes, each with one thread, sending to a corresponding thread User expectation is that the performance is the same Results are joint work with Rajeev Thakur (Argonne) T T T T P P P P T T T T P P P P 22 22

23 Concurrent Bandwidth Test Lesson: Its hard to provide full performance from threads (Recent results on current platforms show similar behavior)

24 Locality is Critical Placement of processes and threads is critical for performance Placement of processes impacts use of communication links; poor placement creates more communication Placement of threads within a process on cores impacts both memory and intranode performance Threads must bind to preserve cache In multi-chip nodes, some cores closer than others same issue as processes MPI has limited, but useful, features for placement

25 Importance of ordering processes/ threads within a multichip node core core core core 0,0 2,0 0,1 2,1 core core core core 1,0 3,0 1,1 3,1 2x4 processes in a mesh How should they be mapped onto this single node? Round robin (by chip)? Labels are coordinates of process in logical computational mesh Results in 3x interchip communication than the natural order Same issue results if there is 1 process with 4 threads on each chip, or 1 process with 8 threads on the node

26 Hybrid Model Options: Fine Fine grain model: Program is single threaded except when actively using multiple threads, e.g., for loop processing Pro: Easily added to existing MPI program Con: Adds overhead in creating and/or managing threads Locality and affinity may be an issue (no guarantees) Amdahl s Law problem serial sections limit speedup

27 Hybrid Model Options: Coarse Coarse grain model Majority of program runs within omp parallel Pro: Lowers overhead of using threads, including creation, locality, and affinity Promotes a more parallel coding style Con: More complex coding, easier to introduce race condition errors

28 Challenges for Programming Models Parallel programming models need to provide ways to coordinate resource allocation Numbers of cores/threads Assignment (affinity) of cores/threads Intranode memory bandwidth Internode memory bandwidth They must also provide clean ways to share data Consistent memory models Decide whether its best to make it easy and transparent for the programmer (but slow) or fast but hard (or impossible, which is often the current state) Remember, parallel programming is about performance You will always get higher programmer productivity with a single threaded code

29 Challenges for Implementations Sharing of communication infrastructure For example, the Berkeley UPC implementation makes use of GASNET, an efficient, portable communication layer But GASNET does not provide all of the features required by an efficient, full MPI implementation Similarly, the communication layer used by MPI implementations may not provide all of the features needed by UPC (see Problems with using MPI 1.1 and 2.0 as compilation targets for parallel language implementations, Dan Bonachea, Jason Duell) It is possible to build such infrastuctures But current examples only address some of the issues. Resource allocation and sharing not covered

30 Conclusions Hybrid programming models exploit complementary strengths In many cases, can replace OpenMP with OpenACC or other accelerator programming system Evolutionary Path to Hybrid Models Short term - better support for resource sharing We need to experiment with specifying additional information, e.g., through mpiexec Medium term - better support for interoperating components We need to ensure that communication infrastructures can cooperate Consider extensions to make implementations aware that they are in a hybrid model program Long term - Generalized model, efficient sharing of communication and computation infrastructure