From 73f6be72497adc3a081df53150a1e3212c73162c Mon Sep 17 00:00:00 2001 From: Johannes Winklehner Date: Mon, 20 Jun 2016 13:24:16 +0200 Subject: [PATCH] =?UTF-8?q?Kommutativit=C3=A4t=20vom=20binom=5Freduce=20be?= =?UTF-8?q?hoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hpc_mpi/src/bin_reduce.c | 2 ++ hpc_mpi/src/binom_reduce.c | 5 ++++- hpc_mpi/src/fib_reduce.c | 2 ++ hpc_mpi/src/hpc_mpi.c | 29 +++++++++++++++++++++++------ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/hpc_mpi/src/bin_reduce.c b/hpc_mpi/src/bin_reduce.c index 7a3c0e0..45a6093 100644 --- a/hpc_mpi/src/bin_reduce.c +++ b/hpc_mpi/src/bin_reduce.c @@ -66,6 +66,7 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_left); MPI_Recv(recv_left, count, datatype, r + 1, 0, comm, &status); //printf("%i received %i from %i\n", r, *((int*) recv_left), r + 1); + printf("%i: %i + %i\n", r, ((int *)sendbuf)[0], ((int *)recv_left)[0]); MPI_Reduce_local(sendbuf, recv_left, count, datatype, op); //printf("right child of %i: %i\n", r, r + max_nodes + 1); if (r + max_nodes + 1 < p) { @@ -73,6 +74,7 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count, &status); //printf("%i received %i from %i\n", r, *((int*) recv_right), // r + max_nodes + 1); + printf("%i: %i + %i\n", r, ((int *)recv_left)[0], ((int *)recv_right)[0]); MPI_Reduce_local(recv_left, recv_right, count, datatype, op); } else { memcpy(recv_right, recv_left, count * size); diff --git a/hpc_mpi/src/binom_reduce.c b/hpc_mpi/src/binom_reduce.c index eff1858..f4543df 100644 --- a/hpc_mpi/src/binom_reduce.c +++ b/hpc_mpi/src/binom_reduce.c @@ -7,6 +7,7 @@ #include #include +#include #include "binom_reduce.h" int Binom_Reduce(const void *sendbuf, void *recvbuf, int count, @@ -32,7 +33,9 @@ int Binom_Reduce(const void *sendbuf, void *recvbuf, int count, while ((r + i) % (2 * i) != 0 && i < p) { if (r + i < p) { MPI_Recv(recv, count, datatype, r + i, i, comm, &status); - MPI_Reduce_local(recv, reduced, count, datatype, op); + printf("%i: %i + %i\n", r, ((int *)reduced)[0], ((int *)recv)[0]); + MPI_Reduce_local(reduced, recv, count, datatype, op); + memcpy(reduced, recv, count*size); } i <<= 1; } diff --git a/hpc_mpi/src/fib_reduce.c b/hpc_mpi/src/fib_reduce.c index 01de8bb..12286d8 100644 --- a/hpc_mpi/src/fib_reduce.c +++ b/hpc_mpi/src/fib_reduce.c @@ -64,10 +64,12 @@ int Fib_Reduce(const void *sendbuf, void *recvbuf, int count, void *recv_left; MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_left); MPI_Recv(recv_left, count, datatype, r + 1, 0, comm, &status); + printf("%i: %i + %i\n", r, ((int *)sendbuf)[0], ((int *)recv_left)[0]); MPI_Reduce_local(sendbuf, recv_left, count, datatype, op); if (left - 1 > 0 && r + left < p) { MPI_Recv(recv_right, count, datatype, r + left, 0, comm, &status); + printf("%i: %i + %i\n", r, ((int *)recv_left)[0], ((int *)recv_right)[0]); MPI_Reduce_local(recv_left, recv_right, count, datatype, op); } else { memcpy(recv_right, recv_left, count * size); diff --git a/hpc_mpi/src/hpc_mpi.c b/hpc_mpi/src/hpc_mpi.c index 3b8f4ab..626c10a 100644 --- a/hpc_mpi/src/hpc_mpi.c +++ b/hpc_mpi/src/hpc_mpi.c @@ -16,9 +16,20 @@ #include "binom_reduce.h" #include "fib_reduce.h" -void usage() { - fprintf(stderr, "usage..."); - exit(EXIT_FAILURE); +void usage(char *progname, int rank) { + if (rank == 0) { + fprintf(stderr, + "USAGE: %s [-b] [-o operation] size\n supported operations:\n 0 MAX\n 1 MIN\n 2 SUM\n 3 PROD\n 4 LAND\n 5 BAND\n 6 LOR\n 7 BOR\n 8 LXOR\n 9 BXOR\n", + progname); + } + MPI_Finalize(); + exit(EXIT_SUCCESS); +} + +void fill(int *a, int count, int rank) { + for (int i = 0; i < count; i++) { + a[i] = rank + i; + } } int main(int argc, char* argv[]) { @@ -42,12 +53,12 @@ int main(int argc, char* argv[]) { oparg = optarg[0]; break; default: - usage(); + usage(argv[0], r); } } if (optind >= argc) { - usage(); + usage(argv[0], r); } int size = atoi(argv[optind]); @@ -88,7 +99,7 @@ int main(int argc, char* argv[]) { int *a; MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &a); - //fill(a, size, sizeof(int)); + fill(a, size, r); if (benchmark) { int *red; @@ -147,8 +158,14 @@ int main(int argc, char* argv[]) { MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rbinom); MPI_Reduce(a, red, size, MPI_INT, op, 0, MPI_COMM_WORLD); + if(r==0) + printf("fib:\n"); Fib_Reduce(a, rfib, size, MPI_INT, op, 0, MPI_COMM_WORLD); + if(r==0) + printf("bin:\n"); Bin_Reduce(a, rbin, size, MPI_INT, op, 0, MPI_COMM_WORLD); + if(r==0) + printf("binom:\n"); Binom_Reduce(a, rbinom, size, MPI_INT, op, 0, MPI_COMM_WORLD); if (r == 0) {