diff --git a/exercise3/wave_1d_parallel.c b/exercise3/wave_1d_parallel.c index ef9847c..14eb4d0 100644 --- a/exercise3/wave_1d_parallel.c +++ b/exercise3/wave_1d_parallel.c @@ -124,7 +124,16 @@ void border_exchange(void) { // to root and assemble it in the root buffer void send_data_to_root() { // BEGIN: T7 - ; + if (comm_rank != ROOT) { + MPI_Send(&U(0), n, MPI_DOUBLE, ROOT, 0, MPI_COMM_WORLD); + } else { + int offset = n; + for (int i = 1; i < comm_size; i++) { + int proc_n = N / comm_size + (i < N % comm_size); + MPI_Recv(&U(offset), proc_n, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + offset += proc_n; + } + } // END: T7 }