Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 10 Dr. Guy Tel-Zur.

Similar presentations


Presentation on theme: "Lecture 10 Dr. Guy Tel-Zur."— Presentation transcript:

1 Lecture 10 Dr. Guy Tel-Zur

2 Today’s Agenda Sorting Algorithms MatlabMPI demo
Wilkinson & Allen chapter 10OpenMP demo in Visual Studio MatlabMPI demo Hybrid OpenMP and MPI programming hpi.c, hybridpi.c, lecture11-12.pdf Numerical Algorithms Wilkinson & Allen chapter 11 CilkPlus (demos in Linux and Visual Studio) Home assignment #3

3 Visual Studio 2012 express

4

5

6 MatlabMPI demo cd to ~/matlab Start Matlab without GUI:
matlab -nojvm –nosplash If MatMPI directory exists before executing your code then erase it or from inside Matlab type: MatMPI_Delete_all

7 xbasic.m See more examples : /usr/local/PP/MatlabMPI/examples/
>> MatMPI_Delete_all No MPI_COMM_WORLD, deleting anyway, files may be leftover. >> eval(MPI_Run('xbasic',4,{})) Launching MPI rank: 3 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 2 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 1 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 0 on: hobbit10.ee.bgu.ac.il unix_launch = /bin/sh ./MatMPI/Unix_Commands.hobbit10.ee.bgu.ac.il.0.sh & my_rank: 0 SUCCESS See more examples : /usr/local/PP/MatlabMPI/examples/

8 hello.m >> MatMPI_Delete_all
>> eval(MPI_Run('hello',4,{})) Launching MPI rank: 3 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 2 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 1 on: hobbit10.ee.bgu.ac.il Launching MPI rank: 0 on: hobbit10.ee.bgu.ac.il unix_launch = /bin/sh ./MatMPI/Unix_Commands.hobbit10.ee.bgu.ac.il.0.sh & HelloWorld from rank: 0 SUCCESS

9 Hybrid MPI + OpenMP

10

11 See helper script: hybrid.bash
Hybrid MPI + OpenMP Demo Machine File: Node1 Node2 Node3 node4 Each node has 8 cores MPI mpicc -o mpi_out mpi_test.c -fopenmp See helper script: hybrid.bash OpenMP Lecturer's note: make a demo cd ~/mpi program name: hybridpi.c

12 mpicc -o mpi_exe mpi_test.c -fopenmp
export OMP_NUM_THREADS=8 (bash) mpirun -np 4 –machinefile ./machines mpi_exe Openmpi extensions (N/A at BGU): -npersocket, --npersocket <#persocket>On each node, launch this many processes times the number of processor sockets on the node. The -npersocket option also turns on the -bind-to-socket option.-npernode, --npernode <#pernode>On each node, launch this many processes.-pernode, --pernodeOn each node, launch one process -- equivalent to -npernode 1. -ppn 1

13 Hybrid Pi (MPI+OpenMP)
#include <stdio.h> #include <mpi.h> #include <omp.h> #define NBIN #define MAX_THREADS 8 int main(int argc,char **argv) { int nbin,myid,nproc,nthreads,tid; double step,sum[MAX_THREADS]={0.0},pi=0.0,pig; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&myid); MPI_Comm_size(MPI_COMM_WORLD,&nproc); nbin = NBIN/nproc; step = 1.0/(nbin*nproc);

14 #pragma omp parallel private(tid)
{ int i; double x; nthreads = omp_get_num_threads(); tid = omp_get_thread_num(); for (i=nbin*myid+tid; i<nbin*(myid+1); i+=nthreads) { x = (i+0.5)*step; sum[tid] += 4.0/(1.0+x*x); } printf("rank tid sum = %d %d %e\n",myid,tid,sum[tid]); for(tid=0; tid<nthreads; tid++) pi += sum[tid]*step; MPI_Allreduce(&pi,&pig,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); if (myid==0) printf("PI = %f\n",pig); MPI_Finalize(); return 0; }

15 Hybrid MPI+OpenMP continued
Lecturer's note:For the demo: See hybrid.bash script


Download ppt "Lecture 10 Dr. Guy Tel-Zur."

Similar presentations


Ads by Google