1 /* Copyright (c) 2009 Da SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simdag/simdag.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd,"Parsing DAX files");
19 static void dax_parse_error(char *msg) {
20 fprintf(stderr, "Parse error on line %d: %s\n", dax_lineno, msg);
23 static double dax_parse_double(const char *string) {
27 ret = sscanf(string, "%lg", &value);
29 dax_parse_error(bprintf("%s is not a double", string));
32 static int dax_parse_int(const char *string) {
36 ret = sscanf(string, "%d", &value);
38 dax_parse_error(bprintf("%s is not an integer", string));
42 static YY_BUFFER_STATE input_buffer;
44 static xbt_dynar_t result;
45 static xbt_dict_t files;
46 static SD_task_t current_job;
47 static SD_task_t root_task,end_task;
49 static void dump_res() {
52 xbt_dynar_foreach(result,cursor,task) {
53 INFO1("Task %d",cursor);
58 static void dax_task_free(void*task){
63 xbt_dynar_t SD_daxload(const char*filename) {
64 FILE* in_file = fopen(filename,"r");
65 xbt_assert1(in_file, "Unable to open \"%s\"\n", filename);
66 input_buffer = dax__create_buffer(in_file, 10);
67 dax__switch_to_buffer(input_buffer);
70 result = xbt_dynar_new(sizeof(SD_task_t),dax_task_free);
72 root_task = SD_task_create_comp_seq("root",NULL,0);
73 xbt_dynar_push(result,&root_task);
74 end_task = SD_task_create_comp_seq("end",NULL,0);
76 xbt_assert2(!dax_lex(),"Parse error in %s: %s",filename,dax__parse_err_msg());
77 dax__delete_buffer(input_buffer);
80 /* And now, post-process the files.
81 * We want a file task per pair of computation tasks exchanging the file. Dupplicate on need
82 * Files not produced in the system are said to be produced by root task (top of DAG).
83 * Files not consumed in the system are said to be consumed by end task (bottom of DAG).
85 xbt_dict_cursor_t cursor;
88 xbt_dict_foreach(files,cursor,name,file) {
89 unsigned int cpt1,cpt2;
90 SD_dependency_t depbefore,depafter;
91 if (xbt_dynar_length(file->tasks_before) == 0) {
92 xbt_dynar_foreach(file->tasks_after,cpt2,depafter) {
93 SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount);
94 SD_task_dependency_add(NULL,NULL,root_task,newfile);
95 SD_task_dependency_add(NULL,NULL,newfile,depafter->dst);
96 xbt_dynar_push(result,&newfile);
98 } else if (xbt_dynar_length(file->tasks_after) == 0) {
99 xbt_dynar_foreach(file->tasks_before,cpt2,depbefore) {
100 SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount);
101 SD_task_dependency_add(NULL,NULL,depbefore->src,newfile);
102 SD_task_dependency_add(NULL,NULL,newfile,end_task);
103 xbt_dynar_push(result,&newfile);
106 xbt_dynar_foreach(file->tasks_before,cpt1,depbefore) {
107 xbt_dynar_foreach(file->tasks_after,cpt2,depafter) {
108 SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount);
109 SD_task_dependency_add(NULL,NULL,depbefore->src,newfile);
110 SD_task_dependency_add(NULL,NULL,newfile,depafter->dst);
111 xbt_dynar_push(result,&newfile);
117 /* Push end task last */
118 xbt_dynar_push(result,&end_task);
120 /* Free previous copy of the files */
121 xbt_dict_free(&files);
126 void STag_dax__adag(void) {
127 double version = dax_parse_double(A_dax__adag_version);
129 xbt_assert1((version == 2.1), "Expected version 2.1 in <adag> tag, got %f. Fix the parser or your file",version);
131 void STag_dax__job(void) {
132 double runtime = dax_parse_double(A_dax__job_runtime);
133 char *name=bprintf("%s@%s",A_dax__job_id,A_dax__job_name);
134 runtime*=4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */
135 // INFO3("See <job id=%s runtime=%s %.0f>",A_dax__job_id,A_dax__job_runtime,runtime);
136 current_job = SD_task_create_comp_seq(name,NULL,runtime);
138 xbt_dynar_push(result,¤t_job);
141 void STag_dax__child(void) {
142 // INFO0("See <child>");
144 void STag_dax__parent(void) {
145 // INFO0("See <parent>");
147 void STag_dax__uses(void) {
149 double size = dax_parse_double(A_dax__uses_size);
150 int is_input = (A_dax__uses_link == A_dax__uses_link_input);
152 // INFO2("See <uses file=%s %s>",A_dax__uses_file,(is_input?"in":"out"));
153 file = xbt_dict_get_or_null(files,A_dax__uses_file);
155 file = SD_task_create_comm_e2e(A_dax__uses_file,NULL,size);
156 xbt_dict_set(files,A_dax__uses_file,file,&dax_task_free);
158 if (SD_task_get_amount(file)!=size) {
159 WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
160 A_dax__uses_file,SD_task_get_amount(file),size);
164 SD_task_dependency_add(NULL,NULL,file,current_job);
166 SD_task_dependency_add(NULL,NULL,current_job,file);
167 if (xbt_dynar_length(file->tasks_before)>1) {
168 WARN1("File %s created at more than one location...",file->name);
172 void ETag_dax__adag(void) {
173 // INFO0("See </adag>");
175 void ETag_dax__job(void) {
177 // INFO0("See </job>");
179 void ETag_dax__child(void) {
180 // INFO0("See </child>");
182 void ETag_dax__parent(void) {
183 // INFO0("See </parent>");
185 void ETag_dax__uses(void) {
186 // INFO0("See </uses>");