Я пытаюсь распределить точки (с координатами x и y - массив с размером = 2) процессами, использующими Scatter, а затем собрать результат с помощью MPI_gather. Проблема заключается в возникновении ошибки сегментации. Стоит ли выделять также память для приемников? И как я могу определить send_count для отправки всех точек независимо от количества процессов - я имею в виду, если у меня есть 5 точек и 3 процесса, как я могу их отправить?
// Getting rank and size
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
// Initialisation of the points :
// The process with rank 0 will hold all the points
// The others will keep the variable poitns as a null pointer
double *points = NULL;
double* rcvpoint = NULL;
int npts = p_count*p_count;
int p_p = npts/size;
if(rank==0){
points = new double[p_count * p_count * 2];
for (int yp=0; yp < p_count; ++yp) {
double py = min_y + dy * yp / p_count;
for (int xp=0; xp < p_count; ++xp) {
double px = min_x + dx * xp / p_count;
int lid = yp*p_count*2 + xp*2;
points[lid] = px;
points[lid+1] = py;
}
}
}
else{
//rcvpoint = new double[npts * 2];
}
int mset[npts];
int rmset[p_p];
MPI_Barrier(MPI_COMM_WORLD);
MPI_Scatter(points, p_p*2, MPI_DOUBLE,rcvpoint,p_p*2,MPI_DOUBLE,0,MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
compute_mandelbrot(rcvpoint,p_p, rmset);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Gather(rmset,p_p*2,MPI_INT,mset,p_p*2,MPI_INT,0,MPI_COMM_WORLD);
// Printing only one result that will be used to create the image
if (rank==0) {
for (int yp=0; yp < p_count; ++yp) {
for (int xp=0; xp < p_count; ++xp)
std::cout << mset[yp*p_count + xp] << " ";
std::cout << std::endl;
}
}