Separated main
This commit is contained in:
parent
deb20e1382
commit
6b83411a49
7
Makefile
7
Makefile
|
@ -9,12 +9,15 @@ all: sequential mpi_line
|
||||||
sequential: config utils main
|
sequential: config utils main
|
||||||
${CC} ${CFLAGS} ${BUILD}/config.o ${BUILD}/utils.o ${BUILD}/main.o ${SRC}/impl/sequential.c -o ${BIN}/jacobi_sequential
|
${CC} ${CFLAGS} ${BUILD}/config.o ${BUILD}/utils.o ${BUILD}/main.o ${SRC}/impl/sequential.c -o ${BIN}/jacobi_sequential
|
||||||
|
|
||||||
mpi_line: config utils main
|
mpi_line: config utils main_mpi
|
||||||
${CC} ${CFLAGS} ${BUILD}/config.o ${BUILD}/utils.o ${BUILD}/main.o ${SRC}/impl/mpi_line.c -o ${BIN}/jacobi_mpi_line
|
${CC} ${CFLAGS} ${BUILD}/config.o ${BUILD}/utils.o ${BUILD}/main_mpi.o ${SRC}/impl/mpi_line.c -o ${BIN}/jacobi_mpi_line
|
||||||
|
|
||||||
main: ${SRC}/main.c
|
main: ${SRC}/main.c
|
||||||
${CC} -c ${CFLAGS} ${SRC}/main.c -o ${BUILD}/main.o
|
${CC} -c ${CFLAGS} ${SRC}/main.c -o ${BUILD}/main.o
|
||||||
|
|
||||||
|
main_mpi: ${SRC}/main_mpi.c
|
||||||
|
${CC} -c ${CFLAGS} ${SRC}/main_mpi.c -o ${BUILD}/main_mpi.o
|
||||||
|
|
||||||
config: ${SRC}/config.c
|
config: ${SRC}/config.c
|
||||||
${CC} -c ${CFLAGS} ${SRC}/config.c -o ${BUILD}/config.o
|
${CC} -c ${CFLAGS} ${SRC}/config.c -o ${BUILD}/config.o
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,15 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <mpi.h>
|
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
double *compute_jacobi(int rank, int numprocs, int n, double init_value, double threshold, borders b, int *iterations) {
|
double *compute_jacobi(int n, double init_value, double threshold, borders b, int *iterations) {
|
||||||
double *x;
|
double *x;
|
||||||
double max_diff, new_x;
|
double max_diff, new_x;
|
||||||
int i, j;
|
int i, j;
|
||||||
int nb = n + 2; // n plus the border
|
int nb = n + 2; // n plus the border
|
||||||
|
|
||||||
if (numprocs != 1) {
|
|
||||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize boundary regions */
|
/* Initialize boundary regions */
|
||||||
x = create_sa_matrix(n + 2, n + 2);
|
x = create_sa_matrix(n + 2, n + 2);
|
||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++) {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
double *compute_jacobi(int rank, int numprocs, int n, double init_value, double threshold, borders b, int *iterations);
|
|
72
src/main.c
72
src/main.c
|
@ -1,76 +1,42 @@
|
||||||
/*
|
|
||||||
* MPI version with the matrix subdivided by "lines".
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <mpi.h>
|
#include <time.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "jacobi.h"
|
|
||||||
|
|
||||||
|
double *compute_jacobi(int n, double init_value, double threshold, borders b, int *iterations);
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
int rank;
|
|
||||||
int numprocs;
|
|
||||||
int n;
|
int n;
|
||||||
double init_value, threshold;
|
double init_value, threshold;
|
||||||
double north, south, east, west;
|
|
||||||
borders b;
|
borders b;
|
||||||
int config_loaded;
|
int config_loaded;
|
||||||
configuration config;
|
configuration config;
|
||||||
double *x;
|
double *x;
|
||||||
double startwtime = 0.0, endwtime;
|
clock_t starttime, endtime;
|
||||||
int iterations;
|
int iterations;
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
config_loaded = load_config(&config);
|
||||||
|
if (config_loaded != 0) {
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
return 1;
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
|
|
||||||
|
|
||||||
if (rank == 0) {
|
|
||||||
config_loaded = load_config(&config);
|
|
||||||
if (config_loaded != 0) {
|
|
||||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
||||||
}
|
|
||||||
n = config.n;
|
|
||||||
threshold = config.threshold;
|
|
||||||
init_value = config.init_value;
|
|
||||||
north = config.north;
|
|
||||||
south = config.south;
|
|
||||||
east = config.east;
|
|
||||||
west = config.west;
|
|
||||||
}
|
}
|
||||||
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
n = config.n;
|
||||||
MPI_Bcast(&init_value, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
threshold = config.threshold;
|
||||||
MPI_Bcast(&threshold, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
init_value = config.init_value;
|
||||||
MPI_Bcast(&north, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
b.north = config.north;
|
||||||
MPI_Bcast(&south, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
b.south = config.south;
|
||||||
MPI_Bcast(&east, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
b.east = config.east;
|
||||||
MPI_Bcast(&west, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
b.west = config.west;
|
||||||
|
|
||||||
b.north = north;
|
starttime = clock();
|
||||||
b.south = south;
|
x = compute_jacobi(n, init_value, threshold, b, &iterations);
|
||||||
b.east = east;
|
endtime = clock();
|
||||||
b.west = west;
|
|
||||||
|
|
||||||
if (rank == 0) {
|
|
||||||
startwtime = MPI_Wtime();
|
|
||||||
}
|
|
||||||
|
|
||||||
x = compute_jacobi(rank, numprocs, n, init_value, threshold, b, &iterations);
|
|
||||||
|
|
||||||
if (rank == 0) {
|
|
||||||
endwtime = MPI_Wtime();
|
|
||||||
printf("Wall clock time: %fs\n", endwtime - startwtime);
|
|
||||||
printf("Iterations: %d\n", iterations);
|
|
||||||
print_sa_matrix(x, n + 2, n + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
printf("clock time: %fs\n", (double)(endtime - starttime) / CLOCKS_PER_SEC);
|
||||||
|
printf("Iterations: %d\n", iterations);
|
||||||
|
print_sa_matrix(x, n + 2, n + 2);
|
||||||
destroy_sa_matrix(x);
|
destroy_sa_matrix(x);
|
||||||
|
|
||||||
MPI_Finalize();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
72
src/main_mpi.c
Normal file
72
src/main_mpi.c
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <mpi.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
double *compute_jacobi(int rank, int numprocs, int n, double init_value, double threshold, borders b, int *iterations);
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
int rank;
|
||||||
|
int numprocs;
|
||||||
|
int n;
|
||||||
|
double init_value, threshold;
|
||||||
|
double north, south, east, west;
|
||||||
|
borders b;
|
||||||
|
int config_loaded;
|
||||||
|
configuration config;
|
||||||
|
double *x;
|
||||||
|
double startwtime = 0.0, endwtime;
|
||||||
|
int iterations;
|
||||||
|
|
||||||
|
MPI_Init(&argc, &argv);
|
||||||
|
|
||||||
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||||
|
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
|
||||||
|
|
||||||
|
if (rank == 0) {
|
||||||
|
config_loaded = load_config(&config);
|
||||||
|
if (config_loaded != 0) {
|
||||||
|
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||||
|
}
|
||||||
|
n = config.n;
|
||||||
|
threshold = config.threshold;
|
||||||
|
init_value = config.init_value;
|
||||||
|
north = config.north;
|
||||||
|
south = config.south;
|
||||||
|
east = config.east;
|
||||||
|
west = config.west;
|
||||||
|
}
|
||||||
|
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&init_value, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&threshold, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&north, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&south, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&east, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
MPI_Bcast(&west, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
||||||
|
|
||||||
|
b.north = north;
|
||||||
|
b.south = south;
|
||||||
|
b.east = east;
|
||||||
|
b.west = west;
|
||||||
|
|
||||||
|
if (rank == 0) {
|
||||||
|
startwtime = MPI_Wtime();
|
||||||
|
}
|
||||||
|
|
||||||
|
x = compute_jacobi(rank, numprocs, n, init_value, threshold, b, &iterations);
|
||||||
|
|
||||||
|
if (rank == 0) {
|
||||||
|
endwtime = MPI_Wtime();
|
||||||
|
printf("Wall clock time: %fs\n", endwtime - startwtime);
|
||||||
|
printf("Iterations: %d\n", iterations);
|
||||||
|
print_sa_matrix(x, n + 2, n + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy_sa_matrix(x);
|
||||||
|
|
||||||
|
MPI_Finalize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user