0
행렬을 얻고 청크별로 분배하는 코드를 작성합니다. 청크 크기가 항상 같지 않을 수도 있습니다. 청크가 제대로 작동하지만이 값을 3으로 설정하려고하면 (예를 들어) 'mpirun이 노드 클러스터에서 PID 8676의 프로세스 2가 신호 6 (종료됨)에서 종료됨을 알게되었습니다.'라는 오류가 나타납니다. 첨부 된 코드를 살펴보십시오. 문제는 무료입니다. 당신이 잘못 할당과 같은프로세스가 신호 6에서 종료되었습니다 (중단됨)
#include <stdio.h>
#include <mpi.h>
#include <stdlib.h>
#define COLUMN 4
#define ROW 10
#define dp 100.0f
// Local start
#define chunk_low(commrank, commsize, nvert) \
((commrank) * (nvert)/(commsize))
// Local end
#define chunk_height(commrank, commsize, nvert) \
(chunk_low((commrank) + 1, commsize, nvert) - 1)
// Local size
#define chunk_size(commrank, commsize, nvert) \
(chunk_height(commrank, commsize, nvert) - \
chunk_low(commrank, commsize, nvert) + 1)
// Matrix initialization function
void init_matrix(int column, int row, float *matrix)
{
int j, i;
printf("\nMatrix\n");
for(i=0; i < row; i++){
for(j=0; j < column; j++){
matrix[i*column+j] = i * column + j; // (float)rand()/RAND_MAX * dp *2.0f - dp;
printf(" %f ", matrix[i * column + j]);
}
printf("\n");
}
printf("\n");
}
int main(int argc, char **argv)
{
int rank, size;
int i, j;
float *vm, *local_matrix;
double time1, time2;
int *displs, *rcounts, *scounts;
vm = (float *)calloc(ROW * COLUMN, sizeof(float));
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
/* Process 0 - master */
if (rank==0)
{
printf("\nNumbers of proccesses %d. \nElements in vector %d.\n", size, COLUMN);
/* Init vector vA */
init_matrix(COLUMN, ROW, vm);
//Time begining calculating of programm
time1=MPI_Wtime();
}
/* End of work process 0 */
displs = (int *)malloc(sizeof(int) * size);
scounts = (int *)malloc(sizeof(int) * size);
rcounts = (int *)malloc(sizeof(int) * size);
for (i = 0; i < size; i++) {
displs[i] = chunk_low(i, size, ROW) * COLUMN; // Position initialization
rcounts[i] = scounts[i] = chunk_size(i, size, ROW) * COLUMN;
printf("\ndispls[%d]=%d, scounts[%d]=%d\n",i , displs[i], i, scounts[i]);
}
local_matrix = (float *)calloc(chunk_size(i, size, ROW) * COLUMN, sizeof(float));
MPI_Scatterv(vm, scounts, displs, MPI_FLOAT, local_matrix,
rcounts[rank], MPI_FLOAT, 0, MPI_COMM_WORLD);
printf("\nProcess=%d Displs=%d rcounts=%d\n", rank, displs[rank], rcounts[rank]);
printf("Local Matrix\n");
for(i=0; i < scounts[rank]; i++){
printf(" %f ", local_matrix[i]);
if (scounts[rank] % ROW == 0) {
printf("%n");
}
}
printf("\n");
/* Only master-process */
if (rank==0)
{
//Time ending programm
time2=MPI_Wtime();
printf("\nTime parallel calculation = %f s.\n",time2-time1);
}
// End work of master-process
/* Delete storage arrays of process */
free(displs);
free(scounts);
free(rcounts);
free(local_matrix);
MPI_Finalize();
return 0;
}
OMG를 의미 생각합니다. 고마워요! 너무 작고 어리 석다. – AZawalar