70
Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU Kickstart Tutorial/Seminar on using the 64-nodes P4-Xe on Cluster in Science Facul ty June 11, 2003

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU Kickstart Tutorial/Seminar on using the 64-nodes P4-Xeon Cluster in Science Faculty June 11, 2003

Embed Size (px)

Citation preview

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Kickstart Tutorial/Seminar on using the 64-nodes P4-Xeon Cluster i

n Science Faculty

June 11, 2003

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Aims and target audience

• Aims:– Provide a kickstart tutorial to potential cluster users in

Science Faculty, HKBU

– Promote the usage of the PC cluster in Science Faculty

• Target audience– Science Faculty students referred by their project/thesis

supervisors

– Staff who are interested in High Performance Computing

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Outline

• Brief introduction– Hardware, software, login and policy

• How to write and run program on multiple CPUs– Simple MPI programming– Resources on MPI documentation

• Demonstration of software installed– SPRNG, BLAS, NAMD2, GAMESS, PGI

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Bought by Teaching Development Grant

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hardware Configuration

• 1 master node + 64 compute nodes + Gigabit Interconnection

• Master node– Dell PE2650, P4-Xeon 2.8GHz x 2– 4GB RAM, 36GB x 2 U160 SCSI (mirror)– Gigabit ethernet ports x 2

• SCSI attached storage– Dell PV220S– 73GB x 10 (RAID5)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hardware Configuration (cont)

• Compute nodes– Dell PE2650, P4-Xeon 2.8GHz x 2– 2GB RAM, 36GB U160 SCSI HD– Gigabit ethernet ports x 2

• Gigabit Interconnect– Extreme Blackdiamond 6816 Gigabit ethernet– 256Gb backplane– 72 Gigabit ports (8 ports card x 9)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Software installed• Cluster operating system

– ROCKS 2.3.2 from www.rocksclusters.org• MPI and PVM libraries

– LAM/MPI 6.5.9, MPICH 1.2.5, PVM 3.4.3-6beolin• Compilers

– GCC 2.96, GCC 3.2.3– PGI C/C++/f77/f90/hpf version 4.0

• MATH libraries– ATLAS 3.4.1, ScaLAPACK, SPRNG 2.0a

• Application software– MATLAB 6.1 with MPITB– Gromacs 3.1.4, NAMD2.5b1 , Gamess

• Editors– vi, pico, emacs, joe

• Queuing system– OpenPBS 2.3.16, Maui scheduler

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Cluster O.S. – ROCKS 2.3.2

• Developed by NPACI and SDSC• Based on RedHat 7.3• Allow setup of 64 nodes in 1 hour• Useful command for users to monitor jobs in all n

odes. E.g.– cluster-fork date– cluster-ps morris– cluster-kill morris

• Web based management and monitoring– http://tdgrocks.sci.hkbu.edu.hk

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Ganglia

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

PBS Job queue

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hostnames

• Master node– External : tdgrocks.sci.hkbu.edu.hk– Internal : frontend-0

• Compute nodes– comp-pvfs-0-1, …, comp-pvfs-0-48– Short names: cp0-1, cp0-2, …, cp0-48

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Network diagram

Master node

Compute node Compute node Compute node

Gigibit ethernet switch

tdgrocks.sci.hkbu.edu.hk

frontend-0 (192.168.8.1)

comp-pvfs-0-1(192.168.8.254)

comp-pvfs-0-2(192.168.8.253)

comp-pvfs-0-48(192.168.8.207)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Login to the master node

• Login is allowed remotely in all HKBU networked PCs by ssh or vncviewer

• SSH Login (terminal login)

– Using your favourite ssh client software, namely putty, SSHsecureshell on windows and openssh on Linux/UNIX

– E.g. on all SCI workstations (sc11 – sc30), typessh tdgrocks.sci.hkbu.edu.hk

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Login to the master node

• VNC Login (graphical login)

– Using vncviewer download from http://www.uk.research.att.com/vnc/

– E.g. in sc11 – sc30.sci.hkbu.edu.hk,vncviewer vnc.sci.hkbu.edu.hk:51

