Upload
rosalind-terry
View
228
Download
6
Embed Size (px)
Citation preview
Parallel SystemsLab 1
Dr. Guy Tel-Zur
השיעור מטרות
של • העיקריות הפלטפורמות לשתי התחברותהקורס:
במעבדה – וירטואלי לינוקס מחשבהמקבילי – הקלאסטר
מערכת • תחת בסיסיות משימות ביצוע תרגולLinuxההפעלה
המשתמשות • בסיסיות מקביליות תכניות הרצת-MPIבמקבילי • בדבאגר - Allinea DDT uשימוש Profilerוב
יעדים
קו • לינוקס יישור בנושאעם • ראשונית MPIהכרות
קוד – פיתוחקימפול–שגיאות – ניפויהרצה–התוצאה – ניתוח
Basic Linux Commands – 1/5
gcc –o file file.cC Compiler
pico, vi, (x)Emacs, gedit… orEdit on Windows then transfer file using ftp
Text editors
exitExit the system
login: usernamepassword: passwd
Enter the system
Basic Linux Commands – 2/5
rmdelErase files
cpcopyCopy files
lsls -l
dirSee files
LinuxDOS
Basic Linux Commands – 3/5
mvrenameMore/Rename
uname -averOS version
rmdirrmdirRemove directory
mkdirmkdirMake directory
LinuxDOS
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
Basic Linux Commands – 5/5
• Redirection: >, >>• Pipe: |• telnet• ftp• ping• chmod• chown
Linux FAQ
http://www.ctssn.com/linux/linuxfaq.html
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 word
0, $ 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 command
i, 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
vi reference card
• Download and print:• http://my.pages.de/vi-refcard.html• http://vh224401.truman.edu/~dbindner/
mirror/vi-ref.pdf
Vi for Windows
Vi for windows
nano
Other text editors
• Vi, Vim• Pico• Emacs/Xemacs• Nedit (very friendly)• Eclipse IDE
Our Parallel Cluster:gathering information
Kernel version: uname –a
CPU information: more /proc/cpuinfo
Memory Information: more /proc/meminfo
גישה – הרשאות הפרטיות על הגנהלקבצים
Connecting to a remote node
• Secured: SSHSSH client from:
http://www.ssh.com/support/downloads/PuTTY:
http://www.chiark.greenend.org.uk/~sgtatham/putty/
Please download Putty !!!!!
Putty
Putty + X windows
Install xming and xming fonts
Download links
• Putty: –http://www.putty.org/
• Xming: –http://sourceforge.net/projects/xming
' מס 1תרגיל
• ב שימוש תוך מהתחנות לאחת ssh -התחבר• כגון קצרה מחשב תכנית Hello : כתוב
World• קומפילציה :בצע gcc –o hello_world hello_world.c• :הרץ את התכנית ושמור הפלט% ./hello_world > hello.txt
• :בדוק את הפלט על-ידי• more hello.txt
The GNU compilerhttp://gcc.gnu.org/
•gcc filename.c– Will produce an executable “a.out”
•gcc –o runme filename.c– Will produce an executable “runme”
• Optimization: gcc –O3 –o runme filename.c
•gcc –c filename.c will produce an object file “filename.o”
' מס תרגיל 1/3 – 1פתרון
' מס תרגיל 2/3 – 1פתרון
' מס תרגיל 3/3 – 1פתרון
MPI-Quick reference card 1/2
MPI-Quick reference card 2/2
MPI Quick Reference Card:http://web.eecs.utk.edu/~dongarra/WEB-PAGES/SPRING-2006/mpi-quick-ref.pdf
What is message passing?• Data transfer through messaging
Requires a sender and a receiver cooperation
DataProcess 0
Process 1
May I Send?
Yes
DataData
DataData
DataData
DataData
Time
Point to Point: Basic Send/Receive
תהליך מס' 1 x
Send(&x,2);
תהליך מס' 2 y
Recv(&y,1);
הזזת נתונים
Space-Time Diagram of a Message-Passing Program
MPI - Message Passing Interface API
• 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• Execution: mpirun –np N filename• Help: man mpirun
MPI Naming Conventions
MPI_Xxxxx(parameter,...)
Example: MPI_Init(&argc,&argv)
The First 4 Functions of MPI
• MPI_Init• MPI_Finalize• MPI_Comm_size• MPI_Comm_rank
• …and don’t forget the #include “mpi.h”
The First 4 Functions Syntax
• int MPI_Init(int argc, char *argv[] )
• int MPI_Finilize()
• int MPI_Comm_size(MPI_Comm comm, int *size)
• int MPI_Comm_rank(MPI_Comm comm, int *rank)
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.
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);
MPI_Sendint MPI_Send(void *buf, int count, MPI_Datatype dtype,int dest, int tag, MPI_Comm comm);
MPI Data typesMPI data type 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)
' מס 2תרגיל
ב • קצרה תכנית :MPI- הרצתHello_World מקבילי
ויודיע • שלום יאמר מחשב כל בה תכנית כתוב: , לדוגמה בריצה שלו התהליך מספר אתHello world from process 1 of 2
' מס תרגיל 1/3 – 2פתרון // see more examples: /usr/local/mpich/examples
#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;}
' מס תרגיל 2/3 – 2פתרון
helloworld: helloworld.c
mpicc -o helloworld helloworld.c
clean:
/bin/rm -f helloworld *.o
% make
The Makefile
' מס תרגיל 3/3, 2פתרון
• Note on syntax:int main( argc, argv )int argc; char **argv;
Is Equivalent to:Int main(int argc, char *argv[])
Then:MPI_Init(&argc,&argv);
' מס - 2תרגיל ב: ++C מימוש
Create a “machinefile”
המחשבים של המעודכנים השמותParallel1Parallel2parallel3
Hello World - Execution% mpicc -o helloworld helloworld.c
% mpirun -np 4 helloworld
Or
mpirun –machinefile ./machinefile –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
%
machinefile
If no machinefile is specified you are running on the local machine
If a machinefile does exist you are running on the machines specified in the file
' מס חישוב: 3תרגיל • אינטגרציה באמצעות חישוב
• הפונקציה על אינטגרציה נבצעf(x)=4/(1+x2) 0בין - - 1ל חלוקת ידי על
ל חלקים n -התחום
41arctan0arctan1arctanarctan
1
1 10
1
02
π=)(=)()(=|(x)=dx
x+
P3P2
Other methods for integrating the area of a circle
P1P0
P1
P0P7
P6
P5
P4 P3
P2
Master/Workers
' מס תרגיל 3פתרון
זמן • למדידת בפונקציה השתמשנו בפתרון)(MPI_Wtime: הנקראת •
•: תחת התרגיל לפתרון דוגמא ראה/usr/local/mpich/examples/cpi.c
: מהכתובת גם התכנית את להוריד ניתןhttp://www.mcs.anl.gov/research/projects/mpi/
usingmpi/examples/simplempi/cpi_c.htm
Copy this program to a location under your home directory where you have a write permission! Execute it from there.
' מס תרגיל 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];
' מס תרגיל המשך- 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;
' מס תרגיל המשך - 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 {
' מס תרגיל המשך - 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);
' מס תרגיל המשך – 3פתרון 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);
' מס תרגיל המשך - 3פתרוןMPI Reduce
' מס תרגיל המשך - 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 */
תהליכים 4הרצת
שני על תהליכים שני הרצתמעבדים
הריצה ביצועי 1/2הערכת
הריצה ביצועי 2/2הערכת
How to try cpi.c?• mkdir mpi• cd mpi• cp /usr/local/mpich2-1.0/share/examples_graphics/cpi.c .
• mpicc –o cpi cpi.c• create a hostfile
•mpirun –np 4 –machinefile ./machinefile ./cpi
מטלות: •SSHהתחברות ב –יצירת מחיצה + עריכת קובץ ושמירתו–MPICC על-ידי MPI ועם GCC עם MPIקימפול ללא –CPIהרצת התכנית –
עם Allinea DDTתרגול
קובץ • נמצא במכללה הקורס עם tarבאתר , . לפתוח הקובץ את להוריד נא לימודי חומר
- ב העוסקים התרגילים את ולבצע , MPIאותוהבא השקף ראו
תחת המצוי ההדרכה חומר את לפתוח נאhandoutsהמחיצה
Allinea DDT tutorialSession 1- Program crash: cstartmpiSession 2 – f90, skipSession 3 – Deadlock in MPI: cpi, loopSession 4 – Memory leaks: mandel, loopSession 5 – GPU Computing, skipSession 6 – C example: matrixSession 7 – f90, skip
Eclipse PTPhtt
p://
eclip
se.o
rg/d
ownl
oads
/
Eclipse PTP
http://wiki.eclipse.org/PTP/tutorials/SC12
SC12 tutorial:http://download.eclipse.org/tools/ptp/docs/ptp-sc12-color.pdf