먼저 this code을 참조로 사용했습니다. MPI_Gather
을 사용하지 않고 MPI_Scatter
을 사용하지 않았으므로 여기에서 얻으려고합니다. 나는 오랫동안이 작업을 해왔고 문제를 파악할 수 없습니다. 이 소벨 가장자리 감지 알고리즘은 이미지 내부의 오브젝트 윤곽을 강화합니다.MPI 루트 프로세스 만 모으십시오.
너무 많지는 않지만 아래 코드를 게시 하겠지만 빠른 코드 설명을 먼저 제공 할 것입니다.
순차 프로그램을 병렬 프로그램으로 변환하려고합니다. 그래서 모든 비 MPI 코드가 정확합니다.
내 MPI
코드로 어딘가에 실수가있을 수 있습니다.
int main(int argc, char **argv) {
FILE *inFile, *oFile;
int grayImage[N][N], edgeImage[N][N];
char type[2];
int w, h, max;
int r, g, b, y, x, i, j, sum, sumx, sumy;
int tid;
int GX[3][3], GY[3][3];
double elapsed_time;
struct timeval tv1, tv2;
int error = 0;
char buffer[BUFSIZ];
int rank, NP;
// Code lies here for reading from the image file and storing into the grayImage array.
// This works so I saw no reason to include it
/* 3x3 Sobel masks. */
GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;
GY[0][0] = 1; GY[0][1] = 2; GY[0][2] = 1;
GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0;
GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &NP);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// This calculates the block size.MPI
// On 4 processors the block size for a 100x100 image would be 25x100 each
int blksz = (int)ceil((double)N/NP);
// This creates a local array for each processor, soon to be gathered
int tempEdge[blksz][N];
// this line shows it's working correctly
printf("processor %d, width: %d, height: %d, blksz: %d, begin: %d, end: %d\n", rank, w, h, blksz, rank*blksz, (rank+1)*blksz);
for(x=rank*blksz; x < (rank+1)*blksz && x<h; x++){
// Any code in this loop can be ignored as it works correctly.
for(y=0; y < w; ++y){
sumx = 0;
sumy = 0;
// handle image boundaries
if(x==0 || x==(h-1) || y==0 || y==(w-1))
sum = 0;
else{
//x gradient approx
for(i=-1; i<=1; i++) {
for(j=-1; j<=1; j++){
sumx += (grayImage[x+i][y+j] * GX[i+1][j+1]);
}
}
//y gradient approx
for(i=-1; i<=1; i++) {
for(j=-1; j<=1; j++){
sumy += (grayImage[x+i][y+j] * GY[i+1][j+1]);
}
}
//gradient magnitude approx
sum = (abs(sumx) + abs(sumy));
}
tempEdge[x][y] = clamp(sum);
}
}
// Here is the line I am guessing is causing the problem
MPI_Gather(&tempEdge, w*blksz, MPI_INT,
&edgeImage, w*blksz, MPI_INT, 0,
MPI_COMM_WORLD);
// Finally, I output edgeImage to a file here.
if(rank==0){
// output edgeImage to File
}
MPI_Finalize();
return 0;
}
은 내가 사용하고 입력 영상은 이것이다 :
그러나 출력은이주고있다 : 당신이 그것을 볼 수 있듯이
만입니다 최고 분기 (N/4) 또는 blksz
입니다.
이것은 MPI_Gather
이 순위 0의 프로세스에서만 수집된다는 의미입니까?
나는 이것에 많은 시간을 보냈습니다. 어떤 도움이라도 대단히 감사 할 것입니다!
나는 그것을 놓친다 고 실제로 믿을 수 없다! 지금 나는 SO에 그것을 게시하는 것에 대해 멍청하다고 느낍니다. 모든 코드를 검토해 주셔서 감사합니다! –
필자는 MPI 코드 디버깅은 한 손의 손가락에 사용할 수있는 병렬 디버거의 수를 계산할 수 있고 대부분 상업용으로 사용할 수 있기 때문에 어렵다고합니다. –