I have an array of numbers that I need to scatter to each node in an MPI program. The setup is that I have an array of numbers from 1 to 100 with all the even numbers except the number 2 removed. Due to the way I removed the even numbers, the number 2 is the last element in the array.
So my array contains 51 odd numbers, 3, 5, 7, ... 99, 2. My problem is that the final partition after a scatter does not contain the last three numbers in the array - 97, 99 and 2.
int *oddsOnly = //array as setup above, 3,5,7,...99,2
int chunkSize = (oddsFound / worldSize);
int *localPartition = new int[chunkSize];
// Send everyone the chunk size
MPI_Bcast(&chunkSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Scatter(oddsOnly, chunkSize, MPI_INT, localPartition, chunkSize, MPI_INT, 0, MPI_COMM_WORLD);
I understand the issue is that the number of ranks and the array size don't divide evenly, I've tried
chunkSize = ceil(oddsFound / worldSize);
And
chunkSize = (oddsFound / worldSize) + 1;
But this then gives me duplicates in the split.
As it stands I get
0 scatter is 1 3 5 7 9 11 13 15 17 19 21 23
1 scatter is 25 27 29 31 33 35 37 39 41 43 45 47
2 scatter is 49 51 53 55 57 59 61 63 65 67 69 71
3 scatter is 73 75 77 79 81 83 85 87 89 91 93 95
Is it possible to do what I'm attemptimg tidily? I had a look at scatterV but I'm not sure its what I need. I should add I don't have to scatter, so maybe there is a better MPI way of doing it.