Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a script to generate a strassen workflow (+cosmetics on other script)
[simgrid.git] / examples / simdag / dax / generate_strassen.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 sub job {
6     print "<job id=\"$_[0]\" namespace=\"$_[1]\" name=\"$_[2]\" version=\"1.0\" runtime=\"$_[3]\">\n";
7 }
8 sub file {
9     print "  <uses file=\"$_[0]\" link=\"$_[1]\" register=\"true\" transfer=\"true\" optional=\"false\" type=\"data\" size=\"$_[2]\"/>\n";
10 }
11 sub strassen {
12     my $matSize=shift;
13     my $max_level=shift||1;
14     my $level=shift||1;
15     my $A = shift||"A";
16     my $B = shift||"B";
17
18     if ($level<$max_level) {
19       die "Recursive Strassen don't work yet\n";
20     }
21     
22     my $sizeAdd=$matSize*$matSize/4;
23     my $sizeMult=$matSize*$matSize*$matSize/8;
24     my $sizeBlock=$sizeAdd;
25
26     # T1 = A11 + A22
27     job("T1","Strassen","l$level",$sizeAdd);
28     file("${A}11l$level","input",$sizeBlock);
29     file("${A}22l$level","input",$sizeBlock);
30     file("T1l$level","output",$sizeBlock);
31     print("</job>\n");
32
33     # T2 = A21 + A22
34     job("T2","Strassen","l$level",$sizeAdd);
35     file("${A}21l$level","input",$sizeBlock);
36     file("${A}22l$level","input",$sizeBlock);
37     file("T2l$level","output",$sizeBlock);
38     print("</job>\n");
39
40     # T3 = A11 + A12
41     job("T3","Strassen","l$level",$sizeAdd);
42     file("${A}11l$level","input",$sizeBlock);
43     file("${A}12l$level","input",$sizeBlock);
44     file("T3l$level","output",$sizeBlock);
45     print("</job>\n");
46
47     # T4 = A21 − A11
48     job("T4","Strassen","l$level",$sizeAdd);
49     file("${A}21l$level","input",$sizeBlock);
50     file("${A}11l$level","input",$sizeBlock);
51     file("T4l$level","output",$sizeBlock);
52     print("</job>\n");
53
54     # T5 = A12 − A22
55     job("T5","Strassen","l$level",$sizeAdd);
56     file("${A}12l$level","input",$sizeBlock);
57     file("${A}22l$level","input",$sizeBlock);
58     file("T5l$level","output",$sizeBlock);
59     print("</job>\n");
60     
61     # T6 = B11 + B22
62     job("T6","Strassen","l$level",$sizeAdd);
63     file("${B}11l$level","input",$sizeBlock);
64     file("${B}22l$level","input",$sizeBlock);
65     file("T6l$level","output",$sizeBlock);
66     print("</job>\n");
67     
68     # T7 = B12 − B22
69     job("T7","Strassen","l$level",$sizeAdd);
70     file("${B}12l$level","input",$sizeBlock);
71     file("${B}22l$level","input",$sizeBlock);
72     file("T7l$level","output",$sizeBlock);
73     print("</job>\n");
74     
75     # T8 = B21 − B11
76     job("T8","Strassen","l$level",$sizeAdd);
77     file("${B}21l$level","input",$sizeBlock);
78     file("${B}11l$level","input",$sizeBlock);
79     file("T8l$level","output",$sizeBlock);
80     print("</job>\n");
81          
82     # T9 = B11 + B12
83     job("T9","Strassen","l$level",$sizeAdd);
84     file("${B}11l$level","input",$sizeBlock);
85     file("${B}12l$level","input",$sizeBlock);
86     file("T9l$level","output",$sizeBlock);
87     print("</job>\n");
88     
89     # T10 = B21 + B22
90     job("T10","Strassen","l$level",$sizeAdd);
91     file("${B}21l$level","input",$sizeBlock);
92     file("${B}22l$level","input",$sizeBlock);
93     file("T10l$level","output",$sizeBlock);
94     print("</job>\n");
95
96     # Q1 = T1 × T6
97     if ($level<$max_level) {
98         strassen($sizeBlock,$max_level,$level+1,"T1_","T6_");
99     } else {
100         job("Q1","Strassen","l$level",$sizeMult);
101         file("T1l$level","input",$sizeBlock);
102         file("T6l$level","input",$sizeBlock);
103         file("Q1l$level","output",$sizeBlock);
104         print("</job>\n");
105     }
106
107     # Q2 = T2 × B11
108     if ($level<$max_level) {
109         strassen($sizeBlock,$max_level,$level+1,"T2_","B11_");
110     } else {
111         job("Q2","Strassen","l$level",$sizeMult);
112         file("T2l$level","input",$sizeBlock);
113         file("${B}11l$level","input",$sizeBlock);
114         file("Q2l$level","output",$sizeBlock);
115         print("</job>\n");
116     }
117
118     # Q3 = A11 × T7         
119     if ($level<$max_level) {
120         strassen($sizeBlock,$max_level,$level+1,"A11_","T7_");
121     } else {
122         job("Q3","Strassen","l$level",$sizeMult);
123         file("${A}11l$level","input",$sizeBlock);
124         file("T7l$level","input",$sizeBlock);
125         file("Q3l$level","output",$sizeBlock);
126         print("</job>\n");
127     }
128     
129     # Q4 = A22 × T8
130     if ($level<$max_level) {
131         strassen($sizeBlock,$max_level,$level+1,"A22_","T8_");
132     } else {
133         job("Q4","Strassen","l$level",$sizeMult);
134         file("${A}22l$level","input",$sizeBlock);
135         file("T8l$level","input",$sizeBlock);
136         file("Q4l$level","output",$sizeBlock);
137         print("</job>\n");
138     }
139     
140     # Q5 = T3 × B22
141     if ($level<$max_level) {
142         strassen($sizeBlock,$max_level,$level+1,"T3_","B22_");
143     } else {
144         job("Q5","Strassen","l$level",$sizeMult);
145         file("T3l$level","input",$sizeBlock);
146         file("${B}22l$level","input",$sizeBlock);
147         file("Q5l$level","output",$sizeBlock);
148         print("</job>\n");
149     }
150     
151     # Q6 = T4 × T9
152     if ($level<$max_level) {
153         strassen($sizeBlock,$max_level,$level+1,"T4_","T9_");
154     } else {
155         job("Q6","Strassen","l$level",$sizeMult);
156         file("T4l$level","input",$sizeBlock);
157         file("T9l$level","input",$sizeBlock);
158         file("Q6l$level","output",$sizeBlock);
159         print("</job>\n");
160     }
161     
162     # Q7 = T5 × T10
163     if ($level<$max_level) {
164         strassen($sizeBlock,$max_level,$level+1,"T5_","T10_");
165     } else {
166         job("Q7","Strassen","l$level",$sizeMult);
167         file("T5l$level","input",$sizeBlock);
168         file("T10l$level","input",$sizeBlock);
169         file("Q7l$level","output",$sizeBlock);
170         print("</job>\n");
171     }
172     
173     # C11 = Q1 + Q4 − Q5 + Q7
174     job("Q11","Strassen","l$level",$sizeAdd*3);
175     file("Q1l$level","input",$sizeBlock);
176     file("Q4l$level","input",$sizeBlock);
177     file("Q5l$level","input",$sizeBlock);
178     file("Q7l$level","input",$sizeBlock);
179     file("C11l$level","output",$sizeBlock);
180     print("</job>\n");
181
182     # C12 = Q3 + Q5
183     job("C12","Strassen","l$level",$sizeAdd);
184     file("Q3l$level","input",$sizeBlock);
185     file("Q5l$level","input",$sizeBlock);
186     file("C12l$level","output",$sizeBlock);
187     print("</job>\n");
188     
189     # C21 = Q2 + Q4
190     job("C21","Strassen","l$level",$sizeAdd);
191     file("Q2l$level","input",$sizeBlock);
192     file("Q4l$level","input",$sizeBlock);
193     file("C21l$level","output",$sizeBlock);
194     print("</job>\n");
195
196     # C22 = Q1 − Q2 + Q3 + Q6
197     job("C22","Strassen","l$level",$sizeMult);
198     file("Q1l$level","input",$sizeBlock);
199     file("Q2l$level","input",$sizeBlock);
200     file("Q3l$level","input",$sizeBlock);
201     file("Q6l$level","input",$sizeBlock);
202     file("C22l$level","output",$sizeBlock);
203     print("</job>\n");          
204 }
205
206 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
207 print "<!-- generated: ".(localtime())." -->\n";
208 print "<adag xmlns=\"http://pegasus.isi.edu/schema/DAX\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://pegasus.isi.edu/schema/DAX http://pegasus.isi.edu/schema/dax-2.1.xsd\" version=\"2.1\" count=\"1\" index=\"0\" name=\"test\" jobCount=\"25\" fileCount=\"0\" childCount=\"20\">\n";
209
210 strassen(2000);
211
212 print "</adag>\n";
213