Implement and test the OpenMP program for computing a matrix-matrix product (par
ID: 3689038 • Letter: I
Question
Implement and test the OpenMP program for computing a matrix-matrix product (part of the code that computes the matrix-matrix product is given below). Vary the number of threads for 4, 8, 12, 16, 20, 24, and 32. You can also use the OMP_NUM_THREADS environment variable to control the number of threads. Run the code for varied number of threads and plot the performance with varying numbers of threads. Consider three cases in which (i) only the outermost loop is parallelized; (ii) the outer two loops are parallelized; and (iii) all three loops are parallelized. What is the observed result from these three cases? Analyze your result. You should submit your c code, your report that includes your plots and analysis. #pragma omp parallel default(private) shared (a, b, c, dim) num_threads(4) #pragma omp for schedule(static) for (i = 0; i < dim; i++) { for (j = 0; j < dim; j++) { c(i,j) = 0; for (k = 0; k < dim; k++) { c(i,j) += a(i, k) * b(k, j); } } } PLEASE I NEED CLEAR ANSWER .
Explanation / Answer
Matric multiply using OMP: #include #include #include #define rowsA 72 /* These are number of rows in matrix A */ #define columnsA 25 /*These are number of columns in matrix A */ #define columnsB 7 /*These are the number of columns in matrix B */ int main (int argc, char *argv[]) { int tid, nthreads, i, j, k, chunk; double one[rowsA][columnsA], /*This is the first matrix to be multiplied */ two[columnsA][columnsB], /*This is the second matrix to be multiplied */ three[rowsA][columnsB]; /*This is the final third and result matrix */ chunk = 10; /* set loop iteration chunk size */ /*** we will now be spawning a parallel region explicitly scoping all variables ***/ #pragma omp parallel shared(a,b,c,nthreads,chunk) private(tid,i,j,k) { tid = omp_get_thread_num(); if (tid == 0) { nthreads = omp_get_num_threads(); printf("Starting matrix multiple example with %d threads ",nthreads); printf("Initializing matrices... "); } /*** This is used toInitialize matrices ***/ #This will be the pragma omp for schedule (static, chunk) //for 1st matrix for (i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.