Supercomputingin Plain English Distributed Multiprocessing.ppt

上传人:花仙子 文档编号:389478 上传时间:2018-10-14 格式:PPT 页数:65 大小:584KB
下载 相关 举报
Supercomputingin Plain English Distributed Multiprocessing.ppt_第1页
第1页 / 共65页
Supercomputingin Plain English Distributed Multiprocessing.ppt_第2页
第2页 / 共65页
Supercomputingin Plain English Distributed Multiprocessing.ppt_第3页
第3页 / 共65页
Supercomputingin Plain English Distributed Multiprocessing.ppt_第4页
第4页 / 共65页
Supercomputingin Plain English Distributed Multiprocessing.ppt_第5页
第5页 / 共65页
亲,该文档总共65页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、Supercomputing in Plain English Distributed Multiprocessing,Henry Neeman Director OU Supercomputing Center for Education & Research November 19 2004,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,2,Outline,The Desert Islands Analogy Distribute

2、d Parallelism MPI,The Desert Islands Analogy,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,4,An Island Hut,Imagine youre on a desert island in a little hut. Inside the hut is a desk and a chair. On the desk is:a phone; a pencil; a calculator;

3、 a piece of paper with instructions; a piece of paper with numbers.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,5,Instructions,The instructions are split into two kinds: Arithmetic/Logical: e.g., Add the 27th number to the 239th number Comp

4、are the 96th number to the 118th number to see whether they are equal Communication: e.g.,dial 555-0127 and leave a voicemail containing the 962nd number call your voicemail box and collect a voicemail from 555-0063 and put that number in the 715th slot,Supercomputing in Plain English: Distributed P

5、arallel OU Supercomputing Center for Education & Research,6,Is There Anybody Out There?,If youre in a hut on an island, you arent specifically aware of anyone else. Especially, you dont know whether anyone else is working on the same problem as you are, and you dont know whos at the other end of the

6、 phone line. All you know is what to do with the voicemails you get, and what phone numbers to send voicemails to.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,7,Someone Might Be Out There,Now suppose that Julie is on another island somewher

7、e, in the same kind of hut, with the same kind of equipment. Suppose that she has the same list of instructions as you, but a different set of numbers (both data and phone numbers). Like you, she doesnt know whether theres anyone else working on her problem.,Supercomputing in Plain English: Distribu

8、ted Parallel OU Supercomputing Center for Education & Research,8,Even More People Out There,Now suppose that Lloyd and Jerry are also in huts on islands. Suppose that each of the four has the exact same list of instructions, but different lists of numbers. And suppose that the phone numbers that peo

9、ple call are each others. That is, your instructions have you call Julie, Lloyd and Jerry, Julies has her call Lloyd, Jerry and you, and so on. Then you might all be working together on the same problem, even though youre not aware of it.,Supercomputing in Plain English: Distributed Parallel OU Supe

10、rcomputing Center for Education & Research,9,All Data Are Private,Notice that you cant see Julies or Lloyds or Jerrys numbers, nor can they see yours or each others. Thus, everyones numbers are private: theres no way for anyone to share numbers, except by leaving them in voicemails.,Supercomputing i

11、n Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,10,Long Distance Calls: 2 Costs,When you make a long distance phone call, you typically have to pay two costs: Connection charge: the fixed cost of connecting your phone to someone elses, even if youre only conne

12、cted for a second Per-minute charge: the cost per minute of talking, once youre connected If the connection charge is large, then you want to make as few calls as possible.,Distributed Parallelism,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research

13、,12,Like Desert Islands,Distributed parallelism is very much like the Desert Islands analogy: processes are independent of each other. All data are private. Processes communicate by passing messages (like voicemails). The cost of passing a message is split into: latency (connection time) bandwidth (

14、time per byte),Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,13,Parallelism,Less fish ,More fish!,Parallelism means doing multiple things at the same time: you can get more work done in the same amount of time.,Supercomputing in Plain English

15、: Distributed Parallel OU Supercomputing Center for Education & Research,14,What Is Parallelism?,Parallelism is the use of multiple processing units either processors or parts of an individual processor to solve a problem, and in particular the use of multiple processing units operating concurrently

