Make TcGenDeriv warning-free
[ghc-hetmet.git] / utils / parallel / SPLIT.pl
1 #!/usr/local/bin/perl
2 #                                           (C) Hans Wolfgang Loidl, July 1995
3 #############################################################################
4 # Time-stamp: <Thu Oct 26 1995 18:23:00 Stardate: [-31]6498.62 hwloidl>
5 #
6 # Usage: SPLIT [options] <gr-file>
7 #
8 # Generate a set of granularity graphs out of the GrAnSim profile <gr-file>.
9 # The granularity graphs are put into subdirs of the structure: 
10 #   <basename of gr-file>-<spark-name>
11 #
12 # Options:
13 #  -s <list> ... a perl list of spark names; the given <gr-file> is scanned 
14 #                for each given name in turn and granularity graphs are 
15 #                generated for each of these sparks  
16 #  -O        ... use gr2RTS and RTS2gran instead of gran-extr;
17 #                this generates fewer output files (only granularity graphs)
18 #                but should be faster and far less memory consuming
19 #  -d <dir>  ... use <dir> as basename for the sub-directories
20 #  -o <file> ... use <file> as basename for the generated latex files; 
21 #                the overall result is in  <file>.ps
22 #  -t <file> ... use <file> as gran-extr type template file 
23 #                ('.' for local template, ',' for global template)
24 #  -A        ... surpress generation of granularity profiles for overall .gr
25 #  -h        ... help; print this text.
26 #  -v        ... verbose mode.
27 #
28 #############################################################################
29
30 require "getopts.pl";
31
32 &Getopts('hvOAd:o:s:t:');  
33
34 do process_options();
35
36 if ( $opt_v ) { do print_verbose_message(); }
37
38 # ---------------------------------------------------------------------------
39 # Init
40 # ---------------------------------------------------------------------------
41
42 $latex = "/usr/local/tex/bin/latex2e"; # or "/usr/local/tex/bin/latex2e"
43
44 do all()  if !$opt_A;
45
46 foreach $s (@sparks) {
47     if ( -f $tmp_file ) { system "rm -f $tmp_file"; }
48     system "tf -H -s $s $gr_file > $tmp_file" 
49         || die "Can't open pipe: tf -s $s $gr_file > $tmp_file\n";
50
51     if ( $opt_d ) {
52         $dir = $opt_d;          
53     } else {
54         $dir = $gr_file;
55     }
56     $dir =~ s/\.gr//g;
57     $dir .= "-$s";
58
59     if ( ! -d $dir ) {
60         mkdir($dir,"755");   # system "mkdir $dir";
61         system "chmod u+rwx $dir";
62     }
63
64     system "mv $tmp_file $dir/$gr_file";
65     chdir $dir;             
66     do print_template();
67     do print_va("Title",$s);
68     if ( -f $va_ps_file ) { 
69         local ($old) = $va_ps_file;
70         $old =~ s/\.ps/-o.ps/g;
71         system "mv $va_ps_file $old";
72     }
73     if ( $opt_O ) {
74         system "gr2RTS -o $rts_file $gr_file; " .
75                "RTS2gran -t $template_file $rts_file; " . 
76                "$latex $va_file; dvips $va_dvi_file > $va_ps_file"; 
77     } else {
78         system "gran-extr -t $template_file $gr_file; " . 
79             "$latex $va_file; dvips $va_dvi_file > $va_ps_file"; 
80     }
81     chdir "..";  # system "cd ..";
82 }
83
84 exit 0;
85
86 # -----------------------------------------------------------------------------
87
88 sub all {
89
90     $dir = $gr_file;
91     $dir =~ s/\.gr//g;
92     $dir .= "-all";
93
94     if ( ! -d $dir ) {
95         mkdir($dir,"755");   # system "mkdir $dir";
96         system "chmod u+rwx $dir";
97     }
98
99     system "cp $gr_file $dir/$gr_file";
100     chdir $dir;             
101     do print_template();
102     do print_va("All","all");
103     if ( -f $va_ps_file ) { 
104         local ($old) = $va_ps_file;
105         $old =~ s/\.ps/-o.ps/g;
106         system "mv $va_ps_file $old";
107     }
108     if ( $opt_O ) {
109         system "gr2RTS -o $rts_file $gr_file; " .
110                "RTS2gran -t $template_file $rts_file; " . 
111                "$latex $va_file; dvips $va_dvi_file > $va_ps_file"; 
112     } else {
113         system "gran-extr -t $template_file $gr_file; " . 
114             "$latex $va_file; dvips $va_dvi_file > $va_ps_file"; 
115     }
116     chdir "..";  # system "cd ..";
117 }
118
119 # ---------------------------------------------------------------------------
120
121 sub print_template {
122
123     open (TEMPL,">$template_file") || die "Can't open $template_file\n";
124
125     print TEMPL <<EOF;
126 -- Originally copied from the master template: GrAn/bin/TEMPL 
127 -- Intervals for pure exec. times
128 G: (1000, 2000, 3000, 4000, 5000, 10000, 20000, 30000, 40000, 50000, 100000, 200000, 300000)
129 -- Intervals for communication (i.e. fetch)  times
130 F: (1000, 2000, 3000, 4000, 5000, 10000, 20000, 30000, 40000, 50000, 100000, 200000, 300000)
131 -- Intervals for communication percentages 
132 C: (0, 1, 2, 5, 8, 10, 20, 30, 40, 50, 100)
133 -- Intervals for no. of sparks
134 S: (1, 2, 5)
135 -- Intervals for heap allocations
136 A: (10,20,30,40,50,100,200,300,400,500,1000,2000,3000)
137 -- A: (100, 50000, 66000, 100000)
138
139
140 g: g.dat
141 f: f.dat
142 c: c.dat
143 s: s.dat
144 a: a.dat
145
146 -- Select file name corr coeff file
147 Xcorr:          CORR
148
149 -- Select file names for GNUPLOT data files for cumulative runtime and
150 -- cluster graphs
151 Xcumulat-rts:   cumu-rts.dat
152 Xcumulat-fts:   cumu-fts.dat
153 Xcumulat-has:   cumu-has.dat
154 Xcumulat-cps:   cumu-cps.dat
155 Xclust-rts:     clust-rts.dat
156 Xclust-has:     clust-has.dat
157 Xclust-cps:     clust-cps.dat
158
159 -- Select file names for GNUPLOT data files for per proc. runnable time
160 -- and per spark site runtime
161 Xpe:            pe.dat
162 Xsn:            sn.dat
163
164 -- Select file names for sorted lists of runtimes, heap allocs, number of
165 -- local and global sparks and communication percentage
166 XRTS:           RTS
167 XFTS:           FTS
168 XHAS:           HAS
169 XLSPS:          LSPS
170 XGSPS:          GSPS
171 XCPS:           CPS
172 XCCPS:          CPS
173
174 -- Std log scaling
175 L: .
176 -- ('g',"xy",'Cg',"xy",'Ca',"xy")
177
178 -- Gray level of impulses in the graph (0=black)
179 i: 0.3
180
181 -- Number of clusters
182 k: 2
183
184 -- Width of impulses (needed for gp-ext-imp)
185 e: 150
186
187 -- Input file
188 -- -: soda.gr
189 EOF
190
191     close(TEMPL);
192 }
193
194 # -----------------------------------------------------------------------------
195 # NB: different file must be generated for $opt_O and default setup.
196 # -----------------------------------------------------------------------------
197
198 sub print_va {
199     local ($title, $spark) = @_;
200
201     open (VA,">$va_file") || die "Can't open $va_file\n";
202
203     if ( $opt_O ) {
204     print VA <<EOF;
205 % Originally copied from master va-file: grasp/tests/va.tex
206 \\documentstyle[11pt,psfig]{article}
207
208 % Page Format
209 \\topmargin=0cm                %0.5cm
210 \\textheight=24cm                %22cm
211 \\footskip=0cm
212 \\oddsidemargin=0cm            %0.75cm
213 \\evensidemargin=0cm           %0.75cm
214 \\rightmargin=0cm            %0.75cm
215 \\leftmargin=0cm            %0.75cm
216 \\textwidth=16cm                 %14.5cm
217
218 \\title{SPLIT}
219 \\author{Me}
220 \\date{Today}
221
222 \\pssilent
223
224 \\begin{document}
225
226 \\pagestyle{empty}
227 \%\\maketitle
228
229 \\nopagebreak
230
231 \\begin{figure}[t]
232 \\begin{center}
233 \\begin{tabular}{c}
234 \\centerline{\\psfig{angle=270,width=7cm,file=$gran_file}}
235 \\end{tabular}
236 \\end{center}
237 \\caption{Granularity {\\bf $spark}}
238 \\end{figure}
239
240 \\begin{figure}[t]
241 \\begin{center}
242 \\begin{tabular}{cc}
243 \\psfig{angle=270,width=7cm,file=cumu-rts.ps} &
244 \\psfig{angle=270,width=7cm,file=cumu-rts0.ps}
245 \\end{tabular}
246 \\end{center}
247 \\caption{Cumulative Execution Times  {\\bf $spark}}
248 \\end{figure}
249
250 \\end{document}
251 EOF
252     } else {
253     print VA <<EOF;
254 % Originally copied from master va-file: grasp/tests/va.tex
255 \\documentstyle[11pt,psfig]{article}
256
257 % Page Format
258 \\topmargin=0cm                %0.5cm
259 \\textheight=24cm                %22cm
260 \\footskip=0cm
261 \\oddsidemargin=0cm            %0.75cm
262 \\evensidemargin=0cm           %0.75cm
263 \\rightmargin=0cm            %0.75cm
264 \\leftmargin=0cm            %0.75cm
265 \\textwidth=16cm                 %14.5cm
266
267 \\title{$title; Spark: $spark}
268 \\author{}
269 \\date{}
270
271 \\begin{document}
272
273 \\pagestyle{empty}
274 %\\maketitle
275
276 \\nopagebreak
277
278 \\begin{figure}[t]
279 \\begin{center}
280 \\begin{tabular}{cc}
281 \\psfig{angle=270,width=7cm,file=$gran_file} &
282 \\psfig{angle=270,width=7cm,file=a.ps}
283 \\end{tabular}
284 \\end{center}
285 \\caption{Granularity \\& Heap Allocations {\\bf $spark}}
286 \\end{figure}
287
288 \\begin{figure}[t]
289 \\begin{center}
290 \\begin{tabular}{cc}
291 \\psfig{angle=270,width=7cm,file=f.ps} &
292 \\psfig{angle=270,width=7cm,file=c.ps}
293 \\end{tabular}
294 \\end{center}
295 \\caption{Fetching Profile  {\\bf $spark}}
296 \\end{figure}
297
298 \\begin{figure}[t]
299 \\begin{center}
300 \\begin{tabular}{cc}
301 \\psfig{angle=270,width=7cm,file=cumu-rts.ps} &
302 \\psfig{angle=270,width=7cm,file=cumu-rts0.ps}
303 \\end{tabular}
304 \\end{center}
305 \\caption{Cumulative Execution Times  {\\bf $spark}}
306 \\end{figure}
307
308 \\end{document}
309 EOF
310 }
311     close (VA);
312 }
313
314 # -----------------------------------------------------------------------------
315
316 sub process_options {
317
318     if ( $opt_h ) {                      
319         open(ME,$0) || die "Can't open myself ($0): $!\n";
320         $n = 0;
321         while (<ME>) {
322             last if $_ =~ /^$/;
323             print $_;
324             $n++;
325         }
326         close(ME);
327         exit ;
328     }
329     
330     if ( $opt_s ) {
331         $opt_s =~ s/[\(\)\[\]]//g;
332         @sparks = split(/[,;. ]+/, $opt_s);
333     } else {
334         @sparks = ( 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15);
335     }
336
337     if ( $#ARGV != 0 ) {
338         print "Usage: $0 [options] <gr-file>\n;";
339         print "Use -h option to get details\n";
340         exit 1;
341     }
342
343     $gr_file = $ARGV[0];
344     ($basename = $gr_file) =~ s/\.gr//;
345     $rts_file = $basename . ".rts";        # "RTS";
346     $gran_file = "g.ps"; # $basename . ".ps";
347     #$rts_file = $gr_file;
348     #$rts_file =~ s/\.gr/.rts/g;
349
350     if ( $opt_o ) {
351         $va_file = $opt_o;
352         $va_dvi_file = $va_file;
353         $va_dvi_file =~ s/\.tex/.dvi/g; 
354         $va_ps_file = $va_file;
355         $va_ps_file =~ s/\.tex/.ps/g; 
356     } else {
357         $va_file = "va.tex";
358         $va_dvi_file = "va.dvi";
359         $va_ps_file = "va.ps";
360     }
361     
362     if ( $opt_t ) {
363         $template_file = $opt_t;
364     } else {
365         $template_file = "TEMPL";
366     }
367
368     $tmp_file = ",t";
369 }
370
371 # -----------------------------------------------------------------------------
372
373 sub print_verbose_message {
374     print "Sparks: (" . join(',',@sparks) . ")\n";
375     print "Files: .gr " . $gr_file . "  template " . $template_file .
376             " va " . $va_file . "\n";
377 }
378
379 # -----------------------------------------------------------------------------