#include #include #include using namespace std; int main(int argc, char * argv[]) { srand(time(nullptr)); MPI_Init(&argc, &argv); // Get the rank and size in the original communicator int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); vector scatterLoc(size); int seed; if (rank == 0) { for(auto & x: scatterLoc) { x = rand(); } } MPI_Scatter(scatterLoc.data(), 1, MPI_INT, &seed, 1, MPI_INT, 0, MPI_COMM_WORLD); cout << rank << " got " << seed << endl; if (rank == 0) { for(int i =0; i < scatterLoc.size(); ++i) { cout << scatterLoc[i] << " was at " << i << endl; } } MPI_Finalize(); return 0; }