Commit 93704077 authored by iker_martin's avatar iker_martin
Browse files

Arreglado error al utilizar multiples fases - La distribucion en las fases de...

Arreglado error al utilizar multiples fases - La distribucion en las fases de iter tiene que ser modificada para tener en cuenta versiones de comunicacion V
parent 8a9e883d
......@@ -11,7 +11,7 @@ void malloc_config_resizes(configuration *user_config, int resizes);
void init_config_stages(configuration *user_config, int stages);
void def_struct_config_file(configuration *config_file, MPI_Datatype *config_type);
void def_struct_config_file_array(configuration *config_file, MPI_Datatype *config_type);
void def_struct_iter_stage(iter_stage_t *iter_stage, MPI_Datatype *config_type);
void def_struct_iter_stage(iter_stage_t *iter_stage, int stages, MPI_Datatype *config_type);
/*
* Funcion utilizada para leer el fichero de configuracion
......@@ -42,8 +42,6 @@ static int handler(void* user, const char* section, const char* name,
init_config_stages(pconfig, pconfig->iter_stages);
} else if (MATCH("general", "matrix_tam")) {
pconfig->matrix_tam = atoi(value);
} else if (MATCH("general", "comm_tam")) {
pconfig->comm_tam = atoi(value);
} else if (MATCH("general", "SDR")) {
pconfig->sdr = atoi(value);
} else if (MATCH("general", "ADR")) {
......@@ -154,6 +152,7 @@ void init_config_stages(configuration *user_config, int stages) {
user_config->iter_stage[i].array = NULL;
user_config->iter_stage[i].full_array = NULL;
user_config->iter_stage[i].double_array = NULL;
user_config->iter_stage[i].real_bytes = 0;
}
}
}
......@@ -168,19 +167,23 @@ void free_config(configuration *user_config) {
free(user_config->procs);
free(user_config->factors);
free(user_config->phy_dist);
for(i=0; i < user_config->iter_stages; i++) {
if(user_config->iter_stage[i].array != NULL)
if(user_config->iter_stage[i].array != NULL) {
free(user_config->iter_stage[i].array);
user_config->iter_stage[i].array = NULL;
if(user_config->iter_stage[i].full_array != NULL)
}
if(user_config->iter_stage[i].full_array != NULL) {
free(user_config->iter_stage[i].full_array);
user_config->iter_stage[i].full_array = NULL;
if(user_config->iter_stage[i].double_array != NULL)
}
if(user_config->iter_stage[i].double_array != NULL) {
free(user_config->iter_stage[i].double_array);
user_config->iter_stage[i].double_array = NULL;
}
}
free(user_config->iter_stage);
//free(user_config->iter_stage); //FIXME ERROR de memoria relacionado con la carpeta malleability
free(user_config);
}
......@@ -193,11 +196,11 @@ void free_config(configuration *user_config) {
void print_config(configuration *user_config, int grp) {
if(user_config != NULL) {
int i;
printf("Config loaded: resizes=%d, stages=%d, matrix=%d, comm_tam=%d, sdr=%d, adr=%d, aib=%d, css=%d, cst=%d || grp=%d\n",
user_config->resizes, user_config->iter_stages, user_config->matrix_tam, user_config->comm_tam, user_config->sdr, user_config->adr, user_config->aib, user_config->css, user_config->cst, grp);
printf("Config loaded: resizes=%d, stages=%d, matrix=%d, sdr=%d, adr=%d, aib=%d, css=%d, cst=%d || grp=%d\n",
user_config->resizes, user_config->iter_stages, user_config->matrix_tam, user_config->sdr, user_config->adr, user_config->aib, user_config->css, user_config->cst, grp);
for(i=0; i<user_config->iter_stages; i++) {
printf("Stage %d: PT=%d, T_stage=%lf, bytes=%d\n",
i, user_config->iter_stage[i].pt, user_config->iter_stage[i].t_stage, user_config->iter_stage[i].bytes);
i, user_config->iter_stage[i].pt, user_config->iter_stage[i].t_stage, user_config->iter_stage[i].real_bytes);
}
for(i=0; i<user_config->resizes; i++) {
printf("Resize %d: Iters=%d, Procs=%d, Factors=%f, Phy=%d\n",
......@@ -223,11 +226,11 @@ void print_config_group(configuration *user_config, int grp) {
sons = user_config->procs[grp+1];
}
printf("Config: matrix=%d, comm_tam=%d, sdr=%d, adr=%d, aib=%d, css=%d, cst=%d\n",
user_config->matrix_tam, user_config->comm_tam, user_config->sdr, user_config->adr, user_config->aib, user_config->css, user_config->cst);
printf("Config: matrix=%d, sdr=%d, adr=%d, aib=%d, css=%d, cst=%d\n",
user_config->matrix_tam, user_config->sdr, user_config->adr, user_config->aib, user_config->css, user_config->cst);
for(i=0; i<user_config->iter_stages; i++) {
printf("Stage %d: PT=%d, T_stage=%lf, bytes=%d\n",
i, user_config->iter_stage[i].pt, user_config->iter_stage[i].t_stage, user_config->iter_stage[i].bytes);
i, user_config->iter_stage[i].pt, user_config->iter_stage[i].t_stage, user_config->iter_stage[i].real_bytes);
}
printf("Config Group: iters=%d, factor=%f, phy=%d, procs=%d, parents=%d, sons=%d\n",
user_config->iters[grp], user_config->factors[grp], user_config->phy_dist[grp], user_config->procs[grp], parents, sons);
......@@ -263,7 +266,7 @@ void send_config_file(configuration *config_file, int root, MPI_Comm intercomm)
// Obtener un tipo derivado para enviar las estructuras de fases de iteracion
// con una sola comunicacion
def_struct_iter_stage(&(config_file->iter_stage[0]), &iter_stage_type);
def_struct_iter_stage(&(config_file->iter_stage[0]), config_file->iter_stages, &iter_stage_type);
MPI_Bcast(config_file, 1, config_type, root, intercomm);
MPI_Bcast(config_file, 1, config_type_array, root, intercomm);
......@@ -306,7 +309,7 @@ void recv_config_file(int root, MPI_Comm intercomm, configuration **config_file_
// Obtener un tipo derivado para enviar los tres vectores
// de enteros con una sola comunicacion
def_struct_config_file_array(config_file, &config_type_array);
def_struct_iter_stage(&(config_file->iter_stage[0]), &iter_stage_type);
def_struct_iter_stage(&(config_file->iter_stage[0]), config_file->iter_stages, &iter_stage_type);
MPI_Bcast(config_file, 1, config_type_array, root, intercomm);
MPI_Bcast(config_file->factors, config_file->resizes, MPI_FLOAT, root, intercomm);
......@@ -322,18 +325,18 @@ void recv_config_file(int root, MPI_Comm intercomm, configuration **config_file_
}
/*
* Tipo derivado para enviar 12 elementos especificos
* Tipo derivado para enviar 11 elementos especificos
* de la estructura de configuracion con una sola comunicacion.
*/
void def_struct_config_file(configuration *config_file, MPI_Datatype *config_type) {
int i, counts = 12;
int blocklengths[12] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int i, counts = 11;
int blocklengths[11] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
MPI_Aint displs[counts], dir;
MPI_Datatype types[counts];
// Rellenar vector types
types[0] = types[1] = types[2] = types[3] = types[4] = types[5] = types[6] = types[7] = types[8] = types[9] = MPI_INT;
types[10] = types[11] = MPI_DOUBLE;
types[0] = types[1] = types[2] = types[3] = types[4] = types[5] = types[6] = types[7] = types[8] = MPI_INT;
types[9] = types[10] = MPI_DOUBLE;
// Rellenar vector displs
MPI_Get_address(config_file, &dir);
......@@ -342,14 +345,13 @@ void def_struct_config_file(configuration *config_file, MPI_Datatype *config_typ
MPI_Get_address(&(config_file->iter_stages), &displs[1]);
MPI_Get_address(&(config_file->actual_resize), &displs[2]);
MPI_Get_address(&(config_file->matrix_tam), &displs[3]);
MPI_Get_address(&(config_file->comm_tam), &displs[4]);
MPI_Get_address(&(config_file->sdr), &displs[5]);
MPI_Get_address(&(config_file->adr), &displs[6]);
MPI_Get_address(&(config_file->aib), &displs[7]);
MPI_Get_address(&(config_file->css), &displs[8]);
MPI_Get_address(&(config_file->cst), &displs[9]);
MPI_Get_address(&(config_file->latency_m), &displs[10]);
MPI_Get_address(&(config_file->bw_m), &displs[11]);
MPI_Get_address(&(config_file->sdr), &displs[4]);
MPI_Get_address(&(config_file->adr), &displs[5]);
MPI_Get_address(&(config_file->aib), &displs[6]);
MPI_Get_address(&(config_file->css), &displs[7]);
MPI_Get_address(&(config_file->cst), &displs[8]);
MPI_Get_address(&(config_file->latency_m), &displs[9]);
MPI_Get_address(&(config_file->bw_m), &displs[10]);
for(i=0;i<counts;i++) displs[i] -= dir;
......@@ -394,16 +396,16 @@ void def_struct_config_file_array(configuration *config_file, MPI_Datatype *conf
* Tipo derivado para enviar elementos especificos
* de la estructuras de fases de iteracion en una sola comunicacion.
*/
void def_struct_iter_stage(iter_stage_t *iter_stage, MPI_Datatype *config_type) {
void def_struct_iter_stage(iter_stage_t *iter_stage, int stages, MPI_Datatype *config_type) {
int i, counts = 4;
int blocklengths[4] = {1, 1, 1, 1};
MPI_Aint displs[counts], dir;
MPI_Datatype types[counts];
MPI_Datatype aux, types[counts];
// Rellenar vector types
types[0] = MPI_INT;
types[0] = types[3] = MPI_INT;
types[1] = MPI_FLOAT;
types[2] = types[3] = MPI_DOUBLE;
types[2] = MPI_DOUBLE;
// Rellenar vector displs
MPI_Get_address(iter_stage, &dir);
......@@ -415,6 +417,12 @@ void def_struct_iter_stage(iter_stage_t *iter_stage, MPI_Datatype *config_type)
for(i=0;i<counts;i++) displs[i] -= dir;
MPI_Type_create_struct(counts, blocklengths, displs, types, config_type);
if (stages == 1) {
MPI_Type_create_struct(counts, blocklengths, displs, types, config_type);
} else { // Si hay mas de una fase(estructura), el "extent" se modifica.
MPI_Type_create_struct(counts, blocklengths, displs, types, &aux);
// Tipo derivado para enviar N elementos de la estructura
MPI_Type_create_resized(aux, 0, 1*sizeof(iter_stage_t), config_type);
}
MPI_Type_commit(config_type);
}
......@@ -10,7 +10,7 @@ typedef struct
double t_op;
int operations;
int bytes, bytes_real;
int bytes, real_bytes;
char* array, *full_array;
double* double_array;
......@@ -20,7 +20,7 @@ typedef struct
{
int resizes, iter_stages;
int actual_resize, actual_iter;
int matrix_tam, comm_tam, sdr, adr;
int matrix_tam, sdr, adr;
int css, cst;
int aib;
double latency_m, bw_m;
......
......@@ -217,7 +217,6 @@ void init_results_data(results_data *results, int resizes, int iters_size) {
void realloc_results_iters(results_data *results, int needed) {
double *time_aux;
time_aux = (double *) realloc(results->iters_time, needed * sizeof(double));
if(time_aux == NULL) {
......
......@@ -111,6 +111,7 @@ int main(int argc, char *argv[]) {
group->grp = group->grp + 1;
obtain_op_times(0); //Obtener los nuevos valores de tiempo para el computo
print_config(config_file, group->grp);
set_benchmark_grp(group->grp);
get_malleability_user_comm(&comm);
MPI_Comm_size(comm, &(group->numP));
......
......@@ -8,6 +8,9 @@
#include "process_stage.h"
#include "../malleability/malleabilityManager.h" //FIXME Refactor
void get_byte_dist(int qty, int id, int numP, int *result);
/*
* Calcula el tiempo por operacion o total de bytes a enviar
* de cada fase de iteración para despues realizar correctamente
......@@ -23,6 +26,7 @@
* la bandera.
*
* TODO Que el trabajo se divida entre los procesos.
* TODO No tiene en cuenta cambios entre maquinas heterogeneas.
*/
void init_stage(void *config_file_void, int stage, void *group_void, MPI_Comm comm, int compute) {
double result, start_time, t_stage;
......@@ -33,13 +37,12 @@ void init_stage(void *config_file_void, int stage, void *group_void, MPI_Comm co
config_file.iter_stage[stage].operations = qty;
t_stage = config_file.iter_stage[stage].t_stage * config_file.factors[group.grp];
if(config_file.iter_stage[stage].bytes == 0) {
config_file.iter_stage[stage].bytes = (t_stage - config_file.latency_m) * config_file.bw_m;
} else {
//config_file.iter_stage[stage].bytes = config_file.iter_stage[stage].bytes;
config_file.iter_stage[stage].bytes = (config_file.iter_stage[stage].t_stage - config_file.latency_m) * config_file.bw_m;
}
get_byte_dist(config_file.iter_stage[stage].bytes, group.myId, group.numP, &(config_file.iter_stage[stage].real_bytes) );
start_time = MPI_Wtime();
result = 0;
switch(config_file.iter_stage[stage].pt) {
......@@ -55,29 +58,30 @@ void init_stage(void *config_file_void, int stage, void *group_void, MPI_Comm co
case COMP_POINT:
if(config_file.iter_stage[stage].array != NULL)
free(config_file.iter_stage[stage].array);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].real_bytes);
break;
case COMP_BCAST:
if(config_file.iter_stage[stage].array != NULL)
free(config_file.iter_stage[stage].array);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
config_file.iter_stage[stage].real_bytes = config_file.iter_stage[stage].bytes; // Caso especial al usar Bcast
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].real_bytes);
break;
case COMP_ALLTOALL:
case COMP_ALLTOALL: //FIXME Utilizar version V
if(config_file.iter_stage[stage].array != NULL)
free(config_file.iter_stage[stage].array);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].real_bytes);
if(config_file.iter_stage[stage].full_array != NULL)
free(config_file.iter_stage[stage].full_array);
config_file.iter_stage[stage].full_array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes * group.numP);
config_file.iter_stage[stage].full_array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
break;
case COMP_REDUCE:
case COMP_REDUCE: //FIXME Utilizar version V
if(config_file.iter_stage[stage].array != NULL)
free(config_file.iter_stage[stage].array);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
config_file.iter_stage[stage].array = malloc(sizeof(char) * config_file.iter_stage[stage].real_bytes);
//Full array para el reduce necesita el mismo tamanyo
if(config_file.iter_stage[stage].full_array != NULL)
free(config_file.iter_stage[stage].full_array);
config_file.iter_stage[stage].full_array = malloc(sizeof(char) * config_file.iter_stage[stage].bytes);
config_file.iter_stage[stage].full_array = malloc(sizeof(char) * config_file.iter_stage[stage].real_bytes);
break;
}
if(compute) {
......@@ -113,16 +117,16 @@ double process_stage(void *config_file_void, int stage, void *group_void, MPI_Co
break;
//Comunicaciones
case COMP_POINT:
point_to_point(group.myId, group.numP, ROOT, comm, stage_data.array, stage_data.bytes);
point_to_point(group.myId, group.numP, ROOT, comm, stage_data.array, stage_data.real_bytes);
break;
case COMP_BCAST:
MPI_Bcast(stage_data.array, stage_data.bytes, MPI_CHAR, ROOT, comm);
MPI_Bcast(stage_data.array, stage_data.real_bytes, MPI_CHAR, ROOT, comm);
break;
case COMP_ALLTOALL:
MPI_Alltoall(stage_data.array, stage_data.bytes, MPI_CHAR, stage_data.full_array, stage_data.bytes, MPI_CHAR, comm);
MPI_Alltoall(stage_data.array, stage_data.real_bytes, MPI_CHAR, stage_data.full_array, stage_data.real_bytes, MPI_CHAR, comm);
break;
case COMP_REDUCE:
MPI_Reduce(stage_data.array, stage_data.full_array, stage_data.bytes, MPI_CHAR, MPI_MAX, ROOT, comm);
MPI_Reduce(stage_data.array, stage_data.full_array, stage_data.real_bytes, MPI_CHAR, MPI_MAX, ROOT, comm);
break;
}
return result;
......@@ -213,3 +217,36 @@ double bandwidth(int myId, int numP, MPI_Comm comm, double latency, int n) {
bw = ((double)n_bytes * 2) / max_time;
return bw;
}
/*
* Obatains for "Id" and "numP", how many
* bytes will have process "Id" and returns
* that quantity.
*
* TODO Refactor: Ya existe esta funcion en malleability/CommDist.c
*/
void get_byte_dist(int qty, int id, int numP, int *result) {
int rem, ini, fin, tamBl;
tamBl = qty / numP;
rem = qty % numP;
if(id < rem) { // First subgroup
ini = id * tamBl + id;
fin = (id+1) * tamBl + (id+1);
} else { // Second subgroup
ini = id * tamBl + rem;
fin = (id+1) * tamBl + rem;
}
if(fin > qty) {
fin = qty;
}
if(ini > fin) {
ini = fin;
}
*result= fin - ini;
}
......@@ -2,24 +2,27 @@
resizes=1
iter_stages=1
matrix_tam=100000
comm_tam=47192
SDR=0.0
ADR=0.0
AIB=0
CST=1
CST=3
CSS=0
time=0.006
; end [general]
[stage0]
PT=3
bytes=0
t_stage=0.05
t_stage=0.1
;end [stage0]
[stage1]
PT=3
bytes=0
t_stage=0.05
;end [stage0]
t_stage=0.01
;end [stage1]
[stage2]
PT=0
bytes=0
t_stage=0.2
;end [stage2]
[resize0]
iters=10
procs=4
......
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