– E.g. in windows, run vncviewer and upon asking the server address, type

vnc.sci.hkbu.edu.hk:51

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Username and password

• The unified password authentication has been implemented

• Same as that of your netware account

• Password authentication using NDS-AS

• Setup similar to net1 and net4 in ITSC

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

ssh key generation

• To make use of multiple nodes in the PC cluster, users are restricted to use ssh.

• Key generation is done once automatically during first login

• You may input a passphrase to protect the key pair

• The key pair is stored in your $HOME/.ssh/

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

User Policy

• Users are allowed to remote login from other networked PCs in HKBU.

• All users must use their own user account to login.• The master node (frontend) is used only for login,

simple editing of program source code, preparing the job dispatching script and dispatching of jobs to compute node. No foreground or background can be run on it.

• Dispatching of jobs must be done via the OpenPBS system.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

OpenPBS system

• Provide a fair and efficient job dispatching and queuing system to the cluster

• PBS script shall be written for running job

• Either sequential or parallel jobs can be handled by PBS

• Jobs error and output are stored in different filenames according to job IDs.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

PBS script example (sequential)

• PBS scripts are shell script with directives preceding with #PBS

• The above example request only 1 node and deliver the job named ‘prime’ in default queue.

• The PBS system will mail a message after the job executed.

#!/bin/bash#PBS -l nodes=1#PBS -N prime#PBS -m ae#PBS -q default# the above is the PBS directive used in batch queue# Assume that you placed the executable in /u1/local/share/pbsexamplesecho Running on host `hostname`/u1/local/share/pbsexamples/prime 216091

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Delivering PBS job

• Prepare and compile executablecp /u1/local/share/pbsexamples/prime.c .

cc –o prime prime.c -lm

• Prepare and edit PBS script as previouscp /u1/local/share/pbsexamples/prime.bat .

• Submit the jobqsub prime.bat

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

PBS script example (parallel)#!/bin/sh#PBS -N cpi#PBS -r n#PBS -e cpi.err#PBS -o cpi.log#PBS -m ae#PBS -l nodes=5:ppn=2#PBS -l walltime=01:00:00# This job's working directoryecho Working directory is $PBS_O_WORKDIRcd $PBS_O_WORKDIRecho Running on host `hostname`echo This jobs runs on the following processors:echo `cat $PBS_NODEFILE`# Define number of processorsNPROCS=`wc -l < $PBS_NODEFILE`echo This job has allocated $NPROCS nodes# Run the parallel MPI executable “cpi” /u1/local/mpich-1.2.5/bin/mpirun -v -machinefile $PBS_NODEFILE -np $NPROCS /u1/local/share/pbsexamples/cpi

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Delivering parallel jobs

• Copy the PBS script examplescp /u1/local/share/pbsexamples/runcpi .

• Submit the PBS job

qsub runcpi

• Note the error and output files named

cpi.e??? and cpi.o???

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

End of Part 1

Thank you!

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Demonstration of software installed

• SPRNG

• BLAS, ScaLAPACK

• MPITB for MATLAB

• NAMD2 and VMD

• GAMESS, GROMACS

• PGI Compilers for parallel programming

• More…

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

SPRNG 2.0a• Scalable Parallel Pseudo Random Number Generators Library• A set of libraries for scalable and portable pseudorandom number generation.• Most suitable for parallel Monte-Carlo simulation• The current version is installed in /u1/local/sprng2.0a• For serial source code (e.g. mcErf.c), compile with

gcc -c -I /u1/local/sprng2.0/include mcErf.cgcc -o mcErf -L /u1/local/sprng2.0/lib mcErf.o -lsprng –lm

