#include #include #include using namespace std; const int tag = 34; int main(int argc, char **argv) { int pid, nprocs; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &pid); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); int n = atoi(argv[1]); // taille du tableau total if (n%nprocs!=0) { MPI_Finalize(); cout << "Impossible d'exécuter " << n << " n'est pas divisible par nprocs=" << nprocs << endl; return 0; } int root = atoi(argv[2]); int* tab; if (pid==root) { tab = new int [n]; random_device rd; mt19937 gen(rd()); uniform_int_distribution<> dis(0, 1000); for (int i = 0; i < n; i++) tab[i] = dis(gen); cout << "pid=" << pid << " : "; for (int i = 0; i < n; i++) cout << tab[i] << " "; cout << endl; } int n_local = n/nprocs; int* tab_recu = new int[n_local]; if (pid==root) for (int i=0; i