parallel processing lab 1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Parallel Processing Lab 1 PowerPoint Presentation
Download Presentation
Parallel Processing Lab 1

Loading in 2 Seconds...

play fullscreen
1 / 114

Parallel Processing Lab 1 - PowerPoint PPT Presentation


  • 148 Views
  • Uploaded on

Parallel Processing Lab 1. Dr. Guy Tel- Zur. August 2013 edition. מטרות השיעור. התחברות לקלאסטר המקבילי תרגול ביצוע משימות בסיסיות תחת מערכת ההפעלה Linux הרצת תכניות מקביליות בסיסיות המשתמשות ב MPI - שימוש ב - Profiler. יעדים. יישור קו בנושא לינוקס הכרות ראשונית עם MPI פיתוח קוד

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Parallel Processing Lab 1' - keely-doyle


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
parallel processing lab 1

Parallel ProcessingLab 1

Dr. Guy Tel-Zur

August 2013 edition

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

בMPI-

  • שימוש ב- Profiler
slide3
יעדים
  • יישור קובנושא לינוקס
  • הכרות ראשונית עם MPI
    • פיתוח קוד
    • קימפול
    • ניפוי שגיאות
    • הרצה
    • ניתוח התוצאה
the hobbits
The Hobbits
  • Old hobbits:
    • Hobbit1 132.72.53.1
    • Hobbit2 132.72.53.2
    • Hobbit3 132.72.53.3
    • Hobbit4 132.72.53.4
    • Hobbit5 132.72.53.5
  • New hobbits:
    • Hobbit6 132.72.50.36
    • Hobbit7 132.72.50.35
    • Hobbit8 132.72.55.240
    • Hobbit9 132.72.55.241
    • Hobbit10 132.72.52.160
  • Virtual hobbits:
    • Hobbit11 132.72.50.68
    • Hobbit12 132.72.50.71
    • Hobbit13 132.72.50.91
    • Hobbit14 132.72.50.93
    • Hobbit15 132.72.50.94
basic linux commands 1 5

Enter the system

login: username

password: passwd

Exit the system

exit

Text editors

pico, vi, (x)Emacs, gedit… or

Edit on Windows then transfer file using ftp

C Compiler

gcc –o file file.c

Basic Linux Commands – 1/5
basic linux commands 2 5

DOS

Linux

See files

dir

ls

ls -l

Copy files

copy

cp

Erase files

del

rm

Basic Linux Commands – 2/5
basic linux commands 3 5

DOS

Linux

Make directory

mkdir

mkdir

Remove directory

rmdir

rmdir

More/Rename

rename

mv

OS version

ver

uname -a

Basic Linux Commands – 3/5
basic linux commands 4 5
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
Basic Linux Commands – 5/5
  • Redirection: >, >>
  • Pipe: |
  • telnet
  • ftp
  • ping
  • chmod
  • chown
the vi editor

ESC

Puts you in command mode

h, j, k, l

Left, down, up, right or use the arrows keys

w, W, b, B

Forward, backward by word

0, $

First, last position of current line

/pattern

Search forward for pattern

?pattern

Search backward for pattern

n,N

Repeat last search in same, opposite direction

x

Delete character

dd

Delete current line

D

Delete to end of line

dw

Delete word

p, P

Put deleted text before, after cursor

u

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

The vi Editor
vi reference card
vi reference card
  • Download and print:
  • http://my.pages.de/vi-refcard.html
  • http://vh224401.truman.edu/~dbindner/mirror/vi-ref.pdf
other text editors
Other text editors
  • Vi, Vim
  • Pico
  • Emacs/Xemacs
  • Nedit (very friendly)
  • Eclipse IDE‏
linux gathering i nformation
Linux: Gathering Information

Kernel version: uname –a

CPU information:more /proc/cpuinfo

Memory Information:more /proc/meminfo

connecting from windows to a remote node
Connecting from Windows to a remote node
  • Secured: SSH

SSH client from: http://www.ssh.com/support/downloads/

PuTTY: http://www.chiark.greenend.org.uk/~sgtatham/putty/

Please download Putty!!!!!

putty xming option 1
Putty + Xming (option 1)

Install xmingand xming fonts

