ex3: task 3

This commit is contained in:
2025-09-22 17:20:04 +02:00
parent ad41c944b3
commit 34c7c09ca4

View File

@@ -19,7 +19,11 @@ typedef double real_t;
// TASK: T1b
// Declare variables each MPI process will need
// BEGIN: T1b
;
int comm_size;
int comm_rank;
int_t n;
#define I(i) ((i) + n * comm_rank)
// END: T1b
// Simulation parameters: size, step count, and how often to save the state.
@@ -64,12 +68,13 @@ void domain_save(int_t step) {
// and set the time step.
void domain_initialize(void) {
// BEGIN: T3
buffers[0] = malloc((N + 2) * sizeof(real_t));
buffers[1] = malloc((N + 2) * sizeof(real_t));
buffers[2] = malloc((N + 2) * sizeof(real_t));
const int_t bufsize = (comm_rank == ROOT ? N : n + 2);
buffers[0] = malloc(bufsize * sizeof(real_t));
buffers[1] = malloc(bufsize * sizeof(real_t));
buffers[2] = malloc(bufsize * sizeof(real_t));
for (int_t i = 0; i < N; i++) {
U_prv(i) = U(i) = cos(2 * M_PI * i / (real_t)N);
for (int_t i = 0; i < n; i++) {
U_prv(i) = U(i) = cos(2 * M_PI * (i + offset) / (real_t)N);
}
// END: T3