16、 on different parts of a problem. The different parts could be different tasks, or the same task on different pieces of the problems data.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,15,Kinds of Parallelism,Shared Memory Multithreading (our

17、 topic last time) Distributed Memory Multiprocessing (today) Hybrid Shared/Distributed,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,16,Why Parallelism Is Good,The Trees: We like parallelism because, as the number of processing units working

18、on a problem grows, we can solve the same problem in less time. The Forest: We like parallelism because, as the number of processing units working on a problem grows, we can solve bigger problems.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research

19、,17,Parallelism Jargon,Threads: execution sequences that share a single memory area (“address space”) Processes: execution sequences with their own independent, private memory areas and thus: Multithreading: parallelism via multiple threads Multiprocessing: parallelism via multiple processes As a ge

20、neral rule, Shared Memory Parallelism is concerned with threads, and Distributed Parallelism is concerned with processes.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,18,Jargon Alert,In principle: “shared memory parallelism” “multithreading”

21、 “distributed parallelism” “multiprocessing” In practice, these terms are often used interchangeably: Parallelism Concurrency (not as popular these days) Multithreading Multiprocessing Typically, you have to figure out what is meant based on the context.,Supercomputing in Plain English: Distributed

22、Parallel OU Supercomputing Center for Education & Research,19,Load Balancing,Suppose you have a distributed parallel code, but one process does 90% of the work, and all the other processes share 10% of the work. Is it a big win to run on 1000 processes?Now, suppose that each process gets exactly 1/N

23、p of the work, where Np is the number of processes. Now is it a big win to run on 1000 processes?,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,20,Load Balancing,Load balancing means giving everyone roughly the same amount of work to do.,Supe

24、rcomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,21,Load Balancing,Load balancing can be easy, if the problem splits up into chunks of roughly equal size, with one chunk per process. Or load balancing can be very hard.,Supercomputing in Plain Englis

25、h: Distributed Parallel OU Supercomputing Center for Education & Research,22,Load Balancing Is Good,When every process gets the same amount of work, the job is load balanced. We like load balancing, because it means that our speedup can potentially be linear: if we run on Np processes, it takes 1/Np

26、 as much time as on one. For some codes, figuring out how to balance the load is trivial (e.g., breaking a big unchanging array into sub-arrays). For others, load balancing is very tricky (e.g., a dynamically evolving collection of arbitrarily many blocks of arbitrary size).,Supercomputing in Plain

27、English: Distributed Parallel OU Supercomputing Center for Education & Research,23,Parallel Strategies,Client-Server: One worker (the server) decides what tasks the other workers (clients) will do; e.g., Hello World, Monte Carlo. Data Parallelism: Each worker does exactly the same tasks on its uniqu

28、e subset of the data; e.g., distributed meshes (weather etc). Task Parallelism: Each worker does different tasks on exactly the same set of data (each process holds exactly the same data as the others); e.g., N-body. Pipeline: Each worker does its tasks, then passes its set of data along to the next

29、 worker and receives the next set of data from the previous worker.,MPI: The Message-Passing Interface,Most of this discussion is from 1 and 2.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,25,What Is MPI?,The Message-Passing Interface (MPI)

30、is a standard for expressing distributed parallelism via message passing. MPI consists of a header file, a library of routines and a runtime environment. When you compile a program that has MPI calls in it, your compiler links to a local implementation of MPI, and then you get parallelism; if the MP

31、I library isnt available, then the compile will fail. MPI can be used in Fortran, C and C+.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,26,MPI Calls,MPI calls in Fortran look like this:CALL MPI_Funcname(, errcode) In C, MPI calls look like:

32、errcode = MPI_Funcname() In C+, MPI calls look like:errcode = MPI:Funcname() Notice that errcode is returned by the MPI routine MPI_Funcname, with a value of MPI_SUCCESS indicating that MPI_Funcname has worked correctly.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center

33、for Education & Research,27,MPI is an API,MPI is actually just an Application Programming Interface (API). An API specifies what a call to each routine should look like, and how each routine should behave. An API does not specify how each routine should be implemented, and sometimes is intentionally