• For parallel source code (e.g. mcErf-mpi.c, compile withmpicc -c -I /u1/local/sprng2.0/include mcErf-mpi.cmpicc -o mcErf-mpi -L /u1/local/sprng2.0/lib mcErf-mpi.o \ -lsprng –lpmpich –lmpich –lm

• Or use Makefile to automate the above process• Samples file mcPi.tar.gz, mcErf.tar.gz can be found in /u1/local/share/example

/sprng/ in the cluster• Thanks for Mr. K.I. Liu for providing documentations and samples for SPRNG i

n http://www.math.hkbu.edu.hk/~kiliu.• More information can be found in http://sprng.cs.fsu.edu/.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

BLAS

• Basic Linear Algebra Subprograms• basic vector and matrix operations• Sample code showing the speed of BLAS matrix-ma

trix multiplication against self written for loop in /u1/local/share/example/blas– dgemm.c, makefile.dgemm.c, – dgemm-mpi.c, makefile.dgemm-mpiThanks Mr. C.W. Yeung, MATH for providing the above ex

ample

• Further information can be found in http://www.netlib.org/blas/

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

ScaLAPACK• Scalable LAPACK• PBLAS + BLACS• PBLAS : Parallel Basic Linear Algebra Subprograms• BLACS : Basic Linear Algebra Communication Subprograms• Support MPI and PVM• Only MPI version can be found in our cluster• Directories for BLAS, BLACS and ScaLAPACK libraries:

– /u1/local/ATLAS/lib/Linux_P4SSE2_2/– /u1/local/BLACS/LIBS– /u1/local/SCALAPACK/libscalapack.a

• PBLAS and ScaLAPACK examples (pblas.tgz, scaex.tgz) are stored in /u1/local/share/example/scalapack

• Further information for ScaLAPACK can be found in http://www.netlib.org/scalapack/scalapack_home.html

• Please ask Morris for further information.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPITB for MATLAB

• MPITB example– MC.tar.gz in /u1/local/share/example/mpitb

• Untar the example in your hometar xzvf /u1/local/share/example/mpitb/MC.tar.gz

• Lamboot first then start matlab and runqsub runMCpbs.bat

• Further information can be found in – http://www.sci.hkbu.edu.hk/~smlam/tdgc/MPITB– Thanks Tammy Lam, MATH for providing the above h

omepage and examples

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

NAMD2

• parallel, object oriented molecular dynamics code• high-performance simulation of large biomolecular

systems• binary downloaded and installed in /u1/local/namd2

/• work with VMD frontend (GUI)• Demonstration of VMD and NAMD using alanin.z

ip in /u1/local/example/namd2• Further information can be found in http://www.ks.

uiuc.edu/Research/namd• Ask Morris Law for further information

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

GAMESS

• The General Atomic and Molecular Electronic Structure System

• A general ab initio quantum chemistry package

• Thanks for Justin Lau, CHEM for providing sample scripts and explanation of the Chemistry behind.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

PGI compilers support 3 types of parallel programming

1. Automatic shared-memory parallel– Use in SMP within the same node (max NCPUS=2)– Using the option -Mconcur in pgcc, pgCC, pgf77, pgf90

pgcc –o pgprime –Mconcur prime.cexport NCPUS=2./pgprime

2. User-directed shared-memory parallel– Use in SMP within the same node (max NCPUS=2)– Using the option -mp in pgcc, pgCC, pgf77, pgf90

pgf90 –o f90prime –Mconcur prime.f90export NCPUS=2./f90prime

– User should understand OpenMP parallelization directives for Fortran and pragmas for C and C++

– Consult PGI Workstations user guide for details• http://www.pgroup.com/ppro_docs/pgiws_ug/pgiug_.htm

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

PGI compilers support 3 types of parallel programming

3. Data parallel shared- or distribute-memory parallel – Only HPF support– suitable in SMP and cluster environment

pghpf –o hello hello.hpf./hello –pghpf –np 8 –stat alls

– PGHPF environmental variables• PGHPF_RSH=ssh• PGHPF_HOST=cp0-1,cp0-2,• PGHPF_STAT=alls (can be cpu, mem, all, etc)• PGHPF_NP (max no.=16, license limit)

– Example files in /u1/local/share/example/hpf• hello.tar.gz, pde1.tar.gz

– Consult PGHPF user guide in http://www.pgroup.com/ppro_docs/pghpf_ug/hpfug.htm

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Other software in considerations

• PGAPACK– Parallel Genetic Algorithm Package– /u1/local/pga

• PETSc– the Portable, Extensible Toolkit for Scientific c

omputation

• Any suggestions

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

End of Part 2

Thank you!

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

What is Message Passing Interface (MPI)?

• Portable standard for communication

• Processes can communicate through messages.

• Each process is a separable program

• All data is private

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

What is Message Passing Interface (MPI)?

• This is a library, not a language!!

• Different compilers, but all must use the same libraries, i.e. MPICH, LAM, etc.

• There are two versions now, MPI-1 and MPI-2

• Use standard sequential language. Fortran, C, etc.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Basic Idea of Message Passing Interface (MPI)

• MPI Environment - Initialize, manage, and terminate communication among processes

• Communication between processes– global communication, i.e. broadcast, gather, etc.

– point to point communication, i.e. send, receive, etc.

• Complicated data structures– i.e. matrices and memory

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Is MPI Large or Small?

• MPI is large– More than one hundred functions

– But not necessarily a measure of complexity

• MPI is small– Many parallel programs can be written with just 6 basic

functions

• MPI is just right– One can access flexibility when it is required

– One need not master all MPI functions

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

When Use MPI?

• You need a portable parallel program

• You are writing a parallel library

• You care about performance

• You have a problem that can be solved in parallel ways

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

F77/F90, C/C++ MPI library calls

• Fortran 77/90 uses subroutines– CALL is used to invoke the library call– Nothing is returned, the error code variable is the last

argument– All variables are passed by reference

• C/C++ uses functions– Just the name is used to invoke the library call– The function returns an integer value (an error code)– Variables are passed by value, unless otherwise

specified

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Getting started with LAM

• Create a file called “lamhosts”• The content of “lamhosts” (8 notes):

cp0-1

cp0-2

cp0-3

cp0-8

frontend-0

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Getting started with LAM

• starts LAM on the specified clusterLAMRSH=sshexport LAMRSHlamboot -v lamhosts• removes all traces of the LAM session on the networklamhalt• In the case of a catastrophic failure (e.g., one or more LAM n

odes crash), the lamhalt utility will hangLAMRSH=sshexport LAMRSHwipe -v lamhosts

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Getting started with MPICH

• Open the “.bashrc” under your home directory

• Add a path at the end of the file:

PATH=/u1/local/mpich-1.2.5/bin:/u1/local/pgi/linux86/bin:$PATH

• Save and exit

• Restart the terminal

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI Commands

• mpicc - compiles an mpi program

mpicc -o foo foo.c

mpif77 -o foo foo.f

mpif90 -o foo foo.f90

• mpirun - start the execution of mpi programs

mpirun -v -np 2 foo

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI Environment

• Initialize - initialize environment• Finalize - terminate environment• Communicator- create default comm. group for all

processes• Version - establish version of MPI• Total processes - spawn total processes• Rank/Process ID - assign identifier to each process• Timing Functions - MPI_Wtime, MPI_Wtick

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_INIT

• Initializes the MPI environment• Assigns all spawned processes to MPI_COMM_WORLD, defa

ult comm.• C

– int MPI_Init(argc,argv)• int *argc;• char ***argv;

– INPUT PARAMETERS• argc - Pointer to the number of arguments• argv - Pointer to the argument vector

• Fortran– CALL MPI_INIT(error_code)– int error_code – variable that gets set to an error code

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_FINALIZE

• Terminates the MPI environment

• C– int MPI_Finalize()

• Fortran– CALL MPI_FINALIZE(error_code)– int error_code – variable that gets set to an error

code

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 1 (C)

#include <stdio.h>#include <mpi.h>int main(int argc, char *argv[]){

MPI_Init(&argc, &argv);printf(”Hello world!\n”);MPI_Finalize();return(0);

}

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 1 (Fortran)

