To start off, I needed to calculate a number of sums and then find the minimum of those sums, this was done as so, using mpi:
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
.
.
.
x = (size)/numprocs;
low = myid * x;
high = low + x;
for(i =low; i < high; i++){
for(j = 0; j < matrixDim; j++){
for(k = 0; k < matrixDim; k+=gap){
for(m = 0; m < matrixDim; m+=gap){
c1 = calculation1(i,j,k,m);
if(c1 > cutoff){
sum += calculation2(modifier1[k][m], modifier2[k][m]);
}
}
}
if(sum < min){
min = sum;
minI = i;
minJ = j;
}
sum = 0;
}
}
MPI_Reduce(&result, &minimum, 1, MPI_FLOAT, MPI_MIN, 0, MPI_COMM_WORLD);
if( 0 == myid)
printf("The min is: %f", minimum);
MPI_Finalize();
However, now instead of finding the minimum sum of the whole 2D matrix, I need to find the minimum sum of every partition in the matrix, a partition will be a square defined by four points, and no matter the matrix size, there will always be 16 squares (the matrix is no smaller than 800 * 800). I'm trying to implement this using a MPI Cartesian topology, however I'm having trouble wrapping my head around the implementation. Any help, or tips would be appreciated.