/* * MPI-based Sobel Edge Detection * Copyright (C) 2000 Chen Jianxun, Sebastien Chauvin, Tarek El-Ghazawi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Sobel edge detection on a random bitmap using MPI. */ #include #include #include #include #include /* ITERATION_NUM: number of iterations of the Sobel Edge Detections. Running * the algorithm several times allows to get a more accurate execution time. */ #define ITERATION_NUM 15.0 #define BYTET unsigned char BYTET verbose=0; #ifndef DYNAMIC #ifndef IMGSIZE # error "IMGSIZE undefined." #else # define pic_size IMGSIZE #endif BYTET orig[pic_size][pic_size], edge[pic_size][pic_size]; BYTET Temp[pic_size][pic_size]; #else /* Dynamic memory allocation */ long pic_size=0; BYTET** orig; BYTET** Temp; BYTET** edge; #endif void Genrandom(void); void MPI_Sobel(); int rank, threads_num; int main(int argc, char** argv) { long i; clock_t itime; double ftime; #ifdef DYNAMIC int p ; MPI_Status status; #endif setbuf(stdout,NULL); /* if (argc > 2) { fprintf(stderr, "sobel: Too many arguments.\n"); fprintf(stderr, "sobel: usage: sobel [-q]\n"); return 1; }*/ #ifdef DEBUG for(i=0; i0) MPI_Send(orig,pic_size,MPI_BYTE,rank-1,1,MPI_COMM_WORLD); if (rank0) MPI_Recv(Localrow1,pic_size,MPI_BYTE,rank-1,0,MPI_COMM_WORLD,&status); /* Below : why should it be 'line-1' and 'pic_size-1' ?! */ for (i=1; i255? 255:(BYTET)magnitude; } } MPI_Barrier(MPI_COMM_WORLD); } void Genrandom(void) { int i,j; for (i=0; i