Testmöglichkeit erstellt
This commit is contained in:
parent
327ca4d5cb
commit
dadb581ed1
2 changed files with 124 additions and 35 deletions
|
@ -46,7 +46,7 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count,
|
||||||
if (r == root) {
|
if (r == root) {
|
||||||
recv_right = recvbuf;
|
recv_right = recvbuf;
|
||||||
} else {
|
} else {
|
||||||
printf("%i gets some memory\n", r);
|
//printf("%i gets some memory\n", r);
|
||||||
MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_right);
|
MPI_Alloc_mem(count * size, MPI_INFO_NULL, &recv_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,19 +60,19 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count,
|
||||||
max_nodes /= 2;
|
max_nodes /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%i: %i\n", r, parent);
|
//printf("%i: %i\n", r, parent);
|
||||||
|
|
||||||
if (depth != tree_depth && r + 1 < p) {
|
if (depth != tree_depth && r + 1 < p) {
|
||||||
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);
|
||||||
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) {
|
||||||
MPI_Recv(recv_right, count, datatype, r + max_nodes + 1, 0, comm,
|
MPI_Recv(recv_right, count, datatype, r + max_nodes + 1, 0, comm,
|
||||||
&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);
|
||||||
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);
|
||||||
|
@ -84,7 +84,7 @@ int Bin_Reduce(const void *sendbuf, void *recvbuf, int count,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r != root) {
|
if (r != root) {
|
||||||
printf("%i sends %i to %i\n", r, *((int*) recv_right), parent);
|
//printf("%i sends %i to %i\n", r, *((int*) recv_right), parent);
|
||||||
MPI_Send(recv_right, count, datatype, parent, 0, comm);
|
MPI_Send(recv_right, count, datatype, parent, 0, comm);
|
||||||
MPI_Free_mem(recv_right);
|
MPI_Free_mem(recv_right);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,37 +10,126 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "bin_reduce.h"
|
#include "bin_reduce.h"
|
||||||
#include "binom_reduce.h"
|
#include "binom_reduce.h"
|
||||||
#include "fib_reduce.h"
|
#include "fib_reduce.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
void usage() {
|
||||||
int my_rank; /* rank of process */
|
fprintf(stderr, "usage...");
|
||||||
int p; /* number of processes */
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
/* start up MPI */
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
MPI_Init(&argc, &argv);
|
int r;
|
||||||
|
int p;
|
||||||
/* find out process rank */
|
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
|
MPI_Init(&argc, &argv);
|
||||||
|
MPI_Comm_rank(MPI_COMM_WORLD, &r);
|
||||||
/* find out number of processes */
|
MPI_Comm_size(MPI_COMM_WORLD, &p);
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &p);
|
|
||||||
|
int opt;
|
||||||
int a = my_rank;
|
int benchmark = 0;
|
||||||
int recv;
|
char oparg = '0';
|
||||||
|
|
||||||
Fib_Reduce(&a, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
while ((opt = getopt(argc, argv, "bo:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
//Binom_Reduce(&a, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
case 'b':
|
||||||
|
benchmark = 1;
|
||||||
if (my_rank == 0) {
|
break;
|
||||||
printf("%i\n", recv);
|
case 'o':
|
||||||
}
|
oparg = optarg[0];
|
||||||
/* shut down MPI */
|
break;
|
||||||
MPI_Finalize();
|
default:
|
||||||
|
usage();
|
||||||
return 0;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= argc) {
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = atoi(argv[optind]);
|
||||||
|
MPI_Op op;
|
||||||
|
|
||||||
|
switch (oparg) {
|
||||||
|
case '0':
|
||||||
|
op = MPI_MAX;
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
op = MPI_MIN;
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
op = MPI_SUM;
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
op = MPI_PROD;
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
op = MPI_LAND;
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
op = MPI_BAND;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
op = MPI_LOR;
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
op = MPI_BOR;
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
op = MPI_LXOR;
|
||||||
|
break;
|
||||||
|
case '9':
|
||||||
|
op = MPI_BXOR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *a;
|
||||||
|
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &a);
|
||||||
|
//fill(a, size, sizeof(int));
|
||||||
|
|
||||||
|
if (benchmark) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
int *red;
|
||||||
|
int *rfib;
|
||||||
|
int *rbin;
|
||||||
|
int *rbinom;
|
||||||
|
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &red);
|
||||||
|
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rfib);
|
||||||
|
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rbin);
|
||||||
|
MPI_Alloc_mem(size * sizeof(int), MPI_INFO_NULL, &rbinom);
|
||||||
|
|
||||||
|
MPI_Reduce(a, red, size, MPI_INT, op, 0, MPI_COMM_WORLD);
|
||||||
|
Fib_Reduce(a, rfib, size, MPI_INT, op, 0, MPI_COMM_WORLD);
|
||||||
|
Bin_Reduce(a, rbin, size, MPI_INT, op, 0, MPI_COMM_WORLD);
|
||||||
|
Binom_Reduce(a, rbinom, size, MPI_INT, op, 0, MPI_COMM_WORLD);
|
||||||
|
|
||||||
|
if (r == 0) {
|
||||||
|
if (memcmp(red, rfib, size * sizeof(int))) {
|
||||||
|
printf("Fib_Reduce does not match\n");
|
||||||
|
}
|
||||||
|
if (memcmp(red, rbin, size * sizeof(int))) {
|
||||||
|
printf("Bin_Reduce does not match\n");
|
||||||
|
}
|
||||||
|
if (memcmp(red, rbinom, size * sizeof(int))) {
|
||||||
|
printf("Binom_Reduce does not match\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("All checks done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Free_mem(red);
|
||||||
|
MPI_Free_mem(rfib);
|
||||||
|
MPI_Free_mem(rbin);
|
||||||
|
MPI_Free_mem(rbinom);
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Free_mem(a);
|
||||||
|
|
||||||
|
MPI_Finalize();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue