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
*
*/
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;
if(is_children_group) {
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
get_block_dist(qty, myId, numP, &dist_data);
*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
//print_counts(dist_data, r_counts->counts, r_counts->displs, numO, 0, "Children C ");
} else {
//get_block_dist(qty, myId, numP, &dist_data);
prepare_comm_alltoall(myId, numP, numO, qty, s_counts);
if(is_intercomm) {
mallocCounts(r_counts, numO);
prepare_comm_alltoall(myId, numP, numO, qty, init_struct, s_counts);
} else {
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
get_block_dist(qty, myId, numO, &dist_data);
*recv = malloc(dist_data.tamBl * sizeof(char));
} else {
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, 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);
*
* 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;
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_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
counts->displs[i] = counts->displs[i-1] + counts->counts[i-1];
}
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) {
* El vector displs indica los desplazamientos necesarios para cada comunicacion
* 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) {
counts->counts = calloc(numP, sizeof(int));
if(counts->counts == NULL) { MPI_Abort(MPI_COMM_WORLD, -2);}
counts->displs = calloc(numP, sizeof(int));
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->idI = -1;
counts->idE = -1;
......@@ -218,19 +225,17 @@ void mallocCounts(struct Counts *counts, size_t numP) {
* de forma dinamica.
*/
void freeCounts(struct Counts *counts) {
if(counts != NULL) {
if(counts->counts != NULL) {
free(counts->counts);
counts->counts = NULL;
}
if(counts->displs != NULL) {
free(counts->displs);
counts->displs = NULL;
}
if(counts->zero_arr != NULL) {
free(counts->zero_arr);
counts->zero_arr = NULL;
}
if(counts == NULL) {
return;
}
if(counts->counts != NULL) {
free(counts->counts);
counts->counts = NULL;
}
if(counts->displs != NULL) {
free(counts->displs);
counts->displs = NULL;
}
}
......
......@@ -22,10 +22,9 @@ struct Counts {
int first_target_displs; // RMA. Indicates displacement for first target when performing a Get.
int *counts;
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 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