diff --git a/Makefile b/Makefile index a59ac0f..f6f1f76 100644 --- a/Makefile +++ b/Makefile @@ -40,14 +40,14 @@ mpi_line_async: config utils main_mpi ${SRC}/impl/mpi_line_async.c \ -o ${BIN}/jacobi_mpi_line_async -main: ${SRC}/main.c +main: ${SRC}/main/main.c ${CC_MPI} -c ${CFLAGS} \ - ${SRC}/main.c \ + ${SRC}/main/main.c \ -o ${BUILD}/main.o -main_mpi: ${SRC}/main_mpi.c +main_mpi: ${SRC}/main/main_mpi.c ${CC_MPI} -c ${CFLAGS} \ - ${SRC}/main_mpi.c \ + ${SRC}/main/main_mpi.c \ -o ${BUILD}/main_mpi.o config: ${SRC}/config.c diff --git a/src/impl/omp.c b/src/impl/omp.c index 79b240b..e098185 100644 --- a/src/impl/omp.c +++ b/src/impl/omp.c @@ -36,11 +36,10 @@ double *compute_jacobi(int n, double init_value, double threshold, borders b, in } } /* Iterative refinement of x until values converge */ - omp_set_num_threads(2); *iterations = 0; do { max_diff = 0; - #pragma omp parallel for schedule(static, 20) \ + #pragma omp parallel for schedule(static) \ reduction (max:max_diff) \ default(none) private(new_value, j) firstprivate(n, nb) shared(x, new_x) for (i = 1; i <= n; i++) { diff --git a/src/main.c b/src/main/main.c similarity index 68% rename from src/main.c rename to src/main/main.c index 07c2e03..289e1b1 100644 --- a/src/main.c +++ b/src/main/main.c @@ -1,9 +1,9 @@ #include #include #include -#include -#include "config.h" -#include "utils.h" +#include +#include "../config.h" +#include "../utils.h" double *compute_jacobi(int n, double init_value, double threshold, borders b, int *iterations); @@ -14,8 +14,9 @@ int main(int argc, char* argv[]) { int config_loaded; configuration config; double *x; - clock_t starttime, endtime; int iterations; + struct timeval start, end; + long secs_used, micros_used; config_loaded = load_config(&config); if (config_loaded != 0) { @@ -29,11 +30,13 @@ int main(int argc, char* argv[]) { b.east = config.east; b.west = config.west; - starttime = clock(); + gettimeofday(&start, NULL); x = compute_jacobi(n, init_value, threshold, b, &iterations); - endtime = clock(); + gettimeofday(&end, NULL); - printf("clock time: %fs\n", (double)(endtime - starttime) / CLOCKS_PER_SEC); + secs_used = (end.tv_sec - start.tv_sec); + micros_used = ((secs_used * 1000000) + end.tv_usec) - (start.tv_usec); + printf("Wall clock time: %fs\n", (double) micros_used / 1000000); printf("Iterations: %d\n", iterations); if (n < 10) { print_sa_matrix(x, n + 2, n + 2); diff --git a/src/main_mpi.c b/src/main/main_mpi.c similarity index 97% rename from src/main_mpi.c rename to src/main/main_mpi.c index 95dbddc..6d3961b 100644 --- a/src/main_mpi.c +++ b/src/main/main_mpi.c @@ -2,8 +2,8 @@ #include #include #include -#include "config.h" -#include "utils.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);