Tugas Arsitektur Komputer Paralel4
Tugas Arsitektur Komputer Paralel4
Tugas Arsitektur Komputer Paralel4
PARALEL
EDGE DETECTION IN OPENMP USING C
LANGUAGE
Nama
: Grasiadi Hersanto
NIM
: 13212124
New.pgm
Original.pgm
New.pgm
Original.pgm
Proses
OpenM
P
Waktu Eksekusi
0.257 s
Alokasi Memori
992k
Serial
1.59s
892k
/
****************************************************************************
**/
/* Source Code:
*/
void image_filter(int pict[][IM_SIZE], int r, int c, double filter[]
[FILTER_SIZE],
int new_pict[][IM_SIZE])
{
double coeff = 0;
double sum;
int i, j, m, n;
#pragma omp parallel shared(nthreads,chunk) private(tid,i,j,m,n,sum)
{
tid = omp_get_thread_num();
t1 = omp_get_wtime(); //start time
#pragma omp for schedule (static, chunk)
for(i = 0; i < r; i++)
{
new_pict[i][0] = pict[i][0];
new_pict[i][c-1] = pict[i][c-1];
}
#pragma omp for schedule (static, chunk)
for(j = 0; j < c; j++)
{
new_pict[0][j] = pict[0][j];
new_pict[r-1][j] = pict[r-1][j];
}
#pragma omp for schedule (static, chunk)
for(i = 0; i < FILTER_SIZE; i++)
for(j = 0; j < FILTER_SIZE; j++)
coeff += filter[i][j];
/* Image Filtering */
#pragma omp for schedule (static, chunk)
for(i = 1; i < r-1; i++)
for(j = 1; j < c-1; j++)
{
sum = 0;
for(m = 0; m < FILTER_SIZE; m++)
for(n = 0; n < FILTER_SIZE; n++)
sum += pict[i+(m-1)][j+(n-1)]*filter[m][n];
new_pict[i][j] = (int)sum;
}
if(coeff != 0)
{
#pragma omp for schedule (static, chunk)
for(i = 1; i < r-1; i++)
/* Pixel Checking */
#pragma omp for schedule (static, chunk)
for(i = 1; i < r-1; i++)
for(j = 1; j < c-1; j++)
{
if(new_pict[i][j] < 0)
new_pict[i][j] = 0;
else if(new_pict[i][j] > 255)
new_pict[i][j] = 255;
}
}
return;
/* End image_filter function */
}
/* Begin write_pict function
*/
/
****************************************************************************
**/
/* Purpose : This function write the filtered image to new.pgm
*/
/
****************************************************************************
**/
/* Variable Definitions
*/
/* Variable Name
Type
Description
*/
/* pict[][]
int
array address
*/
/* new_pict[][]
int
array address
*/
/* r
int
# of rows
*/
/* c
int
# of column
*/
/* i
int
loop counter
*/
/* j
int
loop counter
*/
/* out
FILE *
output FILE pointer
*/
/
****************************************************************************
**/
/* Source Code:
*/
void write_pict(int pict[][IM_SIZE], int r, int c)
{
int i, j;
FILE *out;
out=fopen("new.pgm", "w");
fprintf(out, "P2\n");
fprintf(out, "# new.pgm\n");
fprintf(out, "%d %d\n", r, c);
fprintf(out, "255\n");
for(i = 0; i < r; i++)
{
for(j = 0; j < c; j++)
fprintf(out, "%5d", pict[i][j]);
fprintf(out, "\n");
}
fclose(out);
return;
/* End write_pict function
*/
}