CS3211-Tut10 - CS3211 Parallel and Concurrent Programming...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS3211 Parallel and Concurrent Programming – Guidelines for tutorial (5-9 April 2010) Sample Exercises: [Please conduct these as an interactive discussion, rather than an evaluation. Please also make it clear to the students that they are not being evaluated for their performance in these exercises, so that they are not afraid to make mistakes while answering.] MPI usage instructions See the file tembusu-MPI-access.pdf in Workbin\Assignments 1. MPI Example - This program should demonstrate a simple data decomposition. The master task first initializes an array and then distributes an equal portion of the array to the other tasks. After the other tasks receive their portion of the array, they perform an addition operation to each array element. They also maintain a sum for their portion of the array. The master task does likewise with its portion of the array. As each of the non-master tasks finish, they send their updated portion of the array to the master. Finally, the master task displays the global sum of all array elements. #include "mpi.h" #include <stdio.h> #include <stdlib.h> #define ARRAYSIZE 16000000 #define MASTER 0 float data[ARRAYSIZE]; int main (int argc, char *argv[]) { int numtasks, taskid, rc, dest, offset, i, j, tag1, tag2, source, chunksize; float mysum, sum; float update(int myoffset, int chunk, int myid); MPI_Status status; /***** Initializations *****/ MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); if (numtasks % 4 != 0) { printf("Quitting. Number of MPI tasks must be divisible by 4.\n"); MPI_Abort(MPI_COMM_WORLD, rc); exit(0); } MPI_Comm_rank(MPI_COMM_WORLD,&taskid); printf ("MPI task %d has started. ..\n", taskid); chunksize = (ARRAYSIZE / numtasks); tag2 = 1; tag1 = 2; /***** Master task only ******/
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

CS3211-Tut10 - CS3211 Parallel and Concurrent Programming...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online