Commit ea63dfcb authored by iker_martin's avatar iker_martin
Browse files

Bugfix in realloc for results, where children had not the correct amount of...

Bugfix in realloc for results, where children had not the correct amount of iterations. Another fix for stage time storage.
parent 9ffb1755
...@@ -163,15 +163,15 @@ void compute_results_stages(results_data *results, int myId, int numP, int root, ...@@ -163,15 +163,15 @@ void compute_results_stages(results_data *results, int myId, int numP, int root,
int i; int i;
if(myId == root) { if(myId == root) {
for(i=0; i<stages; i++) { for(i=0; i<stages; i++) {
MPI_Reduce(MPI_IN_PLACE, results->stage_times[i], results->iter_index, MPI_DOUBLE, MPI_SUM, root, comm); MPI_Reduce(MPI_IN_PLACE, results->stage_times[i], results->iter_index, MPI_DOUBLE, MPI_MAX, root, comm);
for(size_t j=0; j<results->iter_index; j++) { /* for(size_t j=0; j<results->iter_index; j++) {
results->stage_times[i][j] = results->stage_times[i][j] / numP; results->stage_times[i][j] = results->stage_times[i][j] / numP;
} }*/
} }
} }
else { else {
for(i=0; i<stages; i++) { for(i=0; i<stages; i++) {
MPI_Reduce(results->stage_times[i], NULL, results->iter_index, MPI_DOUBLE, MPI_SUM, root, comm); MPI_Reduce(results->stage_times[i], NULL, results->iter_index, MPI_DOUBLE, MPI_MAX, root, comm);
} }
} }
} }
...@@ -281,20 +281,24 @@ void realloc_results_iters(results_data *results, size_t stages, size_t needed) ...@@ -281,20 +281,24 @@ void realloc_results_iters(results_data *results, size_t stages, size_t needed)
int error = 0; int error = 0;
double *time_aux; double *time_aux;
size_t i; size_t i;
if(results->iters_size >= needed) return;
time_aux = (double *) realloc(results->iters_time, needed * sizeof(double)); time_aux = (double *) realloc(results->iters_time, needed * sizeof(double));
if(time_aux == NULL) error = 1;
for(i=0; i<stages; i++) { //TODO Comprobar que no da error el realloc for(i=0; i<stages; i++) { //TODO Comprobar que no da error el realloc
results->stage_times[i] = (double *) realloc(results->stage_times[i], needed * sizeof(double)); results->stage_times[i] = (double *) realloc(results->stage_times[i], needed * sizeof(double));
if(results->stage_times[i] == NULL) error = 1; if(results->stage_times[i] == NULL) error = 1;
} }
if(time_aux == NULL) error = 1;
if(error) { if(error) {
fprintf(stderr, "Fatal error - No se ha podido realojar la memoria de resultados\n"); fprintf(stderr, "Fatal error - No se ha podido realojar la memoria de resultados\n");
MPI_Abort(MPI_COMM_WORLD, 1); MPI_Abort(MPI_COMM_WORLD, 1);
} }
results->iters_time = time_aux; results->iters_time = time_aux;
results->iters_size = needed;
} }
/* /*
......
...@@ -127,6 +127,7 @@ int main(int argc, char *argv[]) { ...@@ -127,6 +127,7 @@ int main(int argc, char *argv[]) {
} }
group->grp = group->grp + 1; group->grp = group->grp + 1;
realloc_results_iters(results, config_file->n_stages, config_file->groups[group->grp].iters);
} }
// //
...@@ -264,6 +265,7 @@ double iterate(int async_comm) { ...@@ -264,6 +265,7 @@ double iterate(int async_comm) {
results->iters_async += 1; results->iters_async += 1;
} }
// TODO Pasar el resto de este código a results.c
if(results->iter_index == results->iters_size) { // Aumentar tamaño de ambos vectores de resultados if(results->iter_index == results->iters_size) { // Aumentar tamaño de ambos vectores de resultados
realloc_results_iters(results, config_file->n_stages, results->iters_size + 100); realloc_results_iters(results, config_file->n_stages, results->iters_size + 100);
} }
...@@ -272,6 +274,7 @@ double iterate(int async_comm) { ...@@ -272,6 +274,7 @@ double iterate(int async_comm) {
results->stage_times[i][results->iter_index] = times_stages_aux[i]; results->stage_times[i][results->iter_index] = times_stages_aux[i];
} }
results->iter_index = results->iter_index + 1; results->iter_index = results->iter_index + 1;
// TODO Pasar hasta aqui
free(times_stages_aux); free(times_stages_aux);
......
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