Logo AND Algorithmique Numérique Distribuée

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