I guess my question has 2 parts:
(1) Is this the right approach to send different chunks of an array to different processors? Let's say I have n processors whose rank ranges from 0 to n-1. I have an array of size d. I want to split this array into k equally-sized chunks. Assume d is divisible by k. I want to send each of these chunks to a processor whose rank is less than k. It would be easy if I use something like MPI_Scatter, but this function is sends to EVERY OTHER processors, but I only want to send to a certain number of procs. So what I did was that I have a loop of k iterations and do k MPI_Send's. Is this efficient?
(2) If it is, how do I split an array into chunks? There's always the easy way, which is
int size = d/k;
int buff[size];
for (int k = 0; k < max; ++k)
{
for (int i = 0; i < size ++i)
buff[i] = input[k*size + i];
MPI_Send(&buff[0], size, k, comm);
}
Aucun commentaire:
Enregistrer un commentaire