Commit 3d004461 authored by iker_martin's avatar iker_martin
Browse files

WIP. Refactoring. Ahora se ha separado completamente la logica de la...

WIP. Refactoring. Ahora se ha separado completamente la logica de la maleabilidad de la aplicación sintética
parent 24c93265
......@@ -129,7 +129,7 @@ void free_config(configuration *user_config) {
}
}
/* TODO Añadir COMMTAM
/*
* Imprime por salida estandar toda la informacion que contiene
* la configuracion pasada como argumento
*/
......
......@@ -11,7 +11,7 @@ void def_results_type(results_data *results, int resizes, MPI_Datatype *results_
//======================================================||
//======================================================||
//TODO Generalizar ambas funciones en una sola
/*
* Envia una estructura de resultados al grupo de procesos al que se
* enlaza este grupo a traves del intercomunicador pasado como argumento.
......@@ -57,7 +57,7 @@ void recv_results(results_data *results, int root, int resizes, MPI_Comm interco
* Define un tipo derivado de MPI para mandar los tiempos
* con una sola comunicacion.
*
* En concreto son tres escales y un vector de tamaño "resizes"
* En concreto son tres escalares y dos vectores de tamaño "resizes"
*/
void def_results_type(results_data *results, int resizes, MPI_Datatype *results_type) {
int i, counts = 5;
......@@ -83,6 +83,30 @@ void def_results_type(results_data *results, int resizes, MPI_Datatype *results_
MPI_Type_create_struct(counts, blocklengths, displs, types, results_type);
MPI_Type_commit(results_type);
}
//======================================================||
//======================================================||
//================SET RESULTS FUNCTIONS=================||
//======================================================||
//======================================================||
/*
* Guarda los resultados respecto a la redistribución de datos
* tras una reconfiguración. A llamar por los hijos tras
* terminar la redistribución y obtener la configuración.
*/
void set_results_post_reconfig(results_data *results, int grp, int sdr, int adr) {
if(sdr) { // Si no hay datos sincronos, el tiempo es 0
results->sync_time[grp] = results->sync_end - results->sync_start;
} else {
results->sync_time[grp] = 0;
}
if(adr) { // Si no hay datos asincronos, el tiempo es 0
results->async_time[grp] = results->async_end - results->async_start;
} else {
results->async_time[grp] = 0;
}
}
//======================================================||
//======================================================||
......@@ -96,22 +120,22 @@ void def_results_type(results_data *results, int resizes, MPI_Datatype *results_
* por iteracion, el tipo (Normal o durante communicacion asincrona)
* y cuantas operaciones internas se han realizado en cada iteracion.
*/
void print_iter_results(results_data *results, int last_normal_iter_index) {
void print_iter_results(results_data results, int last_normal_iter_index) {
int i, aux;
printf("Titer: ");
for(i=0; i< results->iter_index; i++) {
printf("%lf ", results->iters_time[i]);
for(i=0; i< results.iter_index; i++) {
printf("%lf ", results.iters_time[i]);
}
printf("\nTtype: "); //FIXME modificar a imprimir solo la cantidad de asincronas
for(i=0; i< results->iter_index; i++) {
printf("%d ", results->iters_type[i] == 0);
for(i=0; i< results.iter_index; i++) {
printf("%d ", results.iters_type[i] == 0);
}
printf("\nTop: "); //TODO modificar a imprimir solo cuantas operaciones cuestan una iteracion?
for(i=0; i< results->iter_index; i++) {
aux = results->iters_type[i] == 0 ? results->iters_type[last_normal_iter_index] : results->iters_type[i];
for(i=0; i< results.iter_index; i++) {
aux = results.iters_type[i] == 0 ? results.iters_type[last_normal_iter_index] : results.iters_type[i];
printf("%d ", aux);
}
printf("\n");
......@@ -122,30 +146,30 @@ void print_iter_results(results_data *results, int last_normal_iter_index) {
* Estos son el tiempo de creacion de procesos, los de comunicacion
* asincrona y sincrona y el tiempo total de ejecucion.
*/
void print_global_results(results_data *results, int resizes) {
void print_global_results(results_data results, int resizes) {
int i;
printf("Tspawn: ");
for(i=0; i< resizes - 1; i++) {
printf("%lf ", results->spawn_time[i]);
printf("%lf ", results.spawn_time[i]);
}
printf("\nTthread: ");
for(i=0; i< resizes - 1; i++) {
printf("%lf ", results->spawn_thread_time[i]);
printf("%lf ", results.spawn_thread_time[i]);
}
printf("\nTsync: ");
for(i=1; i < resizes; i++) {
printf("%lf ", results->sync_time[i]);
printf("%lf ", results.sync_time[i]);
}
printf("\nTasync: ");
for(i=1; i < resizes; i++) {
printf("%lf ", results->async_time[i]);
printf("%lf ", results.async_time[i]);
}
printf("\nTex: %lf\n", results->exec_time);
printf("\nTex: %lf\n", results.exec_time);
}
//======================================================||
......@@ -160,18 +184,18 @@ void print_global_results(results_data *results, int resizes) {
* Los argumentos "resizes" y "iters_size" se necesitan para obtener el tamaño
* de los vectores de resultados.
*/
void init_results_data(results_data **results, int resizes, int iters_size) {
*results = malloc(1 * sizeof(results_data));
(*results)->spawn_time = calloc(resizes, sizeof(double));
(*results)->spawn_thread_time = calloc(resizes, sizeof(double));
(*results)->sync_time = calloc(resizes, sizeof(double));
(*results)->async_time = calloc(resizes, sizeof(double));
(*results)->iters_size = iters_size + 100;
(*results)->iters_time = calloc(iters_size + 100, sizeof(double)); //FIXME Numero magico
(*results)->iters_type = calloc(iters_size + 100, sizeof(int));
(*results)->iter_index = 0;
void init_results_data(results_data *results, int resizes, int iters_size) {
//*results = malloc(1 * sizeof(results_data)); FIXME Borrar
results->spawn_time = calloc(resizes, sizeof(double));
results->spawn_thread_time = calloc(resizes, sizeof(double));
results->sync_time = calloc(resizes, sizeof(double));
results->async_time = calloc(resizes, sizeof(double));
results->iters_size = iters_size + 100;
results->iters_time = calloc(iters_size + 100, sizeof(double)); //FIXME Numero magico
results->iters_type = calloc(iters_size + 100, sizeof(int));
results->iter_index = 0;
}
void realloc_results_iters(results_data *results, int needed) {
......@@ -193,13 +217,13 @@ void realloc_results_iters(results_data *results, int needed) {
/*
* Libera toda la memoria asociada con una estructura de resultados.
*/
void free_results_data(results_data **results) {
free((*results)->spawn_time);
free((*results)->spawn_thread_time);
free((*results)->sync_time);
free((*results)->async_time);
free((*results)->iters_time);
free((*results)->iters_type);
free(*results);
void free_results_data(results_data *results) {
free(results->spawn_time);
free(results->spawn_thread_time);
free(results->sync_time);
free(results->async_time);
free(results->iters_time);
free(results->iters_type);
//free(*results); FIXME Borrar
}
......@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <mpi.h>
#define RESULTS_INIT_DATA_QTY 100
typedef struct {
// Iters data
double *iters_time;
......@@ -9,8 +11,8 @@ typedef struct {
// Spawn, Thread, Sync, Async and Exec time
double spawn_start, *spawn_time, *spawn_thread_time;
double sync_start, *sync_time;
double async_start, *async_time;
double sync_start, sync_end, *sync_time;
double async_start, async_end, *async_time;
double exec_start, exec_time;
} results_data;
......@@ -18,8 +20,10 @@ typedef struct {
void send_results(results_data *results, int root, int resizes, MPI_Comm intercomm);
void recv_results(results_data *results, int root, int resizes, MPI_Comm intercomm);
void print_iter_results(results_data *results, int last_normal_iter_index);
void print_global_results(results_data *results, int resizes);
void init_results_data(results_data **results, int resizes, int iters_size);
void set_results_post_reconfig(results_data *results, int grp, int sdr, int adr);
void print_iter_results(results_data results, int last_normal_iter_index);
void print_global_results(results_data results, int resizes);
void init_results_data(results_data *results, int resizes, int iters_size);
void realloc_results_iters(results_data *results, int needed);
void free_results_data(results_data **results);
void free_results_data(results_data *results);
This diff is collapsed.
module load mpich-3.4.1-noucx
mpicc -Wall Main/Main.c Main/computing_func.c IOcodes/results.c IOcodes/read_ini.c IOcodes/ini.c malleability/ProcessDist.c malleability/CommDist.c -pthread -lslurm -lm
#mpicc -Wall Main/Main.c Main/computing_func.c IOcodes/results.c IOcodes/read_ini.c IOcodes/ini.c malleability/ProcessDist.c malleability/CommDist.c -pthread -lslurm -lm
mpicc -Wall Main/Main.c Main/computing_func.c IOcodes/results.c IOcodes/read_ini.c IOcodes/ini.c malleability/malleabilityManager.c malleability/malleabilityTypes.c malleability/ProcessDist.c malleability/CommDist.c -pthread -lslurm -lm
if [ $# -gt 0 ]
then
......
......@@ -181,7 +181,7 @@ void recv_sync_arrays(struct Dist_data dist_data, char *array, int root, int num
//================================================================================
//================================================================================
//========================ASINCHRONOUS FUNCTIONS==================================
//========================ASYNCHRONOUS FUNCTIONS==================================
//================================================================================
//================================================================================
......@@ -212,18 +212,18 @@ int send_async(char *array, int qty, int myId, int numP, int root, MPI_Comm inte
// MAL_USE_THREAD sigue el camino sincrono
if(parents_wait == MAL_USE_NORMAL) {
*comm_req = (MPI_Request *) malloc(sizeof(MPI_Request));
//*comm_req = (MPI_Request *) malloc(sizeof(MPI_Request));
*comm_req[0] = MPI_REQUEST_NULL;
send_async_arrays(dist_data, array, rootBcast, numP_child, idS[0], idS[1], counts, &(*comm_req[0]));
} else if (parents_wait == MAL_USE_IBARRIER){
*comm_req = (MPI_Request *) malloc(2 * sizeof(MPI_Request));
(*comm_req)[0] = MPI_REQUEST_NULL;
(*comm_req)[1] = MPI_REQUEST_NULL;
//*comm_req = (MPI_Request *) malloc(2 * sizeof(MPI_Request));
*comm_req[0] = MPI_REQUEST_NULL;
*comm_req[1] = MPI_REQUEST_NULL;
send_async_arrays(dist_data, array, rootBcast, numP_child, idS[0], idS[1], counts, &((*comm_req)[1]));
MPI_Ibarrier(intercomm, &((*comm_req)[0]) );
} else if (parents_wait == MAL_USE_POINT){
*comm_req = (MPI_Request *) malloc(numP_child * sizeof(MPI_Request));
//*comm_req = (MPI_Request *) malloc(numP_child * sizeof(MPI_Request));
for(i=0; i<numP_child; i++){
(*comm_req)[i] = MPI_REQUEST_NULL;
}
......
......@@ -2,15 +2,16 @@
#include <stdlib.h>
#include <mpi.h>
#include <string.h>
#include "malleabilityStates.h"
#define MAL_COMM_COMPLETED 0
#define MAL_COMM_UNINITIALIZED 2
#define MAL_ASYNC_PENDING 1
//#define MAL_COMM_COMPLETED 0
//#define MAL_COMM_UNINITIALIZED 2
//#define MAL_ASYNC_PENDING 1
#define MAL_USE_NORMAL 0
#define MAL_USE_IBARRIER 1
#define MAL_USE_POINT 2
#define MAL_USE_THREAD 3
//#define MAL_USE_NORMAL 0
//#define MAL_USE_IBARRIER 1
//#define MAL_USE_POINT 2
//#define MAL_USE_THREAD 3
int send_sync(char *array, int qty, int myId, int numP, int root, MPI_Comm intercomm, int numP_child);
void recv_sync(char **array, int qty, int myId, int numP, int root, MPI_Comm intercomm, int numP_parents);
......
......@@ -8,9 +8,7 @@
#include <slurm/slurm.h>
#include "ProcessDist.h"
#define ROOT 0
int commSlurm = COMM_UNRESERVED;
int commSlurm = MAL_NOT_STARTED;
struct Slurm_data *slurm_data;
pthread_t slurm_thread;
MPI_Comm *returned_comm;
......@@ -23,7 +21,7 @@ struct Slurm_data {
};
typedef struct {
char **argv;
char *argv;
int numP_childs, myId, root, type_dist;
MPI_Comm comm;
}Creation_data;
......@@ -33,21 +31,17 @@ typedef struct {
void* thread_work(void* creation_data_arg);
//--------------PRIVATE DECLARATIONS---------------//
void processes_dist(char *argv[], int numP_childs, int type_dist);
void processes_dist(char *argv, int numP_childs, int type_dist);
int create_processes(int myId, int root, MPI_Comm *child, MPI_Comm comm);
void node_dist(slurm_job_info_t job_record, int type, int total_procs, int **qty, int *used_nodes);
int create_hostfile(char *jobId, char **file_name);
int write_hostfile_node(int ptr, int qty, char *node_name);
void fill_hostfile(slurm_job_info_t job_record, int ptr, int *qty, int used_nodes);
//TESTS
void fill_str_hostfile(slurm_job_info_t job_record, int *qty, int used_nodes, char **hostfile_str);
int write_str_node(char **hostfile_str, int len_og, int qty, char *node_name);
//
void print_Info(MPI_Info info);
//@deprecated functions
int create_hostfile(char *jobId, char **file_name);
int write_hostfile_node(int ptr, int qty, char *node_name);
void fill_hostfile(slurm_job_info_t job_record, int ptr, int *qty, int used_nodes);
//--------------PUBLIC FUNCTIONS---------------//
......@@ -67,7 +61,7 @@ void print_Info(MPI_Info info);
* Devuelve el estado de el procedimiento. Si no devuelve "COMM_FINISHED", es necesario llamar a
* "check_slurm_comm()".
*/
int init_slurm_comm(char **argv, int myId, int numP, int root, int type_dist, int type_creation, MPI_Comm comm, MPI_Comm *child) {
int init_slurm_comm(char *argv, int myId, int numP, int root, int type_dist, int type_creation, MPI_Comm comm, MPI_Comm *child) {
slurm_data = malloc(sizeof(struct Slurm_data));
......@@ -88,10 +82,10 @@ int init_slurm_comm(char **argv, int myId, int numP, int root, int type_dist, in
free(slurm_data->cmd);
free(slurm_data);
commSlurm = COMM_FINISHED;
commSlurm = MAL_SPAWN_COMPLETED;
} else if(type_creation == COMM_SPAWN_PTHREAD) {
commSlurm = COMM_IN_PROGRESS;
commSlurm = MAL_SPAWN_PENDING;
Creation_data *creation_data = (Creation_data *) malloc(sizeof(Creation_data));
creation_data->argv = argv;
......@@ -120,30 +114,9 @@ int check_slurm_comm(int myId, int root, int numP, MPI_Comm *child) { // TODO Bo
if(slurm_data->type_creation == COMM_SPAWN_PTHREAD) {
//MPI_Allreduce(&commSlurm, &state, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
MPI_Allreduce(&commSlurm, &state, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
if(myId == root) {
int i, recv_state;
state = commSlurm;
for(i=0; i<numP; i++) { //Recv states
if(i != myId) {
MPI_Recv(&recv_state, 1, MPI_INT, i, 120, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
if(recv_state == COMM_IN_PROGRESS) {
state = recv_state;
}
}
}
for(i=0; i<numP; i++) { //Send state
if(i != myId) {
MPI_Send(&state, 1, MPI_INT, i, 120, MPI_COMM_WORLD);
}
}
} else {
MPI_Send(&commSlurm, 1, MPI_INT, root, 120, MPI_COMM_WORLD);
MPI_Recv(&state, 1, MPI_INT, root, 120, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
if(state != COMM_FINISHED) return state; // Continue only if asynchronous process creation has ended
if(state != MAL_SPAWN_COMPLETED) return state; // Continue only if asynchronous process creation has ended
} else {
return commSlurm;
......@@ -187,7 +160,7 @@ void* thread_work(void* creation_data_arg) {
}
create_processes(creation_data->myId, creation_data->root, returned_comm, creation_data->comm);
commSlurm = COMM_FINISHED;
commSlurm = MAL_SPAWN_COMPLETED;
free(creation_data);
pthread_exit(NULL);
......@@ -200,8 +173,8 @@ void* thread_work(void* creation_data_arg) {
* para una llamada a MPI_Comm_spawn, obteniendo una distribucion fisica
* para los procesos y creando un fichero hostfile.
*/
void processes_dist(char *argv[], int numP_childs, int type) {
int jobId, ptr;
void processes_dist(char *argv, int numP_childs, int type) {
int jobId;
char *tmp;
job_info_msg_t *j_info;
slurm_job_info_t last_record;
......@@ -217,8 +190,8 @@ void processes_dist(char *argv[], int numP_childs, int type) {
last_record = j_info->job_array[j_info->record_count - 1];
//COPY PROGRAM NAME
slurm_data->cmd = malloc(strlen(argv[0]) * sizeof(char));
strcpy(slurm_data->cmd, argv[0]);
slurm_data->cmd = malloc(strlen(argv) * sizeof(char));
strcpy(slurm_data->cmd, argv);
// GET NEW DISTRIBUTION
node_dist(last_record, type, numP_childs, &procs_array, &used_nodes);
......@@ -226,6 +199,7 @@ void processes_dist(char *argv[], int numP_childs, int type) {
/*
// CREATE/UPDATE HOSTFILE
int ptr;
ptr = create_hostfile(tmp, &hostfile);
MPI_Info_create(&(slurm_data->info));
MPI_Info_set(slurm_data->info, "hostfile", hostfile);
......@@ -236,7 +210,6 @@ void processes_dist(char *argv[], int numP_childs, int type) {
close(ptr);
*/
// TEST
fill_str_hostfile(last_record, procs_array, used_nodes, &hostfile);
MPI_Info_create(&(slurm_data->info));
......@@ -319,6 +292,70 @@ void node_dist(slurm_job_info_t job_record, int type, int total_procs, int **qty
}
/*
* Crea y devuelve una cadena para ser utilizada por la llave "hosts"
* al crear procesos e indicar donde tienen que ser creados.
*/
void fill_str_hostfile(slurm_job_info_t job_record, int *qty, int used_nodes, char **hostfile_str) {
int i=0, len=0;
char *host;
hostlist_t hostlist;
hostlist = slurm_hostlist_create(job_record.nodes);
while ( (host = slurm_hostlist_shift(hostlist)) && i < used_nodes) {
len = write_str_node(hostfile_str, len, qty[i], host);
i++;
free(host);
}
slurm_hostlist_destroy(hostlist);
}
/*
* Añade en una cadena "qty" entradas de "node_name".
* Realiza la reserva de memoria y la realoja si es necesario.
*/
int write_str_node(char **hostfile_str, int len_og, int qty, char *node_name) {
int err, len_node, len, i;
char *ocurrence;
len_node = strlen(node_name);
len = qty * (len_node + 1);
if(len_og == 0) { // Memoria no reservada
*hostfile_str = (char *) malloc(len * sizeof(char) - (1 * sizeof(char)));
} else { // Cadena ya tiene datos
*hostfile_str = (char *) realloc(*hostfile_str, (len_og + len) * sizeof(char) - (1 * sizeof(char)));
}
if(hostfile_str == NULL) return -1; // No ha sido posible alojar la memoria
ocurrence = (char *) malloc((len_node+1) * sizeof(char));
if(ocurrence == NULL) return -1; // No ha sido posible alojar la memoria
err = sprintf(ocurrence, ",%s", node_name);
if(err < 0) return -2; // No ha sido posible escribir sobre la variable auxiliar
i=0;
if(len_og == 0) { // Si se inicializa, la primera es una copia
i++;
strcpy(*hostfile_str, node_name);
}
for(; i<qty; i++){ // Las siguientes se conctanenan
strcat(*hostfile_str, ocurrence);
}
free(ocurrence);
return len+len_og;
}
//====================================================
//====================================================
//============DEPRECATED FUNCTIONS====================
//====================================================
//====================================================
/*
* @deprecated
* Crea un fichero que se utilizara como hostfile
* para un nuevo grupo de procesos.
*
......@@ -346,6 +383,7 @@ int create_hostfile(char *jobId, char **file_name) {
}
/*
* @deprecated
* Rellena un fichero hostfile indicado por ptr con los nombres
* de los nodos a utilizar indicados por "job_record" y la cantidad
* de procesos que alojara cada nodo indicado por "qty".
......@@ -365,6 +403,7 @@ void fill_hostfile(slurm_job_info_t job_record, int ptr, int *qty, int used_node
}
/*
* @deprecated
* Escribe en el fichero hostfile indicado por ptr una nueva linea.
*
* Esta linea indica el nombre de un nodo y la cantidad de procesos a
......@@ -389,53 +428,3 @@ int write_hostfile_node(int ptr, int qty, char *node_name) {
return 0;
}
void fill_str_hostfile(slurm_job_info_t job_record, int *qty, int used_nodes, char **hostfile_str) {
int i=0, len=0;
char *host;
hostlist_t hostlist;
hostlist = slurm_hostlist_create(job_record.nodes);
while ( (host = slurm_hostlist_shift(hostlist)) && i < used_nodes) {
len = write_str_node(hostfile_str, len, qty[i], host);
i++;
free(host);
}
slurm_hostlist_destroy(hostlist);
}
int write_str_node(char **hostfile_str, int len_og, int qty, char *node_name) {
int err, len_node, len, i;
char *ocurrence;
len_node = strlen(node_name);
len = qty * (len_node + 1);
if(len_og == 0) { // Memoria no reservada
*hostfile_str = (char *) malloc(len * sizeof(char) - (1 * sizeof(char)));
} else { // Cadena ya tiene datos
*hostfile_str = (char *) realloc(*hostfile_str, (len_og + len) * sizeof(char) - (1 * sizeof(char)));
}
if(hostfile_str == NULL) return -1; // No ha sido posible alojar la memoria
ocurrence = (char *) malloc((len_node+1) * sizeof(char));
if(ocurrence == NULL) return -1; // No ha sido posible alojar la memoria
err = sprintf(ocurrence, ",%s", node_name);
if(err < 0) return -2; // No ha sido posible escribir sobre la variable auxiliar
i=0;
if(len_og == 0) { // Si se inicializa, la primera es una copia
i++;
strcpy(*hostfile_str, node_name);
}
for(; i<qty; i++){ // Las siguientes se realizan con concatenan
strcat(*hostfile_str, ocurrence);
}
free(ocurrence);
return len+len_og;
}
......@@ -3,16 +3,17 @@
#include <mpi.h>
#include <string.h>
#include <slurm/slurm.h>
#include "malleabilityStates.h"
#define COMM_UNRESERVED -2
#define COMM_IN_PROGRESS -1
#define COMM_FINISHED 0
//#define COMM_UNRESERVED -2
//#define COMM_IN_PROGRESS -1
//#define COMM_FINISHED 0
#define COMM_PHY_NODES 1
#define COMM_PHY_CPU 2
//#define COMM_PHY_NODES 1
//#define COMM_PHY_CPU 2
#define COMM_SPAWN_SERIAL 0
#define COMM_SPAWN_PTHREAD 1
//#define COMM_SPAWN_SERIAL 0
//#define COMM_SPAWN_PTHREAD 1
int init_slurm_comm(char **argv, int myId, int numP, int root, int type_dist, int type_creation, MPI_Comm comm, MPI_Comm *child);
int init_slurm_comm(char *argv, int myId, int numP, int root, int type_dist, int type_creation, MPI_Comm comm, MPI_Comm *child);
int check_slurm_comm(int myId, int root, int numP, MPI_Comm *child);
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mpi.h>
#include "../IOcodes/read_ini.h"
#include "../IOcodes/results.h"
#include "malleabilityStates.h"
void init_malleability(int myId, int numP, int root, MPI_Comm comm, char *name_exec);
void free_malleability();
int malleability_checkpoint();
void set_benchmark_grp(int grp);
void set_malleability_configuration(int spawn_type, int spawn_dist, int spawn_threaded, int comm_type, int comm_threaded);
void set_children_number(int numC); // TODO TO BE DEPRECATED
void malleability_add_data(void *data, int total_qty, int type, int is_replicated, int is_constant);
void malleability_get_entries(int *entries, int is_replicated, int is_constant);
void malleability_get_data(void *data, int index, int is_replicated, int is_constant);
void set_benchmark_configuration(configuration *config_file);
void get_benchmark_configuration(configuration **config_file);
void set_benchmark_results(results_data *results);
void get_benchmark_results(results_data **results);
#define MAL_UNRESERVED -1
#define MAL_DENIED -2
#define MAL_NOT_STARTED 0
#define MAL_SPAWN_PENDING 1
#define MAL_SPAWN_COMPLETED 2
#define MAL_DIST_PENDING 3
#define MAL_DIST_COMPLETED 4
// TODO Refactor
#define COMM_PHY_NODES 1
#define COMM_PHY_CPU 2
#define COMM_SPAWN_SERIAL 0
#define COMM_SPAWN_PTHREAD 1
#define MAL_USE_NORMAL 0
#define MAL_USE_IBARRIER 1
#define MAL_USE_POINT 2
#define MAL_USE_THREAD 3
#include "malleabilityTypes.h"
void init_malleability_data_struct(malleability_data_t *data_struct, int size);
void realloc_malleability_data_struct(malleability_data_t *data_struct, int qty_to_add);
void def_malleability_entries(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, MPI_Datatype *new_type);
void def_malleability_qty_type(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, MPI_Datatype *new_type);
//======================================================||
//======================================================||
//===================PUBLIC FUNCTIONS===================||
//======================================================||
//======================================================||
/*
* Anyade en la estructura de datos a comunicar con los hijos
* un nuevo set de datos de un total "total_qty" distribuido entre
* todos los padres. La nueva serie "data" solo representa los datos
* que tiene este padre.
*/
void add_data(void *data, int total_qty, int type, int request_qty, malleability_data_t *data_struct) {
int i;
if(data_struct->entries == 0) {
init_malleability_data_struct(data_struct, MALLEABILITY_INIT_DATA_QTY);
} else if(data_struct->entries == data_struct->max_entries) {
realloc_malleability_data_struct(data_struct, MALLEABILITY_INIT_DATA_QTY);
}
data_struct->qty[data_struct->entries] = total_qty;
data_struct->types[data_struct->entries] = type;
data_struct->arrays[data_struct->entries] = data;
data_struct->requests[data_struct->entries] = (MPI_Request *) malloc(request_qty * sizeof(MPI_Request));
for(i=0; i < request_qty; i++) {
data_struct->requests[data_struct->entries][i] = MPI_REQUEST_NULL;
}
data_struct->entries+=1;
}
/*
* Comunicar desde los padres a los hijos las estructuras de datos sincronas o asincronas
* No es necesario que las estructuras esten inicializadas para un buen funcionamiento.
*
* En el argumento "root" todos tienen que indicar quien es el proceso raiz de los padres
* unicamente.
*/
void comm_data_info(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, int is_children_group, int myId, int root, MPI_Comm intercomm) {
int rootBcast = MPI_PROC_NULL;
MPI_Datatype entries_type, struct_type;
if(is_children_group) {
rootBcast = root;
} else {
if(myId == root) rootBcast = MPI_ROOT;
}
// Mandar primero numero de entradas
def_malleability_entries(data_struct_dist, data_struct_rep, &entries_type);
MPI_Bcast(&(data_struct_rep->entries), 1, entries_type, rootBcast, intercomm);
if(is_children_group) {
if(data_struct_rep->entries == 0) init_malleability_data_struct(data_struct_rep, data_struct_rep->entries);
if(data_struct_dist->entries == 0) init_malleability_data_struct(data_struct_dist, data_struct_dist->entries);
}
def_malleability_qty_type(data_struct_dist, data_struct_rep, &struct_type);
MPI_Bcast(&data_struct_rep, 1, struct_type, rootBcast, intercomm);
MPI_Type_free(&entries_type);
MPI_Type_free(&struct_type);
}
//======================================================||
//======================================================||
//=========INIT/REALLOC/FREE RESULTS FUNCTIONS==========||
//======================================================||
//======================================================||
/*
* Inicializa la estructura que describe una serie de datos con las mismas
* caracteristicas de localización y uso. Se inicializa para utilizar hasta
* "size" elementos.
*/
void init_malleability_data_struct(malleability_data_t *data_struct, int size) {
data_struct->max_entries = size;
data_struct->qty = (int *) malloc(size * sizeof(int));
data_struct->types = (int *) malloc(size * sizeof(int));
data_struct->requests = (MPI_Request **) malloc(size * sizeof(MPI_Request *));
data_struct->arrays = (void **) malloc(size * sizeof(void *));
data_struct->request_ibarrier = MPI_REQUEST_NULL;
}
/*
* Realoja la estructura que describe una serie de datos con las mismas
* caracteristicas de localización y uso. Se anyaden "size" entradas nuevas
* a las ya existentes.
*/
void realloc_malleability_data_struct(malleability_data_t *data_struct, int qty_to_add) {
int *qty_aux, *types_aux, needed;
MPI_Request **requests_aux;
void **arrays_aux;
needed = data_struct->max_entries + qty_to_add;
qty_aux = (int *) realloc(data_struct->qty, needed * sizeof(int));
types_aux = (int *) realloc(data_struct->types, needed * sizeof(int));
requests_aux = (MPI_Request **) realloc(data_struct->requests, needed * sizeof(MPI_Request *));
arrays_aux = (void **) realloc(data_struct->arrays, needed * sizeof(void *));
if(qty_aux == NULL || arrays_aux == NULL || requests_aux == NULL || types_aux == NULL) {
fprintf(stderr, "Fatal error - No se ha podido realojar la memoria constante de datos a redistribuir/comunicar\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
data_struct->qty = qty_aux;
data_struct->types = types_aux;
data_struct->requests = requests_aux;
data_struct->arrays = arrays_aux;
data_struct->max_entries = needed;
}
void free_malleability_data_struct(malleability_data_t *data_struct) {
int i, max;
max = data_struct->entries;
if(max != 0) {
for(i=0; i<max; i++) {
free(data_struct->requests[i]);
}
free(data_struct->qty);
free(data_struct->types);
free(data_struct->requests);
free(data_struct->arrays);
}
}
//======================================================||
//======================================================||
//================MPI DERIVED DATATYPES=================||
//======================================================||
//======================================================||
/*
* Crea un tipo derivado para mandar el numero de entradas
* en dos estructuras de descripcion de datos.
*/
void def_malleability_entries(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, MPI_Datatype *new_type) {
int counts = 2;
int blocklength = 1;
MPI_Aint displs, dir;
// Obtener direccion base
MPI_Get_address(&(data_struct_rep->entries), &dir);
MPI_Get_address(&(data_struct_dist->entries), &displs);
displs -= dir;
MPI_Type_create_hvector(counts, blocklength, displs, MPI_INT, new_type);
MPI_Type_commit(new_type);
}
/*
* Crea un tipo derivado para mandar las cantidades y tipo
* de datos de dos estructuras de descripcion de datos.
* El vector de "requests" no es enviado ya que solo es necesario
* en los padres.
*/
void def_malleability_qty_type(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, MPI_Datatype *new_type) {
int i, counts = 4;
int blocklengths[counts];
MPI_Aint displs[counts], dir;
MPI_Datatype types[counts];
types[0] = types[1] = types[2] = types[3] = MPI_INT;
blocklengths[0] = blocklengths[1] = data_struct_rep->entries;
blocklengths[2] = blocklengths[3] = data_struct_dist->entries;
// Obtener direccion base
MPI_Get_address(data_struct_rep, &dir);
MPI_Get_address(&(data_struct_rep->qty), &displs[0]);
MPI_Get_address(&(data_struct_rep->types), &displs[1]);
MPI_Get_address(&(data_struct_dist->qty), &displs[2]);
MPI_Get_address(&(data_struct_dist->types), &displs[3]);
for(i=0;i<counts;i++) displs[i] -= dir;
MPI_Type_create_struct(counts, blocklengths, displs, types, new_type);
MPI_Type_commit(new_type);
}
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "malleabilityStates.h"
#define MALLEABILITY_INIT_DATA_QTY 100
#define MAL_INT 0
#define MAL_CHAR 1
typedef struct {
int entries; // Indica numero de vectores a comunicar (replicated data)
int max_entries;
MPI_Request request_ibarrier; // Request para indicar que los padres esperan a que los hijos terminen de recibir
int *qty; // Indica numero de elementos en cada subvector de sync_array
int *types;
// Vector de vectores de request. En cada elemento superior se indican los requests a comprobar para dar por finalizada
// la comunicacion de ese dato
MPI_Request **requests;
void **arrays; // Cada subvector es una serie de datos a comunicar
} malleability_data_t;
void add_data(void *data, int total_qty, int type, int request_qty, malleability_data_t *data_struct);
void comm_data_info(malleability_data_t *data_struct_rep, malleability_data_t *data_struct_dist, int is_children_group, int myId, int root, MPI_Comm intercomm);
void free_malleability_data_struct(malleability_data_t *data_struct);
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