X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9e68ca10e951fb61e944c99c7774b1e415ae9f6d..450f39091bfbf41590dfdcc521f9ce41cf5bbe01:/src/simdag/sd_dotloader.c diff --git a/src/simdag/sd_dotloader.c b/src/simdag/sd_dotloader.c index 57d6d358d5..b6ceb64946 100644 --- a/src/simdag/sd_dotloader.c +++ b/src/simdag/sd_dotloader.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010. The SimGrid Team. +/* Copyright (c) 2009-2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -27,9 +27,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files"); #define agnxtout(dot, edge) agnxtout(edge) #endif +typedef enum { + sequential =0, + parallel +} seq_par_t; + void dot_add_task(Agnode_t * dag_node); -void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge); -void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge); +void dot_add_parallel_task(Agnode_t * dag_node); +void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge, + seq_par_t seq_or_par); +void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge, + seq_par_t seq_or_par); xbt_dynar_t SD_dotload_generic(const char * filename); static double dot_parse_double(const char *string) @@ -95,15 +103,20 @@ static void dot_task_p_free(void *task) SD_task_destroy(*t); } +#ifdef HAVE_TRACING static void TRACE_sd_dotloader (SD_task_t task, const char *category) { - if (category){ - if (strlen (category) != 0){ - TRACE_category (category); - SD_task_set_category (task, category); - } + if (category && strlen (category)){ + if (task->category) + XBT_DEBUG("Change the category of %s from %s to %s", + task->name, task->category, category); + else + XBT_DEBUG("Set the category of %s to %s",task->name, category); + TRACE_category (category); + TRACE_sd_set_task_category(task, category); } } +#endif /** @brief loads a DOT file describing a DAG * @@ -176,10 +189,9 @@ xbt_dynar_t SD_dotload_with_sched(const char *filename){ return NULL; } -xbt_dynar_t SD_dotload_generic(const char * filename) +xbt_dynar_t SD_PTG_dotload(const char * filename) { xbt_assert(filename, "Unable to use a null file descriptor\n"); - //dag_dot = agopen((char*)filename,Agstrictdirected,0); FILE *in_file = fopen(filename, "r"); dag_dot = agread(in_file, NIL(Agdisc_t *)); @@ -187,18 +199,18 @@ xbt_dynar_t SD_dotload_generic(const char * filename) files = xbt_dict_new_homogeneous(&dot_task_free); jobs = xbt_dict_new_homogeneous(NULL); computers = xbt_dict_new_homogeneous(NULL); - root_task = SD_task_create_comp_seq("root", NULL, 0); + root_task = SD_task_create_comp_par_amdahl("root", NULL, 0., 0.); /* by design the root task is always SCHEDULABLE */ __SD_task_set_state(root_task, SD_SCHEDULABLE); xbt_dict_set(jobs, "root", root_task, NULL); xbt_dynar_push(result, &root_task); - end_task = SD_task_create_comp_seq("end", NULL, 0); + end_task = SD_task_create_comp_par_amdahl("end", NULL, 0., 0.); xbt_dict_set(jobs, "end", end_task, NULL); Agnode_t *dag_node = NULL; for (dag_node = agfstnode(dag_dot); dag_node; dag_node = agnxtnode(dag_dot, dag_node)) { - dot_add_task(dag_node); + dot_add_parallel_task(dag_node); } agclose(dag_dot); xbt_dict_free(&jobs); @@ -218,7 +230,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename) if (xbt_dynar_is_empty(file->tasks_before)) { xbt_dynar_foreach(file->tasks_after, cpt2, depafter) { SD_task_t newfile = - SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_create_comm_par_mxn_1d_block(file->name, NULL, file->amount); SD_task_dependency_add(NULL, NULL, root_task, newfile); SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); xbt_dynar_push(result, &newfile); @@ -226,7 +238,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename) } else if (xbt_dynar_is_empty(file->tasks_after)) { xbt_dynar_foreach(file->tasks_before, cpt2, depbefore) { SD_task_t newfile = - SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_create_comm_par_mxn_1d_block(file->name, NULL, file->amount); SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); SD_task_dependency_add(NULL, NULL, newfile, end_task); xbt_dynar_push(result, &newfile); @@ -240,7 +252,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename) file->name, depbefore->src->name); } newfile = - SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_create_comm_par_mxn_1d_block(file->name, NULL, file->amount); SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); xbt_dynar_push(result, &newfile); @@ -254,6 +266,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename) /* Free previous copy of the files */ xbt_dict_free(&files); + xbt_dict_free(&computers); fclose(in_file); if (!acyclic_graph_detail(result)) { XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", @@ -264,6 +277,125 @@ xbt_dynar_t SD_dotload_generic(const char * filename) return result; } + +xbt_dynar_t SD_dotload_generic(const char * filename) +{ + xbt_assert(filename, "Unable to use a null file descriptor\n"); + //dag_dot = agopen((char*)filename,Agstrictdirected,0); + FILE *in_file = fopen(filename, "r"); + dag_dot = agread(in_file, NIL(Agdisc_t *)); + + result = xbt_dynar_new(sizeof(SD_task_t), dot_task_p_free); + files = xbt_dict_new_homogeneous(NULL); + jobs = xbt_dict_new_homogeneous(NULL); + computers = xbt_dict_new_homogeneous(NULL); + root_task = SD_task_create_comp_seq("root", NULL, 0); + /* by design the root task is always SCHEDULABLE */ + __SD_task_set_state(root_task, SD_SCHEDULABLE); + + xbt_dict_set(jobs, "root", root_task, NULL); + xbt_dynar_push(result, &root_task); + end_task = SD_task_create_comp_seq("end", NULL, 0); + xbt_dict_set(jobs, "end", end_task, NULL); + + Agnode_t *dag_node = NULL; + for (dag_node = agfstnode(dag_dot); dag_node; dag_node = agnxtnode(dag_dot, dag_node)) { + dot_add_task(dag_node); + } + agclose(dag_dot); + xbt_dict_free(&jobs); + + /* And now, post-process the files. + * We want a file task per pair of computation tasks exchanging the file. Duplicate on need + * Files not produced in the system are said to be produced by root task (top of DAG). + * Files not consumed in the system are said to be consumed by end task (bottom of DAG). + */ + xbt_dict_cursor_t cursor; + SD_task_t file; + char *name; + xbt_dict_foreach(files, cursor, name, file) { + XBT_DEBUG("Considering file '%s' stored in the dictionnary", + file->name); + if (xbt_dynar_is_empty(file->tasks_before)) { + XBT_DEBUG("file '%s' has no source. Add dependency from 'root'", + file->name); + SD_task_dependency_add(NULL, NULL, root_task, file); + } else if (xbt_dynar_is_empty(file->tasks_after)) { + XBT_DEBUG("file '%s' has no destination. Add dependency to 'end'", + file->name); + SD_task_dependency_add(NULL, NULL, file, end_task); + } + xbt_dynar_push(result, &file); + } + + /* Push end task last */ + xbt_dynar_push(result, &end_task); + + xbt_dict_free(&files); + fclose(in_file); + if (!acyclic_graph_detail(result)) { + XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", + basename((char*)filename)); + xbt_dynar_free(&result); + /* (result == NULL) here */ + } + return result; +} + +/* dot_add_parallel_task create a sd_task of SD_TASK_COMP_PAR_AMDHAL type and + * all transfers required for this task. The execution time of the task is + * given by the attribute size. The unit of size is the Flop.*/ +void dot_add_parallel_task(Agnode_t * dag_node) +{ + char *name = agnameof(dag_node); + SD_task_t current_job; + double amount = dot_parse_double(agget(dag_node, (char *) "size")); + double alpha = dot_parse_double(agget(dag_node, (char *) "alpha")); + + if (alpha == -1.) + alpha = 0.0; + + XBT_DEBUG("See ", name, + agget(dag_node, (char *) "size"), amount, alpha); + if (!strcmp(name, "root")){ + XBT_WARN("'root' node is explicitly declared in the DOT file. Ignore it"); + return; + } + if (!strcmp(name, "end")){ + XBT_WARN("'end' node is explicitly declared in the DOT file. Ignore it"); + return; + } + + current_job = xbt_dict_get_or_null(jobs, name); + if (current_job == NULL) { + current_job = + SD_task_create_comp_par_amdahl(name, NULL , amount, alpha); +#ifdef HAVE_TRACING + TRACE_sd_dotloader (current_job, agget (dag_node, (char*)"category")); +#endif + xbt_dict_set(jobs, name, current_job, NULL); + xbt_dynar_push(result, ¤t_job); + } + Agedge_t *e; + int count = 0; + + for (e = agfstin(dag_dot, dag_node); e; e = agnxtin(dag_dot, e)) { + dot_add_input_dependencies(current_job, e, parallel); + count++; + } + if (count == 0 && current_job != root_task) { + SD_task_dependency_add(NULL, NULL, root_task, current_job); + } + count = 0; + for (e = agfstout(dag_dot, dag_node); e; e = agnxtout(dag_dot, e)) { + dot_add_output_dependencies(current_job, e, parallel); + count++; + } + if (count == 0 && current_job != end_task) { + SD_task_dependency_add(NULL, NULL, current_job, end_task); + } +} + /* dot_add_task create a sd_task and all transfers required for this * task. The execution time of the task is given by the attribute size. * The unit of size is the Flop.*/ @@ -275,12 +407,29 @@ void dot_add_task(Agnode_t * dag_node) XBT_DEBUG("See ", name, agget(dag_node, (char *) "size"), runtime); + + if (!strcmp(name, "root")){ + XBT_WARN("'root' node is explicitly declared in the DOT file. Update it"); + root_task->amount = runtime; +#ifdef HAVE_TRACING + TRACE_sd_dotloader (root_task, agget (dag_node, (char*)"category")); +#endif + } + + if (!strcmp(name, "end")){ + XBT_WARN("'end' node is explicitly declared in the DOT file. Update it"); + end_task->amount = runtime; +#ifdef HAVE_TRACING + TRACE_sd_dotloader (end_task, agget (dag_node, (char*)"category")); +#endif + } + current_job = xbt_dict_get_or_null(jobs, name); - if (current_job == NULL) { + if (!current_job) { current_job = SD_task_create_comp_seq(name, NULL , runtime); #ifdef HAVE_TRACING - TRACE_sd_dotloader (current_job, agget (dag_node, (char*)"category")); + TRACE_sd_dotloader (current_job, agget (dag_node, (char*)"category")); #endif xbt_dict_set(jobs, name, current_job, NULL); xbt_dynar_push(result, ¤t_job); @@ -289,7 +438,7 @@ void dot_add_task(Agnode_t * dag_node) int count = 0; for (e = agfstin(dag_dot, dag_node); e; e = agnxtin(dag_dot, e)) { - dot_add_input_dependencies(current_job, e); + dot_add_input_dependencies(current_job, e, sequential); count++; } if (count == 0 && current_job != root_task) { @@ -297,7 +446,7 @@ void dot_add_task(Agnode_t * dag_node) } count = 0; for (e = agfstout(dag_dot, dag_node); e; e = agnxtout(dag_dot, e)) { - dot_add_output_dependencies(current_job, e); + dot_add_output_dependencies(current_job, e, sequential); count++; } if (count == 0 && current_job != end_task) { @@ -360,7 +509,8 @@ void dot_add_task(Agnode_t * dag_node) * and a transfers. This is given by the edges in the dot file. * The amount of data transfers is given by the attribute size on the * edge. */ -void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge) +void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge, + seq_par_t seq_or_par) { SD_task_t file = NULL; char *name_tail=agnameof(agtail(edge)); @@ -368,17 +518,24 @@ void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge) char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char)); sprintf(name, "%s->%s", name_tail, name_head); double size = dot_parse_double(agget(edge, (char *) "size")); - XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size")); + XBT_DEBUG("add input -- edge: %s, size : %e, get size : %s", + name, size, agget(edge, (char *) "size")); if (size > 0) { file = xbt_dict_get_or_null(files, name); if (file == NULL) { - file = SD_task_create_comm_e2e(name, NULL, size); + if (seq_or_par == sequential){ + file = SD_task_create_comm_e2e(name, NULL, size); + } else { + file = SD_task_create_comm_par_mxn_1d_block(name, NULL, size); + } #ifdef HAVE_TRACING TRACE_sd_dotloader (file, agget (edge, (char*)"category")); #endif + XBT_DEBUG("add input -- adding %s to the dict as new file", name); xbt_dict_set(files, name, file, NULL); } else { + XBT_WARN("%s already exists", name); if (SD_task_get_amount(file) != size) { XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f", name, SD_task_get_amount(file), size); @@ -398,25 +555,32 @@ void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge) * transfers and a task. This is given by the edges in the dot file. * The amount of data transfers is given by the attribute size on the * edge. */ -void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge) -{ +void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge, + seq_par_t seq_or_par){ SD_task_t file; char *name_tail=agnameof(agtail(edge)); char *name_head=agnameof(aghead(edge)); char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char)); sprintf(name, "%s->%s", name_tail, name_head); double size = dot_parse_double(agget(edge, (char *) "size")); - XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size")); + XBT_DEBUG("add_output -- edge: %s, size : %e, get size : %s", + name, size, agget(edge, (char *) "size")); if (size > 0) { file = xbt_dict_get_or_null(files, name); if (file == NULL) { - file = SD_task_create_comm_e2e(name, NULL, size); + if (seq_or_par == sequential){ + file = SD_task_create_comm_e2e(name, NULL, size); + } else { + file = SD_task_create_comm_par_mxn_1d_block(name, NULL, size); + } #ifdef HAVE_TRACING TRACE_sd_dotloader (file, agget (edge, (char*)"category")); #endif + XBT_DEBUG("add output -- adding %s to the dict as new file", name); xbt_dict_set(files, name, file, NULL); } else { + XBT_WARN("%s already exists", name); if (SD_task_get_amount(file) != size) { XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f", name, SD_task_get_amount(file), size);