program main

include 'mpif.h'

integer ierr

call MPI_INIT(ierr)

print *, 'Hello world!'

call MPI_FINALIZE(ierr)

end

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_COMM_SIZE• This finds the number of processes in a communication group• C

– int MPI_Comm_size ( comm, size )• MPI_Comm comm – MPI communication group;• int *size;

– INPUT PARAMETER• comm - communicator (handle)

– OUTPUT PARAMETER• size - number of processes in the group of comm (integer)

• Fortran– CALL MPI_COMM_SIZE(comm, size, error_code)– int error_code – variable that gets set to an error code

• Using MPI_COMM_WORLD will return the total number of processes started

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_COMM_RANK• This gives the rank/identification number of a process in a communica

tion group• C

– int MPI_Comm_rank ( comm, rank )• MPI_Comm comm;• int *rank;

– INPUT PARAMETERS• comm - communicator (handle)

– OUTPUT PARAMETER• rank – rank/id number of the process who made the call (integer)

• Fortran– CALL MPI_COMM_RANK(comm, rank, error_code)– int error_code – variable that gets set to an error code

• Using MPI_COMM_WORLD will return the rank of the process in relation to all processes that were started

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 2 (C)

#include <stdio.h>#include <mpi.h>int main(int argc, char *argv[]){

