47
יייי יייייי יייייי – ייייי יי'2 29.10.01 ייייי יי ייייי ייייייי

מבוא לעיבוד מקבילי – הרצאה מס' 2

Embed Size (px)

DESCRIPTION

מבוא לעיבוד מקבילי – הרצאה מס' 2. 29.10.01 תרגול על המערך המקבילי. מטרות המפגש היום. לוודא כי לכל זוג יש חשבון משתמש על המערך המקבילי. תרגול ביצוע משימות בסיסיות תחת מערכת ההפעלה Linux . הרצת תכניות מקביליות בסיסיות המשתמשות ב- MPI. יעדים. יישור קו הכרות ראשונית עם MPI. - PowerPoint PPT Presentation

Citation preview

Page 1: מבוא לעיבוד מקבילי – הרצאה מס' 2

מבוא לעיבוד מקבילי – הרצאה מס' 2

29.10.01תרגול על המערך המקבילי

Page 2: מבוא לעיבוד מקבילי – הרצאה מס' 2

מטרות המפגש היום

לוודא כי לכל זוג יש חשבון משתמש על המערך •המקבילי.

תרגול ביצוע משימות בסיסיות תחת מערכת •.Linuxההפעלה

הרצת תכניות מקביליות בסיסיות המשתמשות •.MPIב-

Page 3: מבוא לעיבוד מקבילי – הרצאה מס' 2

יעדים

יישור קו •MPIהכרות ראשונית עם •

Page 4: מבוא לעיבוד מקבילי – הרצאה מס' 2

Basic Linux Commands – 1/5Enter the systemlogin: username

password: passwdExit the systemexit

Text editorspico, vi, Emacs

C Compilergcc –o file file.c

Page 5: מבוא לעיבוד מקבילי – הרצאה מס' 2

Basic Linux Commands – 2/5DOSLinux

See filesdirlsls -l

Copy filescopycp

Erase filesdelrm

Page 6: מבוא לעיבוד מקבילי – הרצאה מס' 2

Basic Linux Commands – 3/5DOSLinux

Make directory

mkdirmkdir

Remove directory

rmdirrmdir

More/Renamerenamemv

OS versionveruname -a

Page 7: מבוא לעיבוד מקבילי – הרצאה מס' 2

Basic Linux Commands – 4/5

• Getting help: man topic• Looking at the contents of a file: more• Quit from man or more: q• Where am I? pwd• Clear the screen: clear• Print the contents of a file: cat

Page 8: מבוא לעיבוד מקבילי – הרצאה מס' 2

Basic Linux Commands – 5/5

• Redirection: >, >>• Pipe: |• telnet• ftp• ping• chmod• chown

Page 9: מבוא לעיבוד מקבילי – הרצאה מס' 2

Linux FAQ

http://www.ctssn.com/linux/linuxfaq.html

Page 10: מבוא לעיבוד מקבילי – הרצאה מס' 2

The vi EditorESC Puts you in command modeh, j, k, l Left, down, up, right or use the arrows keysw, W, b, B Forward, backward by word0, $ First, last position of current line/pattern Search forward for pattern?pattern Search backward for patternn,N Repeat last search in same, opposite directionx Delete characterdd Delete current lineD Delete to end of linedw Delete wordp, P Put deleted text before, after cursoru Undo last command. Repeat the last commandi, a Insert text before, after cursor [Puts you into INPUT MODE]o, O Open new line for text below, above cursor [Puts you into INPUT MODE]ZZ Save file and quit:w Save file:q! Quit, without saving changes

Page 11: מבוא לעיבוד מקבילי – הרצאה מס' 2

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).

Page 12: מבוא לעיבוד מקבילי – הרצאה מס' 2

The Dwarves Networking: Two Kinds of NICs

dwarf1 ..dwarf12 – nodes names for the Fast Ethernet link

dwarf1m .. dwarf12m – nodes names for the Myrinet network

Page 13: מבוא לעיבוד מקבילי – הרצאה מס' 2

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

Page 14: מבוא לעיבוד מקבילי – הרצאה מס' 2

Connecting to the Dwarves

Page 15: מבוא לעיבוד מקבילי – הרצאה מס' 2

