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_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);

View file

@ -7,6 +7,7 @@
#include <mpi.h>
#include <string.h>
#include <stdio.h>
#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;
}

View file

@ -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);

View file

@ -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) {