gašper Sever
gašper Sever

Reputation: 11

How is the length determined in sendcount and recvcount in MPI.COMM_WORLD.Gather

So after I Bcast the data (clusters[10][5] 2d array) to every other process and then when each one calculates its new local values I want to send them back to the process 0.
But some of the data is missing sometimes (depends on no. of clusters) or the data is not equal to the ones I have in the sending processes. I don't know why but the max value of recvcount and recvcount need to be divided by size or by some factor, they can't be array size (10 or 10*5 - no. of elements). If I put its full size for instance cluster.lenght(10) it says indexoutofbounce 19 and if I run with more processes (mpjrun.bat -np 11 name) the higher index occurs in the outofbounce and it always goes up or down by 2 with higher/lower no. of processes (for example I use 5 processes and get outofbounce 9 and then next run use 6 and get 11).

Can someone explain why is Gather's count connected to number of processes or why it can't accept the array size?

And also the program doesn't end after the data is calculated correctly, only if I use 1 process it ends but otherwise it goes out of the loop and then print something to the terminal and after that I have MPI.finalize but nothing happens and I have Ctrl+c to terminate bat job so I can use the terminal again.

The clusterget variable is set to number of clusters*size of proceses so that it stores all the new clusters from other processes so that I can then use them all in the first process so the problem isn't in clusterget variable or maybe is it? Since there isn't really anything documented about sending through a 2d array of floats (yeah I need to use MPI.OBJECT because java doesn't like float if I use float it says Float can't be casted to Float).

 MPI.COMM_WORLD.Bcast(clusters, 0, clusters.length, MPI.OBJECT, 0);
//calculate and then send back to 0

 MPI.COMM_WORLD.Gather(clusters, 0, clusters.length / size, MPI.OBJECT, clusterget, 0, clusters.length / size, MPI.OBJECT, 0);

            if (me == 0) {

                for (int j = 0; j < clusters.length; j++) {   //adds clusters from each other process to the first ones
                    for (int i = 0; i < size - 1; i++) { 
                        System.out.println(clusterget[j+i*cluster][4]+" tock "+clusters[j][4]);
                        clusters[j][2] += clusterget[j + i * cluster][2]; //dodaj
                        clusters[j][3] += clusterget[j + i * cluster][3];
                        clusters[j][4] += clusterget[j + i * cluster][4];
                    }
                }
            }

In Summmary: The data from each process isn't the same as the one collected after gather, in which i can't put the full size of 2d float array.

Upvotes: 0

Views: 127

Answers (1)

gašper Sever
gašper Sever

Reputation: 11

I've changed gather to Send and Recv and it works and I needed to add a Barrier so that the data is in synch before sending. But this only works for 2 procesess.

     MPI.COMM_WORLD.Barrier();
            if (me != 0){
                MPI.COMM_WORLD.Send(clusters,0,clusters.length,MPI.OBJECT,0,MPI.ANY_TAG);
            }

            if (me == 0) {
                for (int i = 1; i < size; i++) {
  MPI.COMM_WORLD.Recv(clusterget,0,clusters.length,MPI.OBJECT,i,MPI.ANY_TAG);
                    for (int j = 0; j < clusters.length; j++) {
                        clusters[j][2] += clusterget[j][2]; 
                        clusters[j][3] += clusterget[j][3];
                        clusters[j][4] += clusterget[j][4];
                    }
                }

Upvotes: 0

Related Questions