1תרגיל מס'

.telnetהתחבר לאחת מהתחנות תוך שימוש ב- •Hello Worldכתוב תכנית מחשב קצרה כגון: •בצע קומפילציה:•

gcc –o hello_world hello_world.cהרץ את התכנית ושמור הפלט:•

% ./hello_world > hello.txtבדוק את הפלט על-ידי:•

• more hello.txt

Page 16: מבוא לעיבוד מקבילי – הרצאה מס' 2

1/3 – 1פתרון תרגיל מס'

Page 17: מבוא לעיבוד מקבילי – הרצאה מס' 2

2/3 – 1פתרון תרגיל מס'

Page 18: מבוא לעיבוד מקבילי – הרצאה מס' 2

3/3 – 1פתרון תרגיל מס'

Page 19: מבוא לעיבוד מקבילי – הרצאה מס' 2

What is message passing?•Data transfer plus synchronization

Requires cooperation of sender and receiver

DataProcess 0

Process 1

May I Send?

Yes

DataDataDataDataDataDataDataData

Time

Page 20: מבוא לעיבוד מקבילי – הרצאה מס' 2

Message-Passing Abstraction

Process P Process Q

Address Y

Address X

Send X, Q, t

Receive Y, P, tMatch

Local processaddress space

Local processaddress space

•Send specifies buffer to be transmitted and receiving process•Recv specifies sending process and application storage to receive into•Memory to memory copy, but need to name processes•Optional tag on send and matching rule on receive•User process names local data and entities in process/tag space too•In simplest form, the send/recv match achieves pairwise synch event

–Other variants too•Many overheads: copying, buffer management, protection

Page 21: מבוא לעיבוד מקבילי – הרצאה מס' 2

Space-Time Diagram of a Message-Passing Program

Page 22: מבוא לעיבוד מקבילי – הרצאה מס' 2

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

Page 23: מבוא לעיבוד מקבילי – הרצאה מס' 2

MPI Naming Conventions

MPI_Xxxxx(parameter,...)

Example:MPI_Init(&argc,&argv).

Page 24: מבוא לעיבוד מקבילי – הרצאה מס' 2

The First 4 Functions of MPI

• MPI_Init• MPI_Finalize• MPI_Comm_size• MPI_Comm_rank

Page 25: מבוא לעיבוד מקבילי – הרצאה מס' 2

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)

Page 26: מבוא לעיבוד מקבילי – הרצאה מס' 2

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.

Page 27: מבוא לעיבוד מקבילי – הרצאה מס' 2

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);

Page 28: מבוא לעיבוד מקבילי – הרצאה מס' 2

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);

Page 29: מבוא לעיבוד מקבילי – הרצאה מס' 2

MPI DatatypesMPI Datatype C TypeMPI_CHAR signed charMPI_SHORT signed short intMPI_INT signed intMPI_LONG signed long intMPI_UNSIGNED_CHAR unsigned charMPI_UNSIGNED_SHORT unsigned short intMPI_UNSIGNED unsigned intMPI_UNSIGNED_LONG unsigned long int MPI_FLOAT floatMPI_DOUBLE doubleMPI_LONG_DOUBLE long doubleMPI_BYTE (none)MPI_PACKED (none)

Page 30: מבוא לעיבוד מקבילי – הרצאה מס' 2

MPI Example: MandelbrotMPICH 1.2.1 Running on Windows NT (Dual Celeron 400MHz)

Compiled with Visual C++ 6.

Page 31: מבוא לעיבוד מקבילי – הרצאה מס' 2

Home Work #1 : MPI Tutorialhttp://www-unix.mcs.anl.gov/mpi/tutorial/index.htmlFour-up Postscript for Tutorial on MPI (tutorial4.ps)

Page 32: מבוא לעיבוד מקבילי – הרצאה מס' 2

2תרגיל מס'

:MPIהרצת תכנית קצרה ב- •–Hello_Worldמקבילי

כתוב תכנית בה כל מחשב יאמר שלום ויודיע •את מספר התהליך שלו בריצה:

Hello world from process 1 of 2

Page 33: מבוא לעיבוד מקבילי – הרצאה מס' 2