connecting with cygwin x option 2
Connecting with cygwin X (option 2)
  • Connect with PuTTY
  • Programs  cygwin  xwin server
  • xhost +
  • From PuTTY’swindow: open X application
download links
Download links
  • Putty:
    • http://www.putty.org/
  • Xming:
    • http://sourceforge.net/projects/xming
password less ssh
Password-less SSH:

http://telzur.blogspot.co.il/2006/03/password-less-ssh-connection.html

slide31
תרגיל מס' 1
  • התחבר לאחת מהתחנות תוך שימוש ב- ssh
  • כתוב תכנית מחשב קצרה שמדפיסה: Hello World
  • בצע קומפילציה:

gcc –o hello_worldhello_world.c

  • הרץ את התכנית ושמור הפלט:

% ./hello_world > hello.txt

  • בדוק את הפלט על-ידי:
  • more hello.txt
the gnu compiler http gcc gnu org
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”
slide39

MPI Quick Reference Card:

http://web.eecs.utk.edu/~dongarra/WEB-PAGES/SPRING-2006/mpi-quick-ref.pdf

what is message passing

Data

Process 0

Data

May I Send?

Data

Data

Data

Data

Data

Data

Data

Process 1

Yes

Time

What is message passing?
  • Data transfer through messaging
  • Requires a sender and a receiver cooperation
point to point basic send receive

תהליך מס' 1

תהליך מס' 2

x

y

הזזת נתונים

Send(&x,2);

Recv(&y,1);

Point to Point: Basic Send/Receive
mpi m essage p assing i nterface api
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 Naming Conventions

MPI_Xxxxx(parameter,...)‏

Example: MPI_Init(&argc,&argv)‏

the first 4 functions of mpi
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
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
MPI Communicator

A communicator is a handle representing a group of processors that can communicate with one another.

The communicator nameis 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
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 send
MPI_Send

int MPI_Send(void *buf, int count, MPI_Datatype dtype,

int dest, int tag, MPI_Comm comm);

mpi data types
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)‏

slide51
תרגיל מס' 2
  • הרצת תכנית קצרה ב-MPI:

Hello_World מקבילי

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

Hello world from process 1 of 2

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

// 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 2 3
פתרון תרגיל מס' 2 – 2/3

The Makefile

% make

helloworld: helloworld.c

mpicc -o helloworld helloworld.c

clean:

/bin/rm -f helloworld *.o

2 3 3
פתרון תרגיל מס' 2, 3/3
  • 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);

slide56

Create a “machinefile”

השמות המעודכנים של המחשבים

Hobbit1 .. hobbit10

hello world execution
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
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

slide60
תרגיל מס' 3: חישוב 
  • חישוב באמצעות אינטגרציה
  • נבצע אינטגרציה על הפונקציה f(x)=4/(1+x2) בין 0 ל- 1 על-ידי חלוקת התחום ל- n חלקים
slide63
פתרון תרגיל מס' 3
  • בפתרון השתמשנו בפונקציה למדידת זמן
  • הנקראת : MPI_Wtime()‏

ניתן להוריד את התכנית מהכתובת הבאה בעזרת wget:

Wgethttp://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.

slide64
פתרון תרגיל מס' 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];

slide65
פתרון תרגיל מס' 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;

slide66
פתרון תרגיל מס' 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

