Therefore, for an element (in the middle of the window), the updated value is th
ID: 3756276 • Letter: T
Question
Therefore, for an element (in the middle of the window), the updated value is the square root of the average of square of the elements in the 3x3 window. Similar to the Problem 1, this problem has two parts: (a) Applying MPl and (b) applying OpenMP for high performance. You will be using 1, 4, 8, 16, and 32 processors and threads, respectively. You need to show the total execution time and computation to communication ratio for MPI and thread event times for OpenMP and discuss your results in your report. Please note that for the 256x256 matrix, the boundaries (the first & last column & row) will be causing a irregularity, i.e. calculating the new value for the boundaries require one extra row and/or column that does not exist. There are two solutions for that: (1) You can either skip the computations of the boundaries or (2) you can assume that the required extra row/column entries are filled with zero (or the same value of your element). We accept both cases as long as you explain them in your algorithm.Explanation / Answer
Below is the C-code :
The different timings can be otained while running the code on diferent processors.
#include <time.h>
void main(void)
{
int ROW=256,COL=256,r,c;
unsigned int P0,P1,P2,P3,P4,P5,P6,P7,P8,FilteredImg[ROW][COL];
unsigned int Img[ROW][COL]; //Input Image
double cpu_time_used;
/*
P8 P1 P2
....
P7 :P0: P3
....
P6 P5 P4
*/
FilteredImg = Img;
clock_t start, end;
start = clock();
for(r=1;r<ROW-1;r++) // Boundary pixels left
{
for(c=1;c<COL-1;c++) // Boundary pixels left
{
P0 = power(Img(r,c),2);
P1 = power(Img(r-1,c),2);
P2 = power(Img(r-1,c+1),2);
P3 = power(Img(r,c+1),2);
P4 = power(Img(r+1,c+1),2);
P5 = power(Img(r+1,c),2);
P6 = power(Img(r+1,c-1),2);
P7 = power(Img(r,c-1),2);
P8 = power(Img(r-1,c-1),2);
FilteredImg(r,c) = floor(sqrt((P0+P1+P2+P3+P4+P5+P6+P7+P8)/9)); //The floor command will round off the value towards zero. e.g. floor(5.6) = 5
}
}
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("CPU Time = %.3f",cpu_time_used );
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.