1/3 – 2פתרון תרגיל מס' #include <stdio.h>#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;}

Page 34: מבוא לעיבוד מקבילי – הרצאה מס' 2

2/3 – 2פתרון תרגיל מס'

helloworld: helloworld.cmpicc -o helloworld helloworld.c

clean:/bin/rm -f helloworld *.o

% make

The Makefile

Page 35: מבוא לעיבוד מקבילי – הרצאה מס' 2

Hello World - Execution% mpicc -o helloworld helloworld.c% mpirun -np 4 helloworldHello world from process 0 of 4Hello world from process 3 of 4Hello world from process 1 of 4Hello world from process 2 of 4%

Page 36: מבוא לעיבוד מקבילי – הרצאה מס' 2

: חישוב 3תרגיל מס'

חישוב באמצעות אינטגרציה•

f(x)=4/(1+x2)נבצע אינטגרציה על הפונקציה • חלקיםn על-ידי חלוקת התחום ל- 1 ל- 0בין

4)1arctan()0arctan()1arctan(|)arctan(

11 1

0

1

02

xdxx

Page 37: מבוא לעיבוד מקבילי – הרצאה מס' 2

3פתרון תרגיל מס'

בפתרון השתמשנו בפונקציה למדידת זמן•)(MPI_Wtimeהנקראת: •

ראה דוגמא לפתרון התרגיל תחת:•/usr/local/mpich/examples/basic/cpi.c

Page 38: מבוא לעיבוד מקבילי – הרצאה מס' 2

3פתרון תרגיל מס' #include "mpi.h"#include <stdio.h>#include <math.h>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];

Page 39: מבוא לעיבוד מקבילי – הרצאה מס' 2

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;

Page 40: מבוא לעיבוד מקבילי – הרצאה מס' 2

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 {

Page 41: מבוא לעיבוד מקבילי – הרצאה מס' 2

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(;

Page 42: מבוא לעיבוד מקבילי – הרצאה מס' 2

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 */

Page 43: מבוא לעיבוד מקבילי – הרצאה מס' 2

1תרגיל הגשה מס'

העבודה תתבצע בזוגות• תוך שבועיים Emailהתרגיל יוגש באמצעות ה- •

היום האחרון להגשה הוא יום ב' ה- – 12/11/01.

יש לתעד את התכנית.•חובה!אמנם התרגיל הוא ללא ציון, אך הגשתו •

Page 44: מבוא לעיבוד מקבילי – הרצאה מס' 2

:1תרגיל הגשה מס' אינטגרציה בשיטת הטרפז

כתוב תכנית מחשב מקבילית המבצעת אינטגרציה •בשיטת הטרפז

השתמש בפקודות העברת מסרים בין המעבדים • שנלמדו בשיעור: Point-to-Pointמטיפוס

MPI_Send -ו MPI_Recv יקבל מהמשתמש את תחום 0מעבד מס' •

b ל- aלדוגמה, מ- האינטגרציה ואת מס' הטרפזים: טרפזים.nעם

Page 45: מבוא לעיבוד מקבילי – הרצאה מס' 2

1תרגיל הגשה מס'

ירכז אליו את תוצאות הביניים 0מעבד מס' •הנשלחות מהמעבדים וידפיס את התוצאה הסופית.

כמו-כן, יש להדפיס את גבולות האינטגרציה ומס' .nהטרפזים,

פעמים עבור שלושה ערכים של 3להריץ התכנית •n: n=100 ,1000 ,10000

יש לצרף את הפלט של הריצות•

Page 46: מבוא לעיבוד מקבילי – הרצאה מס' 2

1תרגיל הגשה מס'

הפונקציה עליה יש לבצע את האינטגרציה היא •פולינום ממעלה שלישית:

השווה עם התוצאה האנליטית•

3

0

i

iix

Page 47: מבוא לעיבוד מקבילי – הרצאה מס' 2

1תרגיל הגשה מס'

גבולות האינטגרציה הם:•a=Min(ID1,ID2)/1000000b=Max(ID1,ID2)/1000000

הם מספרי ת.ז. של המגישים, ID2 ו- ID1כאשר •כולל ספרת ביקורת.