{

slide67
פתרון תרגיל מס' 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
פתרון תרגיל מס' 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);
slide70
פתרון תרגיל מס' 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 */

how to run cpi c
How to run cpi.c?
  • mkdirmpi
  • cd mpi
  • cp /usr/local/mpich2-1.0/share/examples_graphics/cpi.c .
  • mpicc –o cpicpi.c
  • create a hostfile
  • mpirun –np 4 –machinefile ./machinefile ./cpi
  • מטלות:
    • התחברות ב SSH
    • יצירת מחיצה + עריכת קובץ ושמירתו
    • קימפול עם MPI על-ידי MPICC
    • הרצת התכנית CPI
job execution via a batch queuing system bqs torque
Job execution via a Batch Queuing System (BQS) - Torque

#!/bin/bash

#PBS -N cpi

####PBS -q default

#PBS -l nodes=4:ppn=1

echo Start printing:

echo The working directory is `echo $PBS_O_WORKDIR`

cd $PBS_O_WORKDIR

/usr/local/bin/mpirun -np 4 -machinefile ./machinefile ./cpi

exercise 4 pmandel
Exercise #4: pmandel
  • Mandelbot Fractal
  • Usage on Linux, see: /path/to/mpich/examples/README
slide79

[telzur@TPad examples]$ mpirun -np 4 ./pmandel -i

Welcome to the Mandelbrot/Julia set explorer.

input xminyminxmaxymaxmax_iter, (0 0 0 0 0 to quit):

-1 -1 0 0 512

read <-1 -1 0 0 512

> from stdin

x0,y0 = (-1.000000, -1.000000) x1,y1 = (0.000000,0.000000) max_iter = 512

0 0 0 0 0

input xminyminxmaxymaxmax_iter, (0 0 0 0 0 to quit):

read <0 0 0 0 0

> from stdin

x0,y0 = (0.000000, 0.000000) x1,y1 = (0.000000,0.000000) max_iter = 0

Done calculating mandelbrot, now creating file

pmandel.ppm

width: 760

height: 760

colors: 100

str: Mandelbrot over (0.000000-0.000000,0.000000-0.000000), size 760 x 760

exercise 5
Exercise #5
  • Write a C and MPI parallel code to compute:
  • Use the Trapezoidal rule.
  • Is your answer sensitive to the number of MPI tasks?
  • Plot speedup and efficiency vs. # tasks
  • Use Torque!
exercise 6 message passing in a ring
Exercise #6: Message Passing in a ring

1. Download and execute the code from:

http://www.nics.tennessee.edu/files/pdf/MPI_WORKSHOP/ringnb.c.soln

slide84

#include <stdio.h>

#include <mpi.h>

void main(intargc, char *argv[])

{

intmyrank, nprocs, leftid, rightid;

intval, sum, tmp;

MPI_Statusrecv_status, send_status;

MPI_Requestsend_request;

/*----------------*/

/* Initialize MPI */

/*----------------*/

MPI_Init(&argc, &argv);

/*--------------------------------------------------------------------*/

/* Find out my rank and size using global communicator MPI_COMM_WORLD */

/*--------------------------------------------------------------------*/

MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

/*--------------------*/

/* Find out neighbors */

/*--------------------*/

if ((leftid=(myrank-1)) < 0) leftid = nprocs-1;

if ((rightid=(myrank+1)) == nprocs) rightid = 0;

slide85

/*---------------------------------------------------------------------*//*---------------------------------------------------------------------*/

/* Send the process rank stored as val to the process on my right and */

/* receive a process rank from the process on my left and store as tmp */

/*---------------------------------------------------------------------*/

val = myrank;

sum = 0;

do {

MPI_Issend(&val,1,MPI_INT,rightid,99,MPI_COMM_WORLD,&send_request);

MPI_Recv(&tmp,1,MPI_INT,leftid,99,MPI_COMM_WORLD,&recv_status);

MPI_Wait(&send_request,&send_status);

val = tmp;

sum += val;

} while (val != myrank);

/*--------------------------*/

/* Print the output message */

/*--------------------------*/

printf("Proc %d sum = %d \n", myrank, sum);

/*-----------------------*/

/* Exit and finalize MPI */

/*-----------------------*/

MPI_Finalize();

}

mpich jumpshot
MPICH Jumpshot

Download the cpi (+log) source using wget:

wgethttp://ftp.mcs.anl.gov/pub/mpi/usingmpi-1st/examples/simplempi/cpilog.c

mpicc –o executable –lpme –llmpe ./source.c

Liblmpe – exists only on the old hobbits

MPE currently is not working on our cluster

You can skip this slide!

slide88

http://tools.pub.lab.nm.ifi.lmu.de/web/ipm/home

http://ipm-hpc.sourceforge.net/userguide.html

You can skip IPM.

We will use Scalasca instead

building ipm
Building IPM

[telzur@TPad ipm-2.0.0]$ ./configure --with-papi=/home/telzur/papi500 --enable-parser --enable-posixio=yes

IPM configuration:

MPI profiling enabled : yes

POSIX-I/O profiling enabled : yes

PAPI enabled : yes

CFLAGS : -g -O2 -DHAVE_DYNLOAD -I/home/telzur/papi500/include -DOS_LINUX

LDFLAGS : -L/home/telzur/papi500/lib

LIBS : -lmxml -lpthread -lpapi

MPI_STATUS_COUNT : count

Fortran underscore : -funderscore_post

Building IPM Parser : yes

[telzur@TPad ipm-2.0.0]$ export LIBS=-lpthread

[telzur@TPad ipm-2.0.0]$ make

You can skip IPM.

We will use Scalasca instead

PAPI=Performance Application Programming Interface, http://icl.cs.utk.edu/papi/

slide90
mpicc -o cpi_hpc -L/usr/local/lib -lipm -ldlcpi_hpc.c
  • mpirun -np 4 ./cpi_hpc
  • ipm_parse -html <name of xml file>
  • Watch index.html in browser

You can skip IPM.

We will use Scalasca instead

slide91
IPM

export LD_LIBRARY_PATH=/usr/local/lib

mpicc -g -o cpi_hpc -L/usr/local/lib -lipm ./cpi_hpc.c

[telzur@TPad lab1]$ mpirun -np 4 ./cpi_hpc

Process 1 of 4 is on TPad

Process 3 of 4 is on TPad

Process 0 of 4 is on TPad

Process 2 of 4 is on TPad

pi is approximately 3.1415926544231239, Error is 0.0000000008333307

wall clock time = 14.185038

ipm_parse -html telzur.1365977652.ipm.xml

Open your browser and look for index.html in that directory

slide92
[telzur@TPadtest.hello]$ mpirun -np 4 ./hello.ipm
  • Hello from rank 0 of 4
  • Hello from rank 2 of 4
  • Hello from rank 3 of 4
  • Hello from rank 1 of 4
  • ##IPM2v0.xx########################################################
  • # command : ./hello.ipm
  • # start : Mon Apr 15 08:11:05 2013 host : TPad
  • # stop : Mon Apr 15 08:11:05 2013 wallclock : 0.12
  • # mpi_tasks : 4 on 1 nodes %comm : 0.00
  • # mem [GB] : 0.14 gflop/sec : 0.00
  • #
  • # : [total] <avg> min max
  • # wallclock : 0.40 0.10 0.09 0.12
  • # MPI : 0.00 0.00 0.00 0.00
  • # %wall :
  • # MPI : 0.00 0.00 0.01
  • # #calls :
  • # MPI : 16 4 4 4
  • # mem [GB] : 0.14 0.03 0.03 0.03
  • ###################################################################
  • # region :'ipm_noregion'
  • # : [total] <avg> min max
  • # wallclock : 0.40 0.10 0.09 0.12
  • # MPI : 0.00 0.00 0.00 0.00
  • # %wall :
  • # MPI : 0.00 0.00 0.01
  • # #calls :
  • # MPI : 16 4 4 4
  • # mem [GB] : 0.14 0.03 0.03 0.03 ################
  • [telzur@TPadtest.hello]$

You can skip IPM.

We will use Scalasca instead

advanced examples
Advanced Examples
  • Athena
  • https://trac.princeton.edu/Athena/
  • Make clean
  • configure --with-problem=rt --with-gas=hydro –enable-mpi
  • Make all
  • [telzur@TPad bin]$ ./athena -i ../tst/2D-hydro/athinput.rt
visualization
Visualization

ImageMagic (or VisIt)

cd /home/telzur/Downloads/athena4.1/bin/id0

animate *.ppm

scalasca
Scalasca
  • Is installed on the hobbits
  • VI-HPS http://www.vi-hps.org/
  • LiveDVD: http://www.vi-hps.org/training/livedvd/
  • VI-HPS demos
  • Quick Reference Guide: http://apps.fz-juelich.de/scalasca/releases/scalasca/1.4/docs/QuickReference.pdf
slide112
Repeat all the previous exercises, this time with Scalasca’s Instrumentation and Examine the jobs profiling
eclipse ptp
Eclipse PTP

NOT READY YET FOR THIS COURSE

http://eclipse.org/downloads/

eclipse ptp1
Eclipse PTP

http://wiki.eclipse.org/PTP/tutorials/SC12

SC12 tutorial:

http://download.eclipse.org/tools/ptp/docs/ptp-sc12-color.pdf

NOT READY YET FOR THIS COURSE