Commit b5d18427 authored by iker_martin's avatar iker_martin
Browse files

Refactor de código para eliminar warnings. Moviendose Config a dos ficheros. WIP

parent 7836c7b6
......@@ -27,7 +27,7 @@ void prepare_comm_alltoall(int myId, int numP, int numP_other, int n, struct Cou
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 mallocCounts(struct Counts *counts, int numP);
void mallocCounts(struct Counts *counts, size_t numP);
void freeCounts(struct Counts *counts);
void print_counts(struct Dist_data data_dist, int *xcounts, int *xdispls, int size, int include_zero, const char* name);
......
......@@ -292,7 +292,7 @@ void get_malleability_user_comm(MPI_Comm *comm) {
*
* Mas informacion en la funcion "add_data".
*/
void malleability_add_data(void *data, int total_qty, int type, int is_replicated, int is_constant) {
void malleability_add_data(void *data, size_t total_qty, int type, int is_replicated, int is_constant) {
if(is_constant) {
if(is_replicated) {
......@@ -304,14 +304,14 @@ void malleability_add_data(void *data, int total_qty, int type, int is_replicate
if(is_replicated) {
add_data(data, total_qty, type, 0, rep_a_data); //FIXME Numero magico || Un request?
} else {
int total_reqs = 0;
size_t total_reqs = 0;
if(mall_conf->comm_type == MAL_USE_NORMAL) {
total_reqs = 1;
} else if(mall_conf->comm_type == MAL_USE_IBARRIER) {
total_reqs = 2;
} else if(mall_conf->comm_type == MAL_USE_POINT) {
total_reqs = mall->numC;
total_reqs = (size_t) mall->numC;
}
add_data(data, total_qty, type, total_reqs, dist_a_data);
......@@ -323,7 +323,7 @@ void malleability_add_data(void *data, int total_qty, int type, int is_replicate
* Devuelve el numero de entradas para la estructura de descripcion de
* datos elegida.
*/
void malleability_get_entries(int *entries, int is_replicated, int is_constant){
void malleability_get_entries(size_t *entries, int is_replicated, int is_constant){
if(is_constant) {
if(is_replicated) {
......@@ -381,18 +381,18 @@ void malleability_get_data(void **data, int index, int is_replicated, int is_con
* de forma bloqueante o no. El padre puede tener varios hilos.
*/
void send_data(int numP_children, malleability_data_t *data_struct, int is_asynchronous) {
int i;
size_t i;
char *aux;
if(is_asynchronous) {
for(i=0; i < data_struct->entries; i++) {
aux = (char *) data_struct->arrays[i]; //TODO Comprobar que realmente es un char
send_async(aux, data_struct->qty[i], mall->myId, mall->numP, mall->root, mall->intercomm, numP_children, data_struct->requests, mall_conf->comm_type);
send_async(aux, (int) data_struct->qty[i], mall->myId, mall->numP, mall->intercomm, numP_children, data_struct->requests, mall_conf->comm_type);
}
} else {
for(i=0; i < data_struct->entries; i++) {
aux = (char *) data_struct->arrays[i]; //TODO Comprobar que realmente es un char
send_sync(aux, data_struct->qty[i], mall->myId, mall->numP, mall->root, mall->intercomm, numP_children);
send_sync(aux, (int) data_struct->qty[i], mall->myId, mall->numP, mall->intercomm, numP_children);
}
}
}
......@@ -403,19 +403,19 @@ void send_data(int numP_children, malleability_data_t *data_struct, int is_async
* de forma bloqueante o no. El padre puede tener varios hilos.
*/
void recv_data(int numP_parents, malleability_data_t *data_struct, int is_asynchronous) {
int i;
size_t i;
char *aux;
if(is_asynchronous) {
for(i=0; i < data_struct->entries; i++) {
aux = (char *) data_struct->arrays[i]; //TODO Comprobar que realmente es un char
recv_async(&aux, data_struct->qty[i], mall->myId, mall->numP, mall->root, mall->intercomm, numP_parents, mall_conf->comm_type);
recv_async(&aux, (int) data_struct->qty[i], mall->myId, mall->numP, mall->intercomm, numP_parents, mall_conf->comm_type);
data_struct->arrays[i] = (void *) aux;
}
} else {
for(i=0; i < data_struct->entries; i++) {
aux = (char *) data_struct->arrays[i]; //TODO Comprobar que realmente es un char
recv_sync(&aux, data_struct->qty[i], mall->myId, mall->numP, mall->root, mall->intercomm, numP_parents);
recv_sync(&aux, (int) data_struct->qty[i], mall->myId, mall->numP, mall->intercomm, numP_parents);
data_struct->arrays[i] = (void *) aux;
}
}
......@@ -434,7 +434,8 @@ void recv_data(int numP_parents, malleability_data_t *data_struct, int is_asynch
* ya sea de forma sincrona, asincrona o ambas.
*/
void Children_init() {
int numP_parents, root_parents, i;
size_t i;
int numP_parents, root_parents;
int is_intercomm;
malleability_connect_children(mall->myId, mall->numP, mall->root, mall->comm, &numP_parents, &root_parents, &(mall->intercomm));
......@@ -444,7 +445,7 @@ void Children_init() {
recv_config_file(mall->root, mall->intercomm, &(mall_conf->config_file));
mall_conf->results = (results_data *) malloc(sizeof(results_data));
init_results_data(mall_conf->results, mall_conf->config_file->n_resizes, mall_conf->config_file->n_stages, RESULTS_INIT_DATA_QTY);
init_results_data(mall_conf->results, (size_t) mall_conf->config_file->n_resizes, (size_t) mall_conf->config_file->n_stages, RESULTS_INIT_DATA_QTY);
if(dist_a_data->entries || rep_a_data->entries) { // Recibir datos asincronos
comm_data_info(rep_a_data, dist_a_data, MALLEABILITY_CHILDREN, mall->myId, root_parents, mall->intercomm);
......@@ -473,7 +474,7 @@ void Children_init() {
} else {
datatype = MPI_CHAR;
}
MPI_Bcast(rep_s_data->arrays[i], rep_s_data->qty[i], datatype, root_parents, mall->intercomm);
MPI_Bcast(rep_s_data->arrays[i], (int) rep_s_data->qty[i], datatype, root_parents, mall->intercomm);
}
}
......@@ -620,7 +621,8 @@ int check_redistribution() {
* Finalmente termina enviando los datos temporales a los hijos.
*/
int end_redistribution() {
int i, is_intercomm, rootBcast, local_state;
size_t i;
int is_intercomm, rootBcast, local_state;
is_intercomm = 0;
if(mall->intercomm != MPI_COMM_NULL) {
......@@ -650,7 +652,7 @@ int end_redistribution() {
} else {
datatype = MPI_CHAR;
}
MPI_Bcast(rep_s_data->arrays[i], rep_s_data->qty[i], datatype, rootBcast, mall->intercomm);
MPI_Bcast(rep_s_data->arrays[i], (int) rep_s_data->qty[i], datatype, rootBcast, mall->intercomm);
}
}
......
......@@ -7,8 +7,8 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <mpi.h>
#include "../IOcodes/read_ini.h"
#include "../IOcodes/results.h"
#include "../Main/configuration.h"
#include "../Main/Main_datatypes.h"
#include "malleabilityStates.h"
......@@ -22,8 +22,8 @@ void set_malleability_configuration(int spawn_method, int spawn_strategies, int
void set_children_number(int numC); // TODO TO BE DEPRECATED
void get_malleability_user_comm(MPI_Comm *comm);
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_add_data(void *data, size_t total_qty, int type, int is_replicated, int is_constant);
void malleability_get_entries(size_t *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);
......
......@@ -20,6 +20,7 @@
#define MAL_DIST_ADAPTED 8
*/
#define MALL_DENIED -1
enum mall_states{MALL_UNRESERVED, MALL_NOT_STARTED, MALL_ZOMBIE, MALL_SPAWN_PENDING, MALL_SPAWN_SINGLE_PENDING,
MALL_SPAWN_SINGLE_COMPLETED, MALL_SPAWN_ADAPT_POSTPONE, MALL_SPAWN_COMPLETED, MALL_DIST_PENDING, MALL_DIST_COMPLETED,
MALL_SPAWN_ADAPT_PENDING, MALL_SPAWN_ADAPTED, MALL_COMPLETED};
......
#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 init_malleability_data_struct(malleability_data_t *data_struct, size_t size);
void realloc_malleability_data_struct(malleability_data_t *data_struct, size_t 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);
......@@ -20,8 +20,8 @@ void def_malleability_qty_type(malleability_data_t *data_struct_rep, malleabilit
* 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;
void add_data(void *data, size_t total_qty, int type, size_t request_qty, malleability_data_t *data_struct) {
size_t i;
if(data_struct->entries == 0) {
init_malleability_data_struct(data_struct, MALLEABILITY_INIT_DATA_QTY);
......@@ -49,7 +49,8 @@ void add_data(void *data, int total_qty, int type, int request_qty, malleability
* 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 i, is_intercomm, rootBcast = MPI_PROC_NULL;
int is_intercomm, rootBcast = MPI_PROC_NULL;
size_t i;
MPI_Datatype entries_type, struct_type;
......@@ -65,8 +66,8 @@ void comm_data_info(malleability_data_t *data_struct_rep, malleability_data_t *d
MPI_Bcast(MPI_BOTTOM, 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);
if(data_struct_rep->entries != (size_t) 0) init_malleability_data_struct(data_struct_rep, data_struct_rep->entries);
if(data_struct_dist->entries != (size_t) 0) init_malleability_data_struct(data_struct_dist, data_struct_dist->entries);
}
def_malleability_qty_type(data_struct_dist, data_struct_rep, &struct_type);
......@@ -99,9 +100,9 @@ void comm_data_info(malleability_data_t *data_struct_rep, malleability_data_t *d
* 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) {
void init_malleability_data_struct(malleability_data_t *data_struct, size_t size) {
data_struct->max_entries = size;
data_struct->qty = (int *) malloc(size * sizeof(int));
data_struct->qty = (size_t *) malloc(size * sizeof(size_t));
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 *));
......@@ -114,13 +115,14 @@ void init_malleability_data_struct(malleability_data_t *data_struct, int size) {
* 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;
void realloc_malleability_data_struct(malleability_data_t *data_struct, size_t qty_to_add) {
size_t needed, *qty_aux;
int *types_aux;
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));
qty_aux = (size_t *) 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 *));
......@@ -138,7 +140,7 @@ void realloc_malleability_data_struct(malleability_data_t *data_struct, int qty_
}
void free_malleability_data_struct(malleability_data_t *data_struct) {
int i, max;
size_t i, max;
max = data_struct->entries;
if(max != 0) {
......@@ -195,8 +197,8 @@ void def_malleability_qty_type(malleability_data_t *data_struct_rep, malleabilit
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;
blocklengths[0] = blocklengths[1] = (int)data_struct_rep->entries;
blocklengths[2] = blocklengths[3] = (int)data_struct_dist->entries;
MPI_Get_address((data_struct_rep->qty), &displs[0]);
MPI_Get_address((data_struct_rep->types), &displs[1]);
......
......@@ -11,10 +11,10 @@
#define MALLEABILITY_INIT_DATA_QTY 100
typedef struct {
int entries; // Indica numero de vectores a comunicar (replicated data)
int max_entries;
size_t entries; // Indica numero de vectores a comunicar (replicated data)
size_t 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
size_t *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
......@@ -24,7 +24,7 @@ typedef struct {
} malleability_data_t;
void add_data(void *data, int total_qty, int type, int request_qty, malleability_data_t *data_struct);
void add_data(void *data, size_t total_qty, int type, size_t 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);
......
......@@ -20,8 +20,8 @@ void gestor_usr2() {}
void zombies_collect_suspended(MPI_Comm comm, int myId, int numP, int numC, int root, void *results_void) {
int pid = getpid();
int *pids_counts = malloc(numP * sizeof(int));
int *pids_displs = malloc(numP * sizeof(int));
int *pids_counts = malloc((size_t)numP * sizeof(int));
int *pids_displs = malloc((size_t)numP * sizeof(int));
int i, count=1;
if(myId < numC) {
......
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <pthread.h>
#include "../malleabilityStates.h"
#include "Baseline.h"
#include "Spawn_state.h"
//--------------PRIVATE DECLARATIONS---------------//
int baseline_spawn(Spawn_data spawn_data, MPI_Comm comm, MPI_Comm *child);
int baseline_single_spawn(Spawn_data spawn_data, MPI_Comm *child);
void baseline_establish_connection(int myId, int root, MPI_Comm *parents);
int single_strat_parents(Spawn_data spawn_data, MPI_Comm *child);
void single_strat_children(int myId, int root, MPI_Comm *parents);
//--------------PUBLIC FUNCTIONS---------------//
/*
* Metodo basico para la creacion de procesos. Crea en total
* spawn_data.spawn_qty procesos.
*
* Tiene incorporada la estrategia Single para permitir que
* un solo proceso padre cree a los hijos.
*
* Si la funcion es llamada por los hijos se comprobara si
* se esta utilizando la estrategia Single para terminar
* la creacion de procesos. En caso contrario no realizan
* nada los hijos.
*/
int baseline(Spawn_data spawn_data, MPI_Comm *child) { //TODO Tratamiento de errores
MPI_Comm intercomm;
MPI_Comm_get_parent(&intercomm);
if (intercomm == MPI_COMM_NULL) { // Parents path
if(spawn_data.spawn_is_single) {
baseline_single_spawn(spawn_data, child);
if (spawn_data.spawn_is_single) {
single_strat_parents(spawn_data, child);
} else {
baseline_spawn(spawn_data, spawn_data.comm, child);
}
} else if(spawn_data.spawn_is_single) { // Children path
baseline_establish_connection(spawn_data.myId, spawn_data.root, child);
single_strat_children(spawn_data.myId, spawn_data.root, child);
}
return MALL_SPAWN_COMPLETED;
}
......@@ -52,23 +44,21 @@ int baseline_spawn(Spawn_data spawn_data, MPI_Comm comm, MPI_Comm *child) {
// WORK
int spawn_err = MPI_Comm_spawn(spawn_data.cmd, MPI_ARGV_NULL, spawn_data.spawn_qty, spawn_data.mapping, spawn_data.root, comm, child, MPI_ERRCODES_IGNORE);
// END WORK
if(spawn_err != MPI_SUCCESS) {
printf("Error creating new set of %d procs.\n", spawn_data.spawn_qty);
}
// END WORK
MPI_Bcast(&spawn_data, 1, spawn_data.dtype, rootBcast, *child);
return spawn_err;
}
/*
* Si la variable "type" es 1, la creación es con la participación de todo el grupo de padres
* Si el valor es diferente, la creación es solo con la participación del proceso root
*/
int baseline_single_spawn(Spawn_data spawn_data, MPI_Comm *child) {
int single_strat_parents(Spawn_data spawn_data, MPI_Comm *child) {
int spawn_err;
char *port_name;
MPI_Comm newintercomm;
......@@ -95,7 +85,6 @@ int baseline_single_spawn(Spawn_data spawn_data, MPI_Comm *child) {
return spawn_err;
}
/*
* Conectar grupo de hijos con grupo de padres
* Devuelve un intercomunicador para hablar con los padres
......@@ -103,7 +92,7 @@ int baseline_single_spawn(Spawn_data spawn_data, MPI_Comm *child) {
* Solo se utiliza cuando la creación de los procesos ha sido
* realizada por un solo proceso padre
*/
void baseline_establish_connection(int myId, int root, MPI_Comm *parents) {
void single_strat_children(int myId, int root, MPI_Comm *parents) {
char *port_name;
MPI_Comm newintercomm;
......
......@@ -34,7 +34,7 @@ int check_generic_state(MPI_Comm comm, MPI_Comm *child, int local_state, double
//--------------PRIVATE THREADS DECLARATIONS---------------//
int allocate_thread_spawn();
void* thread_work(void* arg);
void* thread_work();
//--------------PUBLIC FUNCTIONS---------------//
......@@ -339,7 +339,7 @@ int allocate_thread_spawn() {
* Una vez esta lista la configuracion y es posible crear los procesos
* se avisa al hilo maestro.
*/
void* thread_work(void* arg) {
void* thread_work() {
int local_state;
returned_comm = (MPI_Comm *) malloc(sizeof(MPI_Comm));
......
......@@ -15,9 +15,9 @@ void node_dist( struct physical_dist dist, int **qty, int *used_nodes);
void spread_dist(struct physical_dist dist, int *used_nodes, int *procs);
void compact_dist(struct physical_dist dist, int *used_nodes, int *procs);
void generate_info_string(char *nodelist, int *procs_array, int nodes, MPI_Info *info);
void fill_str_hostfile(char *nodelist, int *qty, int used_nodes, char **hostfile_str);
int write_str_node(char **hostfile_str, int len_og, int qty, char *node_name);
void generate_info_string(char *nodelist, int *procs_array, size_t nodes, MPI_Info *info);
void fill_str_hostfile(char *nodelist, int *qty, size_t used_nodes, char **hostfile_str);
int write_str_node(char **hostfile_str, size_t len_og, size_t qty, char *node_name);
//@deprecated functions
void generate_info_hostfile(char *nodelist, int *procs_array, int nodes, MPI_Info *info);
......@@ -76,7 +76,7 @@ void processes_dist(struct physical_dist dist, MPI_Info *info_spawn) {
node_dist(dist, &procs_array, &used_nodes);
switch(dist.info_type) {
case MALL_DIST_STRING:
generate_info_string(dist.nodelist, procs_array, used_nodes, info_spawn);
generate_info_string(dist.nodelist, procs_array, (size_t) used_nodes, info_spawn);
break;
case MALL_DIST_HOSTFILE:
generate_info_hostfile(dist.nodelist, procs_array, used_nodes, info_spawn);
......@@ -101,7 +101,7 @@ void processes_dist(struct physical_dist dist, MPI_Info *info_spawn) {
void node_dist(struct physical_dist dist, int **qty, int *used_nodes) {
int i, *procs;
procs = calloc(dist.num_nodes, sizeof(int)); // Numero de procesos por nodo
procs = calloc((size_t)dist.num_nodes, sizeof(int)); // Numero de procesos por nodo
/* GET NEW DISTRIBUTION */
switch(dist.dist_type) {
......@@ -114,7 +114,7 @@ void node_dist(struct physical_dist dist, int **qty, int *used_nodes) {
}
//Copy results to output vector qty
*qty = calloc(*used_nodes, sizeof(int)); // Numero de procesos por nodo
*qty = calloc((size_t)*used_nodes, sizeof(int)); // Numero de procesos por nodo
for(i=0; i< *used_nodes; i++) {
(*qty)[i] = procs[i];
}
......@@ -189,7 +189,7 @@ void compact_dist(struct physical_dist dist, int *used_nodes, int *procs) {
* en el que se indica el mappeado a utilizar en los nuevos
* procesos.
*/
void generate_info_string(char *nodelist, int *procs_array, int nodes, MPI_Info *info){
void generate_info_string(char *nodelist, int *procs_array, size_t nodes, MPI_Info *info){
// CREATE AND SET STRING HOSTS
char *hoststring;
fill_str_hostfile(nodelist, procs_array, nodes, &hoststring);
......@@ -203,15 +203,15 @@ void generate_info_string(char *nodelist, int *procs_array, int nodes, MPI_Info
* 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(char *nodelist, int *qty, int used_nodes, char **hostfile_str) {
int i=0, len=0;
void fill_str_hostfile(char *nodelist, int *qty, size_t used_nodes, char **hostfile_str) {
char *host;
size_t i=0,len=0;
hostlist_t hostlist;
hostlist = slurm_hostlist_create(nodelist);
while ( (host = slurm_hostlist_shift(hostlist)) && i < used_nodes) {
if(qty[i] != 0) {
len = write_str_node(hostfile_str, len, qty[i], host);
len = (size_t) write_str_node(hostfile_str, len, (size_t)qty[i], host);
}
i++;
free(host);
......@@ -223,24 +223,25 @@ void fill_str_hostfile(char *nodelist, int *qty, int used_nodes, char **hostfile
* 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;
int write_str_node(char **hostfile_str, size_t len_og, size_t qty, char *node_name) {
int err;
char *ocurrence;
size_t i, len, len_node;
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)));
*hostfile_str = (char *) malloc(len * sizeof(char) - sizeof(char));
} else { // Cadena ya tiene datos
*hostfile_str = (char *) realloc(*hostfile_str, (len_og + len) * sizeof(char) - (1 * sizeof(char)));
*hostfile_str = (char *) realloc(*hostfile_str, (len_og + len) * sizeof(char) - 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
if(ocurrence == NULL) return -2; // 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
if(err < 0) return -3; // No ha sido posible escribir sobre la variable auxiliar
i=0;
if(len_og == 0) { // Si se inicializa, la primera es una copia
......@@ -294,10 +295,11 @@ void generate_info_hostfile(char *nodelist, int *procs_array, int nodes, MPI_Inf
* modificar el fichero.
*/
int create_hostfile(char **file_name) {
int ptr, err, len = 11;
int ptr, err;
size_t len = 11; //FIXME Numero mágico
*file_name = NULL;
*file_name = malloc( len * sizeof(char));
*file_name = malloc(len * sizeof(char));
if(*file_name == NULL) return -1; // No ha sido posible alojar la memoria
err = snprintf(*file_name, len, "hostfile.o");
if(err < 0) return -2; // No ha sido posible obtener el nombre de fichero
......@@ -336,18 +338,21 @@ void fill_hostfile(char *nodelist, int ptr, int *qty, int nodes) {
* alojar en ese nodo.
*/
int write_hostfile_node(int ptr, int qty, char *node_name) {
int err, len_node, len_int, len;
int err;
char *line;
size_t len, len_node, len_int;
len_node = strlen(node_name);
len_int = snprintf(NULL, 0, "%d", qty);
err = snprintf(NULL, 0, "%d", qty);
if(err < 0) return -1;
len_int = (size_t) err;
len = len_node + len_int + 3;
line = malloc(len * sizeof(char));
if(line == NULL) return -1; // No ha sido posible alojar la memoria
if(line == NULL) return -2; // No ha sido posible alojar la memoria
err = snprintf(line, len, "%s:%d\n", node_name, qty);
if(err < 0) return -2; // No ha sido posible escribir en el fichero
if(err < 0) return -3; // No ha sido posible escribir en el fichero
write(ptr, line, len-1);
free(line);
......
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