34、 vague about certain aspects of a routines behavior. Each platform has its own MPI implementation.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,28,Example MPI Routines,MPI_Init starts up the MPI runtime environment at the beginning of a run.

35、 MPI_Finalize shuts down the MPI runtime environment at the end of a run. MPI_Comm_size gets the number of processes in a run, Np (typically called just after MPI_Init). MPI_Comm_rank gets the process ID that the current process uses, which is between 0 and Np-1 inclusive (typically called just afte

36、r MPI_Init).,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,29,More Example MPI Routines,MPI_Send sends a message from the current process to some other process (the destination). MPI_Recv receives a message on the current process from some ot

37、her process (the source). MPI_Bcast broadcasts a message from one process to all of the others. MPI_Reduce performs a reduction (e.g., sum, maximum) of a variable on all processes, sending the result to a single process.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center

38、for Education & Research,30,MPI Program Structure (F90),PROGRAM my_mpi_programIMPLICIT NONEINCLUDE “mpif.h“other includesINTEGER : my_rank, num_procs, mpi_error_codeother declarationsCALL MPI_Init(mpi_error_code) ! Start up MPICALL MPI_Comm_Rank(my_rank, mpi_error_code)CALL MPI_Comm_size(num_procs,

39、mpi_error_code)actual work goes hereCALL MPI_Finalize(mpi_error_code) ! Shut down MPI END PROGRAM my_mpi_program Note that MPI uses the term “rank” to indicate process identifier.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,31,MPI Program S

40、tructure (in C),#include #include “mpi.h“other includesint main (int argc, char* argv) /* main */int my_rank, num_procs, mpi_error;other declarationsmpi_error = MPI_Init( /* Shut down MPI */ /* main */,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Res

41、earch,32,Example: Hello World,Start the MPI system. Get the rank and number of processes. If youre not the server process: Create a “hello world” string. Send it to the server process. If you are the server process: For each of the client processes: Receive its “hello world” string. Print its “hello

42、 world” string. Shut down the MPI system.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,33,hello_world_mpi.c,#include #include #include “mpi.h“int main (int argc, char* argv) /* main */const int maximum_message_length = 100;const int server_r

43、ank = 0;char messagemaximum_message_length+1;MPI_Status status; /* Info about receive status */int my_rank; /* This process ID */int num_procs; /* Number of processes in run */int source; /* Process ID to receive from */int destination; /* Process ID to send to */int tag = 0; /* Message ID */int mpi

44、_error; /* Error code for MPI calls */work goes here /* main */,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,34,Hello World Startup/Shut Down,header file includes int main (int argc, char* argv) /* main */declarationsmpi_error = MPI_Init( /*

45、 main */,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,35,Hello World Clients Work,header file includes int main (int argc, char* argv) /* main */declarationsMPI startup (MPI_Init etc)if (my_rank != server_rank) sprintf(message, “Greetings fr

46、om process #%d!“,my_rank);destination = server_rank;mpi_error = MPI_Send(message, strlen(message) + 1, MPI_CHAR,destination, tag, MPI_COMM_WORLD); /* if (my_rank != server_rank) */else work of server process /* if (my_rank != server_rank)else */mpi_error = MPI_Finalize(); /* main */,Supercomputing i

47、n Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,36,Hello World Servers Work,header file includes int main (int argc, char* argv) /* main */declarations, MPI startupif (my_rank != server_rank) work of each client process /* if (my_rank != server_rank) */else fo

48、r (source = 0; source num_procs; source+) if (source != server_rank) mpi_error =MPI_Recv(message, maximum_message_length + 1,MPI_CHAR, source, tag, MPI_COMM_WORLD, /* main */,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,37,How an MPI Run Wor

49、ks,Every process gets a copy of the executable: Single Program, Multiple Data (SPMD). They all start executing it. Each looks at its own rank to determine which part of the problem to work on. Each process works completely independently of the other processes, except when communicating.,Supercomputing in Plain English: Distributed Parallel OU Supercomputing Center for Education & Research,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学课件 > 综合培训

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1