-void Start_dot_job(Agnode_t *dag_node) {
- char *name = agnameof(dag_node);
- double runtime = parse_double(agget(dag_node,"size"));
- int performer = parse_int(agget(dag_node,"performer"));
- INFO3("See <job id=%s runtime=%s %.0f>",name,agget(dag_node,"size"),runtime);
- SD_task_t current_job = SD_task_create_comp_seq(name,(void*)performer,runtime);
- 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)) {
- input_edge(current_job,e);
- count++;
- }
- if (count==0){
- SD_task_t file;
- char *name="root->many";
- double size = 0;
-
- file = xbt_dict_get_or_null(files,name);
- if (file==NULL) {
- file = SD_task_create_comm_e2e(name,NULL,size);
- xbt_dict_set(files,name,file,&dot_task_free);
- } else {
- if (SD_task_get_amount(file)!=size) {
- WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
- name,SD_task_get_amount(file),size);
- }
- }
- SD_task_dependency_add(NULL,NULL,file,current_job);
- }
- count = 0;
- for (e = agfstout(dag_dot,dag_node); e; e = agnxtout(dag_dot,e)) {
- output_edge(current_job,e);
- count++;
- }
- if (count==0){
- SD_task_t file;
- char *name = "many->end";
- double size = 0;
-
- // INFO2("See <uses file=%s %s>",A_dot__uses_file,(is_input?"in":"out"));
- file = xbt_dict_get_or_null(files,name);
- if (file==NULL) {
- file = SD_task_create_comm_e2e(name,NULL,size);
- xbt_dict_set(files,name,file,&dot_task_free);
- } else {
- if (SD_task_get_amount(file)!=size) {
- WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
- name,SD_task_get_amount(file),size);
- }
- }
- SD_task_dependency_add(NULL,NULL,current_job,file);
- if (xbt_dynar_length(file->tasks_before)>1) {
- WARN1("File %s created at more than one location...",file->name);
- }
- }
+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(&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);
+ /* 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) {
+ unsigned int cpt1, cpt2;
+ SD_task_t newfile = NULL;
+ SD_dependency_t depbefore, depafter;
+ 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_dependency_add(NULL, NULL, root_task, newfile);
+ SD_task_dependency_add(NULL, NULL, newfile, depafter->dst);
+ xbt_dynar_push(result, &newfile);
+ }
+ } 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_dependency_add(NULL, NULL, depbefore->src, newfile);
+ SD_task_dependency_add(NULL, NULL, newfile, end_task);
+ xbt_dynar_push(result, &newfile);
+ }
+ } else {
+ xbt_dynar_foreach(file->tasks_before, cpt1, depbefore) {
+ xbt_dynar_foreach(file->tasks_after, cpt2, depafter) {
+ if (depbefore->src == depafter->dst) {
+ XBT_WARN
+ ("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.",
+ file->name, depbefore->src->name);
+ }
+ newfile =
+ SD_task_create_comm_e2e(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);
+ }
+ }
+ }
+ }
+
+ /* Push end task last */
+ xbt_dynar_push(result, &end_task);
+
+ /* Free previous copy of the files */
+ 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;