Question

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.

Was it helpful?

Solution

This is more of an extended comment than an answer ...

Like francesco I'm not sure that I see the need for a cartesian (or any other) topology here. If your problem is as you describe it each MPI process can compute a partition minimum sum without either sending or receiving data from the other processes (apart, probably, from an initial scatter and terminal gather).

Toplogies are generally used for situations where the problem decomposes into pieces and those pieces have some idea of relative neighbourliness: in a cartesian topology a process (or piece of the problem) might have east, west, north and south neighbours for example. I don't see such a concept here, nor any utility in forcing it onto this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top