Heap memory for matrix and elapsed time

This commit is contained in:
Fabio Salvini
2016-11-12 21:53:11 +01:00
parent 85c3977901
commit 784416b7ca
8 changed files with 115 additions and 37 deletions

View File

@@ -1,12 +1,15 @@
CC=gcc
CC=mpicc
CFLAGS=-Wall -lm -std=c99
all: config jacobi_sequential.c
${CC} ${CFLAGS} config.o jacobi_sequential.c -o jacobi.out
all: config utils jacobi_sequential.c
${CC} ${CFLAGS} config.o utils.o jacobi_sequential.c -o jacobi.out
config: ../config/config.c
${CC} -c ${CFLAGS} ../config/config.c
utils: ../utils/utils.c
${CC} -c ${CFLAGS} ../utils/utils.c
.PHONY: clean
clean:
rm -f *.out *.o

View File

@@ -1,7 +1,7 @@
# Configuration file for the Jacobi project.
# The size of the matrix (borders excluded).
N 10
N 5000
# The value at each border.
NORTH 0.0

View File

@@ -5,21 +5,25 @@
#include <stdio.h>
#include <math.h>
#include <mpi.h>
#include "../config/config.h"
typedef struct borders {
double north;
double east;
double south;
double west;
} borders;
#include "../utils/utils.h"
void compute_jacobi(int n, double init_value, double threshold, borders b);
int main(int argc, char* argv[]) {
int numprocs;
int config_loaded;
configuration config;
borders b;
double startwtime = 0.0, endwtime;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
if (numprocs != 1) {
MPI_Abort(MPI_COMM_WORLD, 1);
}
config_loaded = load_config(&config);
if (config_loaded != 0) {
@@ -31,17 +35,24 @@ int main(int argc, char* argv[]) {
b.south = config.south;
b.west = config.west;
startwtime = MPI_Wtime();
compute_jacobi(config.n, config.init_value, config.threshold, b);
endwtime = MPI_Wtime();
printf("Wall clock time: %fs\n", endwtime - startwtime);
MPI_Finalize();
return 0;
}
void compute_jacobi(int n, double init_value, double threshold, borders b) {
double x[n + 2][n + 2];
double **x;
double max_diff, new_x;
int i, j;
/* Initialize boundary regions */
x = create_matrix(n + 2, n + 2);
for (i = 1; i <= n; i++) {
x[0][i] = b.north;
x[n + 1][i] = b.south;
@@ -65,4 +76,6 @@ void compute_jacobi(int n, double init_value, double threshold, borders b) {
}
}
} while (max_diff > threshold);
destroy_matrix(x, n + 2);
}