Fragment of of an mpi program


2.a) Consider the following fragment of of an MPI program, and assume that at least two processors are executing. Explain the conditions under which it may deadlock, and why it may deadlock.
MPI_Comm_size(MPI_COMM_WORLD, &npes);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Send(a,1,MPI_INT,(myrank+1)%npes,1,MPI_COMM_WORLD);
MPI_Recv(b,1,MPI_INT,(myrank-1+npes)%npes,1,
MPI_COMM_WORLD,&status);
b)Consider the following sequential program fragment, which computes the
histogram of a data array. x0 and x1 are minimum and maximum values,
respectively, in the array x[1:N]. The histogram vector is h[0:M-1]
scale = M/(x1 - x0);
for (i = 1; i <= N; i++) {
j = int(scale*(x[i] - x0));
h[j]++;
}
Write an OpenMP program fragment for the histogram calculation, in which you assume that there are N threads sharing the computation. Make sure to indicate critical sections by adding appropriate directives, and make sure you use suitable directive clauses to ensure all necessary variables are shared or private.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Fragment of of an mpi program
Reference No:- TGS081690

Expected delivery within 24 Hours