Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
some more work on dax loader
[simgrid.git] / src / simdag / sd_daxloader.c
1 /* Copyright (c) 2009 Da SimGrid Team.  All rights reserved.                */
2
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. */
5
6 #include "private.h"
7 #include "simdag/simdag.h"
8 #include "xbt/misc.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd,"Parsing DAX files");
12
13 #undef CLEANUP
14 #include "dax_dtd.h"
15 #include "dax_dtd.c"
16
17
18 /* Parsing helpers */
19 static void dax_parse_error(char *msg) {
20   fprintf(stderr, "Parse error on line %d: %s\n", dax_lineno, msg);
21   abort();
22 }
23 static double dax_parse_double(const char *string) {
24   int ret = 0;
25   double value;
26
27   ret = sscanf(string, "%lg", &value);
28   if (ret != 1)
29     dax_parse_error(bprintf("%s is not a double", string));
30   return value;
31 }
32 static int dax_parse_int(const char *string) {
33   int ret = 0;
34   int value;
35
36   ret = sscanf(string, "%d", &value);
37   if (ret != 1)
38     dax_parse_error(bprintf("%s is not an integer", string));
39   return value;
40 }
41
42 static YY_BUFFER_STATE input_buffer;
43
44 static xbt_dynar_t result;
45 static xbt_dict_t files;
46 static SD_task_t current_job;
47
48 typedef struct {
49   xbt_dynar_t inputs;
50   xbt_dynar_t outputs;
51 } dax_comp_task;
52
53 typedef struct {
54   double size;
55 } dax_comm_task;
56
57 typedef struct {
58   short int is_comm_task;
59   union {
60     dax_comp_task comp;
61     dax_comm_task comm;
62   };
63 } *dax_task_t;
64
65 static void dax_task_rmdata(SD_task_t t) {
66
67 }
68
69 static void dax_task_free(void*task){
70   SD_task_t t=task;
71   SD_task_destroy(t);
72 }
73
74 xbt_dynar_t SD_daxload(const char*filename) {
75   SD_task_t task;
76   FILE* in_file = fopen(filename,"r");
77   xbt_assert1(in_file, "Unable to open \"%s\"\n", filename);
78   input_buffer = dax__create_buffer(in_file, 10);
79   dax__switch_to_buffer(input_buffer);
80   dax_lineno = 1;
81
82   result = xbt_dynar_new(sizeof(SD_task_t),dax_task_free);
83   files=xbt_dict_new();
84   task = SD_task_create("top",NULL,0);
85   xbt_dynar_push(result,&task);
86
87   xbt_assert2(!dax_lex(),"Parse error in %s: %s",filename,dax__parse_err_msg());
88   dax__delete_buffer(input_buffer);
89   xbt_dict_free(&files);
90   fclose(in_file);
91   return result;
92 }
93
94 void STag_dax__adag(void) {
95   double version = dax_parse_double(A_dax__adag_version);
96
97   xbt_assert1((version == 2.1), "Expected version 2.1 in <adag> tag, got %f. Fix the parser or your file",version);
98 }
99 void STag_dax__job(void) {
100   double runtime = dax_parse_double(A_dax__job_runtime);
101   runtime*=4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */
102   INFO3("See <job id=%s runtime=%s %.0f>",A_dax__job_id,A_dax__job_runtime,runtime);
103   current_job = SD_task_create(A_dax__job_id,NULL,runtime);
104   xbt_dynar_push(result,current_job);
105 }
106 void STag_dax__child(void) {
107 //  INFO0("See <child>");
108 }
109 void STag_dax__parent(void) {
110 //  INFO0("See <parent>");
111 }
112 void STag_dax__uses(void) {
113   SD_task_t file;
114   double size = dax_parse_double(A_dax__uses_size);
115   int is_input = (A_dax__uses_link == A_dax__uses_link_input);
116
117   INFO2("See <uses file=%s %s>",A_dax__uses_file,(is_input?"in":"out"));
118   file = xbt_dict_get_or_null(files,A_dax__uses_file);
119   if (file==NULL) {
120     file = SD_task_create(A_dax__uses_file,NULL,size);
121     xbt_dict_set(files,A_dax__uses_file,file,NULL);
122   } else {
123     if (SD_task_get_amount(file)!=size) {
124       WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
125           A_dax__uses_file,SD_task_get_amount(file),size);
126     }
127   }
128   if (is_input) {
129     SD_task_dependency_add(NULL,NULL,file,current_job);
130   } else {
131     SD_task_dependency_add(NULL,NULL,file,current_job);
132   }
133 }
134 void ETag_dax__adag(void) {
135 //  INFO0("See </adag>");
136 }
137 void ETag_dax__job(void) {
138   current_job = NULL;
139 //  INFO0("See </job>");
140 }
141 void ETag_dax__child(void) {
142 //  INFO0("See </child>");
143 }
144 void ETag_dax__parent(void) {
145 //  INFO0("See </parent>");
146 }
147 void ETag_dax__uses(void) {
148 //  INFO0("See </uses>");
149 }