int rank, size;MPI_Init(&argc, &argv);MPI_Comm_rank(MPI_COMM_WORLD, &rank);MPI_Comm_size(MPI_COMM_WORLD, &size);printf(”Hello world! I am %d of %d\n”, rank, size);MPI_Finalize();return(0);

}

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 2 (Fortran)

program maininclude 'mpif.h'integer rank, size, ierrcall MPI_INIT(ierr)call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ier

r)call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)print *, 'Hello world! I am ', rank, ' of ', sizecall MPI_FINALIZE(ierr)end

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_Send• standard send• C

– int MPI_Send( buf, count, datatype, dest, tag, comm )• void *buf;• int count, dest, tag;• MPI_Datatype datatype;• MPI_Comm comm;

– INPUT PARAMETERS• buf initial address of send buffer (choice)• count number of elements in send buffer (non negative integer)• datatype datatype of each send buffer element (handle)• dest rank of destination (integer)• tag message tag (integer)• comm communicator (handle)

– NOTES• This routine may block until the message is received.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_Send

• Fortran– MPI_SEND(BUF, COUNT, DATATYPE,

DEST, TAG, COM, IERR)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_Recv• basic receive• C

– int MPI_Recv( buf, count, datatype, source, tag, comm, status )• void *buf;• int count, source, tag;• MPI_Datatype datatype;• MPI_Comm comm;• MPI_Status *status;

– OUTPUT PARAMETERS• buf initial address of receive buffer (choice)• status status object (Status)

– INPUT PARAMETERS• count maximum number of elements in receive buffer (integer)• datatype datatype of each receive buffer element (handle)• source rank of source (integer)• tag message tag (integer)• comm communicator (handle)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI_Recv

• Fortran– MPI_RECV(BUF, COUNT, DATATYPE,

SOURCE, TAG, COMM, STATUS, IERR)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Timing Functions

• MPI_Wtime() - returns a floating point number of seconds, representing elapsed wall-clock time.

• MPI_Wtick() - returns a double precision number of seconds between successive clock ticks.

** The times returned are local to the node/processor that made the call.

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (C)/* * The root node sends out a message to the next node in the ring and each node then passes the * message along to the next node. The root node times how long it takes for the message to get back to it. */#include<stdio.h> /* for input/output */#include<mpi.h> /* for mpi routines */

#define BUFSIZE 64 /* The size of the messege being passed */

