Kommutativität vom binom_reduce behoben

This commit is contained in:
Johannes Winklehner 2016-06-20 13:24:16 +02:00
parent a08f03ba4c
commit 73f6be7249
4 changed files with 31 additions and 7 deletions

View file

@ -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_Alloc_mem(count * size, MPI_INFO_NULL, &recv_left);
MPI_Recv(recv_left, count, datatype, r + 1, 0, comm, &status); 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 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); MPI_Reduce_local(sendbuf, recv_left, count, datatype, op);
//printf("right child of %i: %i\n", r, r + max_nodes + 1); //printf("right child of %i: %i\n", r, r + max_nodes + 1);
if (r + max_nodes + 1 < p) { if (r + max_nodes + 1 < p) {
@ -73,6 +74,7 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count,
&status); &status);
//printf("%i received %i from %i\n", r, *((int*) recv_right), //printf("%i received %i from %i\n", r, *((int*) recv_right),
// r + max_nodes + 1); // 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); MPI_Reduce_local(recv_left, recv_right, count, datatype, op);
} else { } else {
memcpy(recv_right, recv_left, count * size); memcpy(recv_right, recv_left, count * size);

View file

@ -7,6 +7,7 @@
#include <mpi.h> #include <mpi.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "binom_reduce.h" #include "binom_reduce.h"
int Binom_Reduce(const void *sendbuf, void *recvbuf, int count, 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) { while ((r + i) % (2 * i) != 0 && i < p) {
if (r + i < p) { if (r + i < p) {
MPI_Recv(recv, count, datatype, r + i, i, comm, &status); 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; i <<= 1;
} }

View file

@ -64,10 +64,12 @@ int Fib_Reduce(const void *sendbuf, void *recvbuf, int count,
void *recv_left; void *recv_left;
MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_left); MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_left);
MPI_Recv(recv_left, count, datatype, r + 1, 0, comm, &status); 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); MPI_Reduce_local(sendbuf, recv_left, count, datatype, op);
if (left - 1 > 0 && r + left < p) { if (left - 1 > 0 && r + left < p) {
MPI_Recv(recv_right, count, datatype, r + left, 0, comm, &status); 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); MPI_Reduce_local(recv_left, recv_right, count, datatype, op);
} else { } else {
memcpy(recv_right, recv_left, count * size); memcpy(recv_right, recv_left, count * size);

View file

@ -16,9 +16,20 @@
#include "binom_reduce.h" #include "binom_reduce.h"
#include "fib_reduce.h" #include "fib_reduce.h"
void usage() { void usage(char *progname, int rank) {
fprintf(stderr, "usage..."); if (rank == 0) {
exit(EXIT_FAILURE); 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[]) { int main(int argc, char* argv[]) {
@ -42,12 +53,12 @@ int main(int argc, char* argv[]) {
oparg = optarg[0]; oparg = optarg[0];
break; break;
default: default:
usage(); usage(argv[0], r);
} }
} }
if (optind >= argc) { if (optind >= argc) {
usage(); usage(argv[0], r);
} }
int size = atoi(argv[optind]); int size = atoi(argv[optind]);
@ -88,7 +99,7 @@ int main(int argc, char* argv[]) {
int *a; int *a;
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &a); MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &a);
//fill(a, size, sizeof(int)); fill(a, size, r);
if (benchmark) { if (benchmark) {
int *red; int *red;
@ -147,8 +158,14 @@ int main(int argc, char* argv[]) {
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rbinom); MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rbinom);
MPI_Reduce(a, red, size, MPI_INT, op, 0, MPI_COMM_WORLD); 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); 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); 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); Binom_Reduce(a, rbinom, size, MPI_INT, op, 0, MPI_COMM_WORLD);
if (r == 0) { if (r == 0) {