Download presentation
Presentation is loading. Please wait.
1
מבוא לעיבוד מקבילי – הרצאה מס ' 2 תרגול MPI על המערך המקבילי
2
מטרות השיעור לוודא כי לכל זוג יש חשבון משתמש על המערך המקבילי. תרגול ביצוע משימות בסיסיות תחת מערכת ההפעלה Linux. הרצת תכניות מקביליות בסיסיות המשתמשות ב - MPI.
3
יעדים יישור קו הכרות ראשונית עם MPI
4
Basic Linux Commands – 1/5 login: username password: passwd Enter the system exitExit the system pico, vi, Emacs or Edit on Windows then transfer with ftp Text editors gcc –o file file.cC Compiler
5
Basic Linux Commands – 2/5 LinuxDOS ls ls -l dirSee files cpcopyCopy files rmdelErase files
6
Basic Linux Commands – 3/5 LinuxDOS mkdir Make directory rmdir Remove directory mvrenameMore/Rename uname -averOS version
7
Basic Linux Commands – 4/5 Getting help: man topic Look at the contents of a file: cat, more,head and tail Quit from man or more: q Where am I? pwd Clear the screen: clear
8
Basic Linux Commands – 5/5 Redirection: >, >> Pipe: | telnet ftp ping chmod chown
9
Linux FAQ http://www.ctssn.com/linux/linuxfaq.html
10
The vi Editor ESCPuts you in command mode h, j, k, lLeft, down, up, right or use the arrows keys w, W, b, BForward, backward by word 0, $First, last position of current line /patternSearch forward for pattern ?patternSearch backward for pattern n,NRepeat last search in same, opposite direction xDelete character ddDelete current line DDelete to end of line dwDelete word p, PPut deleted text before, after cursor uUndo last command.Repeat the last command i, aInsert text before, after cursor [Puts you into INPUT MODE] o, OOpen new line for text below, above cursor [Puts you into INPUT MODE] ZZSave file and quit :wSave file :q!Quit, without saving changes
11
vi reference card Download and print: http://my.pages.de/vi-refcard.html http://vh224401.truman.edu/~dbindner/mirr or/vi-ref.pdf
12
Our Parallel Cluster: The Dwarves There are 12 computers with Linux operating system. dwarf[1-12] or dwarf[1-12]m dwarf1[m], dwarf3[m]-dwarf7[m] - Pentium II 300 MHz, dwarf9[m]-dwarf12[m] - Pentium III 450 MHz (dual CPU), dwarf2[m], dwarf8[m] - Pentium III 733 MHz (dual CPU).
13
The Dwarves Networking: Two Kinds of NICs dwarf1..dwarf14 – nodes names using Fast Ethernet dwarf1m.. dwarf12m – nodes names using Myrinet dwarf13 and dwarf14 have only Ethernet cards (no myrinet!) – use them for editing!!
14
The Dwarves IP Addresses Fast Ethernet: 132.72.53.* Where * is between 111 to 122 Myrinet: 132.72.52.* Where * is between 161 to 172
15
Connecting to the Dwarves
16
תרגיל מס ' 1 התחבר לאחת מהתחנות תוך שימוש ב - telnet. כתוב תכנית מחשב קצרה כגון : Hello World בצע קומפילציה : gcc –o hello_world hello_world.c הרץ את התכנית ושמור הפלט : %./hello_world > hello.txt בדוק את הפלט על - ידי : more hello.txt
17
פתרון תרגיל מס ' 1 – 1/3
18
פתרון תרגיל מס ' 1 – 2/3
19
פתרון תרגיל מס ' 1 – 3/3
20
MPI-Quick reference card 1/2
21
MPI-Quick reference card 2/2
22
What is message passing? Data transfer plus synchronization l Requires cooperation of sender and receiver DataProcess 0 Process 1 May I Send? Yes Data Time
23
Point to Point: Basic Send/Receive תהליך מס ' 1 x Send(&x,2); תהליך מס ' 2 y Recv(&y,1); הזזת נתונים
24
Space-Time Diagram of a Message-Passing Program
25
MPI - Message Passing Library MPI is a standard not an implementation Popular implementations are LAM and MPICH MPICH is installed under /usr/local/mpich Always put in the code: #include “mpi.h” Compilation: mpicc –o filename file.c Executing: mpirun –np N filename
26
MPI Naming Conventions MPI_Xxxxx(parameter,...) Example: MPI_Init(&argc,&argv ).
27
The First 4 Functions of MPI MPI_Init MPI_Finalize MPI_Comm_size MPI_Comm_rank
28
The First 4 Functions Syntax int MPI_Init(*argc, ***argv) int MPI_Finilize() int MPI_Comm_size(MPI_Comm comm, int *size) int MPI_Comm_rank(MPI_Comm comm, int *rank)
29
MPI Communicator A communicator is a handle representing a group of processors that can communicate with one another. The communicator name is required as an argument to all point-to-point and collective operations. The communicator specified in the send and receive calls must agree for communication to take place. Processors can communicate only if they share a communicator.
30
Basic Point to Point Functions MPI_Send MPI_Recv MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status status);
31
Basic Collective Functions MPI_Bcast MPI_Reduce The exact syntax: MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm); MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
32
MPI Data types MPI data typeC Type MPI_CHAR signed char MPI_SHORT signed short int MPI_INT signed int MPI_LONG signed long int MPI_UNSIGNED_CHAR unsigned char MPI_UNSIGNED_SHORT unsigned short int MPI_UNSIGNED unsigned int MPI_UNSIGNED_LONG unsigned long int MPI_FLOAT float MPI_DOUBLE double MPI_LONG_DOUBLE long double MPI_BYTE (none) MPI_PACKED (none)
33
MPI Example: Mandelbrot MPICH 1.2.1 Running on Windows NT (Dual Celeron 400MHz) Compiled with Visual C++ 6.
34
Home Work #1: MPI Tutorial http://www-unix.mcs.anl.gov/mpi/tutorial/index.html Four-up Postscript for Tutorial on MPI (tutorial4.ps)
35
תרגיל מס ' 2 הרצת תכנית קצרה ב - MPI: –Hello_World מקבילי כתוב תכנית בה כל מחשב יאמר שלום ויודיע את מספר התהליך שלו בריצה : Hello world from process 1 of 2
36
פתרון תרגיל מס ' 2 – 1/3 #include #include "mpi.h" int main( argc, argv ) int argc; char **argv; { int rank, size; MPI_Init( &argc, &argv ); MPI_Comm_size( MPI_COMM_WORLD, &size ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0; }
37
פתרון תרגיל מס ' 2 – 2/3 helloworld: helloworld.c mpicc -o helloworld helloworld.c clean: /bin/rm -f helloworld *.o % make The Makefile
38
תרגיל מס ' 2 : מימוש ב - C++
39
Hello World - Execution % mpicc -o helloworld helloworld.c % mpirun -np 4 helloworld Hello world from process 0 of 4 Hello world from process 3 of 4 Hello world from process 1 of 4 Hello world from process 2 of 4 %
40
תרגיל מס ' 3 : חישוב חישוב באמצעות אינטגרציה נבצע אינטגרציה על הפונקציה f(x)=4/(1+x 2 ) בין 0 ל - 1 על - ידי חלוקת התחום ל - n חלקים
41
פתרון תרגיל מס ' 3 בפתרון השתמשנו בפונקציה למדידת זמן הנקראת : MPI_Wtime() ראה דוגמא לפתרון התרגיל תחת : /usr/local/mpich/examples/basic/cpi.c
42
פתרון תרגיל מס ' 3 #include "mpi.h" #include double f(double a) { return (4.0 / (1.0 + a*a)); } void main(int argc, char *argv[]) { int done = 0, n, myid, numprocs, i; double PI25DT = 3.141592653589793238462643; double mypi, pi, h, sum, x; double startwtime, endwtime; int namelen; char processor_name[MPI_MAX_PROCESSOR_NAME];
43
פתרון תרגיל מס ' 3 - המשך MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); MPI_Get_processor_name(processor_name,&namelen); fprintf(stderr,"Process %d on %s\n",myid, processor_name); fflush(stderr); n = 0;
44
פתרון תרגיל מס ' 3 - המשך while (!done) { if (myid == 0) { printf("Enter the number of intervals: (0 quits) "); fflush(stdout); scanf("%d",&n); startwtime = MPI_Wtime(); } MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); if (n == 0) done = 1; else {
45
פתרון תרגיל מס ' 3 - המשך h = 1.0 / (double) n; sum = 0.0; for (i = myid + 1; i <= n; i += numprocs) { x = h * ((double)i - 0.5); sum += f(x); } mypi = h * sum; MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
46
פתרון תרגיל מס ' 3 - המשך if (myid == 0) { printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT)); endwtime = MPI_Wtime(); printf("wall clock time = %f\n",endwtime-startwtime); } } /* end of if */ } /* end of while */ MPI_Finalize(); } /* end of main */
47
הרצת 4 תהליכים
48
הרצת שני תהליכים על שני מעבדים
49
הערכת ביצועי הריצה 1/2
50
הערכת ביצועי הריצה 2/2
51
תרגיל הגשה מס ' 1 העבודה תתבצע בזוגות התרגיל יוגש באמצעות ה - Email תוך שבועיים – היום האחרון להגשה הוא עד לשיעור בעוד שבועיים ( שבוע 4). יש לתעד את התכנית. אמנם התרגיל הוא ללא ציון, אך הגשתו חובה !
52
תרגיל הגשה מס ' 1: מטרות התרגיל – הכרות ראשונית עם MPI: פקודות תקשורת מסוג Point-to-Point. פקודות תקשורת קולקטיביות. – מיקבול בשיטת Master-workers.
53
תרגיל הגשה מס ' 1: אינטגרציה בשיטת הטרפז כתוב תכנית מחשב מקבילית המבצעת אינטגרציה בשיטת הטרפז לפולינום ממעלה שלישית ( ראה בהמשך ). השתמש בפקודות MPI להעברת מסרים בין המעבדים שנלמדו בשיעור : Send, Recv, Bcast and Reduce בפעם הראשונה, השתמש בפקודות Point-to-Point בלבד. בפעם השניה השתמש בפקודות קולקטיביות בלבד. השווה זמני ריצה בין שתי הפעמים.
54
תרגיל הגשה מס ' 1 מעבד מס ' 0 יקבל מהמשתמש את תחום האינטגרציה ואת מס ' הטרפזים : לדוגמה, מ -a ל - b עם n טרפזים. מעבד מס ' 0 ירכז אליו את תוצאות הביניים הנשלחות מהמעבדים וידפיס את התוצאה הסופית. כמו - כן, יש להדפיס את גבולות האינטגרציה ומס ' הטרפזים, n. קבע את n כך שהשגיאה בתוצאה תהיה קטנה מ - 0.001 יש לצרף את הפלט של הריצות ואת התוצאה האנליטית.
55
תרגיל הגשה מס ' 1 הפונקציה עליה יש לבצע את האינטגרציה היא פולינום ממעלה שלישית : גבולות האינטגרציה הם לבחירתכם, אך ציינו אותם בפלט. להשוות עם התוצאה האנליטית !
56
תרגיל הגשה מס ' 1: נקודות למחשבה : – האם ה - master עושה גם - כן חישוב או רק אדמיניסטרציה ? – האם ניתן להריץ את התכנית גם עם תהליך אחד בלבד mpirun –np 1 exe1?
57
בשבוע הבא... לימוד MPI השיעור יתקיים בכיתות הלימוד הרגילות קבוצה מס ' 1 : שינוי חדר לימוד : בניין 90 חדר 127
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.