From d25da4df8cc2c3cf5535495d167378273026ca56 Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Mon, 22 Sep 2025 16:33:07 +0200 Subject: [PATCH] ex3: task 1 --- exercise3/wave_1d_parallel.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/exercise3/wave_1d_parallel.c b/exercise3/wave_1d_parallel.c index ef9847c..d81c084 100644 --- a/exercise3/wave_1d_parallel.c +++ b/exercise3/wave_1d_parallel.c @@ -9,7 +9,7 @@ // TASK: T1a // Include the MPI headerfile // BEGIN: T1a -; +#include // END: T1a // Option to change numerical precision. @@ -19,7 +19,10 @@ typedef double real_t; // TASK: T1b // Declare variables each MPI process will need // BEGIN: T1b -; +#define ROOT 0 +int comm_size; +int comm_rank; +int_t n; // END: T1b // Simulation parameters: size, step count, and how often to save the state. @@ -150,7 +153,14 @@ int main(int argc, char **argv) { // TASK: T1c // Initialise MPI // BEGIN: T1c - ; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank); + MPI_Comm_size(MPI_COMM_WORLD, &comm_size); + + n = N / comm_size; + int_t remr = N % comm_size; + if (comm_rank < remr) + n++; // END: T1c struct timeval t_start, t_end; @@ -168,7 +178,7 @@ int main(int argc, char **argv) { // TASK: T1d // Finalise MPI // BEGIN: T1d - ; + MPI_Finalize(); // END: T1d exit(EXIT_SUCCESS);