main( int argc, char** argv){

double start,finish;int my_rank; /* the rank of this process */int n_processes; /* the total number of processes */char buf[BUFSIZE]; /* a buffer for the messege */int tag=0; /* not important here */float totalTime=0; /* for timing information */MPI_Status status; /* not important here */

MPI_Init(&argc, &argv); /* Initializing mpi */MPI_Comm_size(MPI_COMM_WORLD, &n_processes); /* Getting # of processes */MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Getting my rank */

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (C)/* * If this process is the root process send a messege to the next node* and wait to recieve one from the last node. Time how long it takes* for the messege to get around the ring. If this process is not the * root node, wait to recieve a messege from the previous node and* then send it to the next node.*/start=MPI_Wtime();printf("Hello world! I am %d of %d\n", my_rank, n_processes);if( my_rank == 0 ){

/* send to the next node */MPI_Send(buf, BUFSIZE, MPI_CHAR, my_rank+1, tag,MPI_COMM_WORLD);

/* recieve from the last node */MPI_Recv(buf, BUFSIZE, MPI_CHAR, n_processes-1, tag,MPI_COMM_WORLD, &status);

}

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (C)if( my_rank != 0){

/* recieve from the previous node */MPI_Recv(buf, BUFSIZE, MPI_CHAR, my_rank-1, tag,MPI_COMM_WORLD, &status);

/* send to the next node */MPI_Send(buf, BUFSIZE, MPI_CHAR, (my_rank+1)%n_processes, tag,MPI_COMM_WORLD);

}finish=MPI_Wtime();MPI_Finalize(); /* I'm done with mpi stuff */

/* Print out the results. */if (my_rank == 0)

printf("Total time used was %f seconds\n", finish-start);

return 0;}

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (Fortran)C /* C * The root node sends out a message to the next node in the ring and each node then passes the C * message along to the next node. The root node times how long it takes for the message to get b

ack to it.C */

program maininclude 'mpif.h'

double precision start, finishdouble precision buf(64)integer my_rankinteger n_processesinteger ierrinteger BUFSIZE = 64integer tag = 2001

call MPI_INIT(ierr)call MPI_COMM_RANK(MPI_COMM_WORLD, my_rank, ierr)call MPI_COMM_SIZE(MPI_COMM_WORLD, n_processes, ierr)

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (Fortran)C /* C * If this process is the root process send a messege to the next nodeC * and wait to recieve one from the last node. Time how long it takesC * for the messege to get around the ring. If this process is not the C * root node, wait to recieve a messege from the previous node andC * then send it to the next node.C */

start = MPI_Wtime()

print *, 'Hello world! I am ', my_rank, ' of ', n_processes

if (my_rank .eq. 0) thenC /* send to the next node */

call MPI_SEND(buf, BUFSIZE, MPI_DOUBLE_PRECISION, my_rank+1,1 tag, MPI_COMM_WORLD, ierr)

C /* recieve from the last node */call MPI_RECV(buf, BUFSIZE, MPI_DOUBLE_PRECISION, n_processes-1,

1 tag, MPI_COMM_WORLD, status, ierr)else

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Hello World 3 (Fortran)C /* recieve from the previous node */

call MPI_RECV(buf, BUFSIZE, MPI_DOUBLE_PRECISION, my_rank-1, tag,1 MPI_COMM_WORLD, status, ierr)

C /* send to the next node */call MPI_SEND(buf, BUFSIZE, MPI_DOUBLE_PRECISION, modulo

1 ((my_rank+1), n_processes), tag, MPI_COMM_WORLD, ierr)endiffinish=MPI_Wtime()

C /* Print out the results. */if (my_rank .eq. 0) then

print *, 'Total time used was ', finish-start, ' seconds'endif

call MPI_FINALIZE(ierr)end

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI C Datatypes

MPI Datatype C Datatype

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

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI C Datatypes

MPI Datatype C Datatype

MPI_UNSIGNED unsigned int

MPI_UNSIGNED_LONG unsigned long int

MPI_FLOAT float

MPI_DOUBLE double

MPI_LONG_DOUBLE long double

MPI_BYTE

MPI_PACKED

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

MPI Fortran DatatypesMPI Datatype Fortran DatatypeMPI_INTEGER INTEGER

MPI_REAL REAL

MPI_DOUBLE_PRECISION DOUBLE PRECISION

MPI_COMPLEX COMPLEX

MPI_LOGICAL LOGICAL

MPI_CHARACTER CHARACTER

MPI_BYTE

MPI_PACKED

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

End of Part 3

Thank You!

Using the P4-Xeon cluster HPCCC, Science Faculty, HKBU

Thanks very much!