Commit 1ce6e4dd authored by iker_martin's avatar iker_martin
Browse files

Hotfix in CommDist for Merge Shrink. Refactor in block distribution, removed...

Hotfix in CommDist for Merge Shrink. Refactor in block distribution, removed not needed variable, added error checking in alltoall and minor changes.
parent a4f071d2
...@@ -373,11 +373,12 @@ void async_point2point(char *send, char *recv, struct Counts s_counts, struct Co ...@@ -373,11 +373,12 @@ void async_point2point(char *send, char *recv, struct Counts s_counts, struct Co
* *
*/ */
void prepare_redistribution(int qty, int myId, int numP, int numO, int is_children_group, int is_intercomm, char **recv, struct Counts *s_counts, struct Counts *r_counts) { void prepare_redistribution(int qty, int myId, int numP, int numO, int is_children_group, int is_intercomm, char **recv, struct Counts *s_counts, struct Counts *r_counts) {
int init_struct = 1;
struct Dist_data dist_data; struct Dist_data dist_data;
if(is_children_group) { if(is_children_group) {
mallocCounts(s_counts, numO); mallocCounts(s_counts, numO);
prepare_comm_alltoall(myId, numP, numO, qty, r_counts); prepare_comm_alltoall(myId, numP, numO, qty, init_struct, r_counts);
// Obtener distribución para este hijo // Obtener distribución para este hijo
get_block_dist(qty, myId, numP, &dist_data); get_block_dist(qty, myId, numP, &dist_data);
*recv = malloc(dist_data.tamBl * sizeof(char)); *recv = malloc(dist_data.tamBl * sizeof(char));
...@@ -385,19 +386,26 @@ void prepare_redistribution(int qty, int myId, int numP, int numO, int is_childr ...@@ -385,19 +386,26 @@ void prepare_redistribution(int qty, int myId, int numP, int numO, int is_childr
//print_counts(dist_data, r_counts->counts, r_counts->displs, numO, 0, "Children C "); //print_counts(dist_data, r_counts->counts, r_counts->displs, numO, 0, "Children C ");
} else { } else {
//get_block_dist(qty, myId, numP, &dist_data); //get_block_dist(qty, myId, numP, &dist_data);
prepare_comm_alltoall(myId, numP, numO, qty, s_counts);
if(is_intercomm) { if(is_intercomm) {
mallocCounts(r_counts, numO); mallocCounts(r_counts, numO);
prepare_comm_alltoall(myId, numP, numO, qty, init_struct, s_counts);
} else { } else {
if(myId < numO) { if(myId < numO) {
prepare_comm_alltoall(myId, numO, numP, qty, r_counts); prepare_comm_alltoall(myId, numO, numP, qty, init_struct, r_counts);
// Obtener distribución para este hijo // Obtener distribución para este hijo
get_block_dist(qty, myId, numO, &dist_data); get_block_dist(qty, myId, numO, &dist_data);
*recv = malloc(dist_data.tamBl * sizeof(char)); *recv = malloc(dist_data.tamBl * sizeof(char));
} else { } else {
mallocCounts(r_counts, numP); mallocCounts(r_counts, numP);
} }
if(numP > numO) { // Shrink
mallocCounts(s_counts, numP);
init_struct = 0;
}
prepare_comm_alltoall(myId, numP, numO, qty, init_struct, s_counts);
//print_counts(dist_data, r_counts->counts, r_counts->displs, numP, 0, "Children P "); //print_counts(dist_data, r_counts->counts, r_counts->displs, numP, 0, "Children P ");
} }
//print_counts(dist_data, s_counts->counts, s_counts->displs, numO, 0, "Parents "); //print_counts(dist_data, s_counts->counts, s_counts->displs, numO, 0, "Parents ");
......
...@@ -13,11 +13,11 @@ void get_util_ids(struct Dist_data dist_data, int numP_other, int **idS); ...@@ -13,11 +13,11 @@ void get_util_ids(struct Dist_data dist_data, int numP_other, int **idS);
* *
* The struct should be freed with freeCounts * The struct should be freed with freeCounts
*/ */
void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, struct Counts *counts) { void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, int init_struct, struct Counts *counts) {
int i, *idS; int i, *idS;
struct Dist_data dist_data, dist_target; struct Dist_data dist_data, dist_target;
mallocCounts(counts, numP_other); if(init_struct) mallocCounts(counts, numP_other);
get_block_dist(n, myId, numP, &dist_data); get_block_dist(n, myId, numP, &dist_data);
get_util_ids(dist_data, numP_other, &idS); get_util_ids(dist_data, numP_other, &idS);
...@@ -36,6 +36,17 @@ void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, struct Cou ...@@ -36,6 +36,17 @@ void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, struct Cou
counts->displs[i] = counts->displs[i-1] + counts->counts[i-1]; counts->displs[i] = counts->displs[i-1] + counts->counts[i-1];
} }
free(idS); free(idS);
for(i=0; i<numP_other; i++) {
if(counts->counts[i] < 0) {
fprintf(stderr, "Counts value [i=%d] is negative for rank %d/%d", i, myId, numP);
MPI_Abort(MPI_COMM_WORLD, -3);
}
if(counts->displs[i] < 0) {
fprintf(stderr, "Displs value [i=%d] is negative for rank %d/%d", i, myId, numP);
MPI_Abort(MPI_COMM_WORLD, -3);
}
}
} }
/* /*
...@@ -191,19 +202,15 @@ void get_util_ids(struct Dist_data dist_data, int numP_other, int **idS) { ...@@ -191,19 +202,15 @@ void get_util_ids(struct Dist_data dist_data, int numP_other, int **idS) {
* El vector displs indica los desplazamientos necesarios para cada comunicacion * El vector displs indica los desplazamientos necesarios para cada comunicacion
* con el proceso "i" del otro grupo. * con el proceso "i" del otro grupo.
* *
* El vector zero_arr se utiliza cuando se quiere indicar un vector incializado
* a 0 en todos sus elementos. Sirve para indicar que no hay comunicacion.
*/ */
void mallocCounts(struct Counts *counts, size_t numP) { void mallocCounts(struct Counts *counts, size_t numP) {
counts->counts = calloc(numP, sizeof(int)); counts->counts = calloc(numP, sizeof(int));
if(counts->counts == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);} if(counts->counts == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);}
counts->displs = calloc(numP, sizeof(int)); counts->displs = calloc(numP, sizeof(int));
if(counts->displs == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);} if(counts->displs == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);}
counts->zero_arr = calloc(numP, sizeof(int)); // TODO Deprecate
if(counts->zero_arr == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);} // TODO Deprecate
counts->len = numP; counts->len = numP;
counts->idI = -1; counts->idI = -1;
counts->idE = -1; counts->idE = -1;
...@@ -218,7 +225,10 @@ void mallocCounts(struct Counts *counts, size_t numP) { ...@@ -218,7 +225,10 @@ void mallocCounts(struct Counts *counts, size_t numP) {
* de forma dinamica. * de forma dinamica.
*/ */
void freeCounts(struct Counts *counts) { void freeCounts(struct Counts *counts) {
if(counts != NULL) { if(counts == NULL) {
return;
}
if(counts->counts != NULL) { if(counts->counts != NULL) {
free(counts->counts); free(counts->counts);
counts->counts = NULL; counts->counts = NULL;
...@@ -227,11 +237,6 @@ void freeCounts(struct Counts *counts) { ...@@ -227,11 +237,6 @@ void freeCounts(struct Counts *counts) {
free(counts->displs); free(counts->displs);
counts->displs = NULL; counts->displs = NULL;
} }
if(counts->zero_arr != NULL) {
free(counts->zero_arr);
counts->zero_arr = NULL;
}
}
} }
/* /*
......
...@@ -22,10 +22,9 @@ struct Counts { ...@@ -22,10 +22,9 @@ struct Counts {
int first_target_displs; // RMA. Indicates displacement for first target when performing a Get. int first_target_displs; // RMA. Indicates displacement for first target when performing a Get.
int *counts; int *counts;
int *displs; int *displs;
int *zero_arr;
}; };
void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, struct Counts *counts); void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, int init_struct, struct Counts *counts);
void prepare_comm_allgatherv(int numP, int n, struct Counts *counts); void prepare_comm_allgatherv(int numP, int n, struct Counts *counts);
void get_block_dist(int qty, int id, int numP, struct Dist_data *dist_data); void get_block_dist(int qty, int id, int numP, struct Dist_data *dist_data);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment