ex3: task 1
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
// TASK: T1a
|
||||
// Include the MPI headerfile
|
||||
// BEGIN: T1a
|
||||
;
|
||||
#include <mpi.h>
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user