-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart-build.pl
executable file
·548 lines (445 loc) · 13.1 KB
/
smart-build.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#!/usr/bin/perl
# This is an interactive script that knows
# common ways to build Charm++ and AMPI.
#
# Authors: dooley, becker
use strict;
use warnings;
# Turn off I/O buffering
$| = 1;
# A subroutine that reads from input and returns a yes/no/default
sub promptUserYN {
while(my $line = <>){
chomp $line;
if(lc($line) eq "y" || lc($line) eq "yes" ){
return "yes";
} elsif(lc($line) eq "n" || lc($line) eq "no" ){
return "no";
} elsif( $line eq "" ){
return "default";
}
}
}
# The beginning of the good stuff:
print "\n============================================================\n";
print "\nBegin interactive charm configuration ...\n";
print "If you are a poweruser expecting a list of options, please use ./build --help\n";
print "\n============================================================\n\n\n";
# Use uname to get the cpu type and OS information
my $os = `uname -s`;
my $cpu = `uname -m`;
#Variables to hold the portions of the configuration:
my $nobs = "";
my $arch = "";
my $compilers = "";
my $options = "";
#remove newlines from these strings:
chomp($os);
chomp ($cpu);
my $arch_os;
# Determine OS kernel
if ($os eq "Linux") {
$arch_os = "linux";
} elsif ($os eq "Darwin") {
$arch_os = "darwin";
} elsif ($os =~ m/BSD/ ) {
$arch_os = "linux";
} elsif ($os =~ m/OSF1/ ) {
$arch_os = "linux";
} elsif ($os =~ m/AIX/ ) {
$arch = "mpi-sp";
} elsif ($os =~ m/CYGWIN/ ) {
print "Detected a Cygwin system\n";
print "This uses the gnu compiler by default,\n";
print "To build with Microsoft Visual C++ compiler, use net-win32. Please refer to README.win32 for the details on setting up VC++ under cygwin.\n\n";
$arch_os = "cygwin";
}
my $x86;
my $amd64;
my $ia64;
my $ppc;
my $alpha;
# Determine architecture (x86, ppc, ...)
if($cpu =~ m/i[0-9]86/){
$x86 = 1;
} elsif($cpu =~ m/x86\_64/){
$amd64 = 1;
} elsif($cpu =~ m/ia64/){
$ia64 = 1;
$nobs = "--no-build-shared";
} elsif($cpu =~ m/powerpc/){
$ppc = 1;
} elsif($cpu =~ m/Power Mac/){
$ppc = 1;
} elsif($cpu =~ m/ppc*/){
$ppc = 1;
} elsif($cpu =~ m/alpha/){
$alpha = 1;
}
# default to netlrts
my $converse_network_type = "netlrts";
my $skip_choosing = "false";
print "Are you building to run just on the local machine, and not across multiple nodes? [";
if($arch_os eq "darwin") {
print "Y/n]\n";
} else {
print "y/N]\n";
}
{
my $p = promptUserYN();
if($p eq "yes" || ($arch_os eq "darwin" && $p eq "default")){
$converse_network_type = "multicore";
$skip_choosing = "true";
}
}
# check for MPI
my $mpi_found = "false";
my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
my $mpioption;
if($m == 0){
$mpi_found = "true";
$mpioption = "";
}
$m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
if($m == 0){
$mpi_found = "true";
$mpioption = "mpicxx";
}
# Give option of just using the mpi version if mpicc and mpiCC are found
if($skip_choosing eq "false" && $mpi_found eq "true"){
print "\nI found that you have an mpicc available in your path.\nDo you want to build Charm++ on this MPI? [y/N]: ";
my $p = promptUserYN();
if($p eq "yes"){
$converse_network_type = "mpi";
$skip_choosing = "true";
$options = "$options $mpioption";
}
}
if($skip_choosing eq "false") {
print "\nDo you have a special network interconnect? [y/N]: ";
my $p = promptUserYN();
if($p eq "yes"){
print << "EOF";
Choose an interconnect from below: [1-10]
1) MPI
2) Infiniband (ibverbs)
3) Cray XE, XK
4) Cray XC
5) Blue Gene/P Native
6) Blue Gene/P MPI
7) Blue Gene/Q
EOF
while(my $line = <>){
chomp $line;
if($line eq "1"){
$converse_network_type = "mpi";
last;
} elsif($line eq "2"){
$converse_network_type = "verbs";
last;
} elsif($line eq "3"){
$arch = "gni-crayxe";
last;
} elsif($line eq "4"){
$arch = "gni-crayxc";
last;
} elsif($line eq "5"){
$arch = "bluegenep";
$compilers = "xlc ";
last;
} elsif($line eq "6"){
$arch = "mpi-bluegenep";
$compilers = "xlc ";
last;
} elsif($line eq "7"){
$arch = "pamilrts-bluegeneq";
last;
} else {
print "Invalid option, please try again :P\n"
}
}
}
}
# construct an $arch string if we did not explicitly set one above
if($arch eq ""){
$arch = "${converse_network_type}-${arch_os}";
if($amd64) {
$arch = $arch . "-x86_64";
} elsif($ia64){
$arch = $arch . "-ia64";
} elsif($ppc){
$arch = $arch . "-ppc";
} elsif($alpha){
$arch = $arch . "-axp";
}
}
# Fixup $arch to match the inconsistent directories in src/archs
if($arch eq "net-darwin"){
$arch = "net-darwin-x86";
} elsif($arch eq "net-ppc-darwin"){
$arch = "net-darwin-ppc";
} elsif($arch eq "mpi-ppc-darwin"){
$arch = "mpi-darwin-ppc";
} elsif($arch eq "multicore-linux-x86_64"){
$arch = "multicore-linux64";
}
#================ Choose SMP/PXSHM =================================
# find what options are available
my $opts = `./build charm++ $arch help 2>&1 | grep "Supported options"`;
$opts =~ m/Supported options: (.*)/;
$opts = $1;
my $smp_opts = <<EOF;
1) single-threaded [default]
EOF
# only add the smp or pxshm options if they are available
my $counter = 1; # the last index used in the list
my $smpIndex = -1;
if($opts =~ m/smp/){
$counter ++;
$smp_opts = $smp_opts . " $counter) SMP\n";
$smpIndex = $counter;
}
my $pxshmIndex = -1;
if($opts =~ m/pxshm/){
$counter ++;
$smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
$pxshmIndex = $counter;
}
if ($counter != 1) {
print "How do you want to handle SMP/Multicore: [1-$counter]\n";
print $smp_opts;
while(my $line = <>){
chomp $line;
if($line eq "" || $line eq "1"){
last;
} elsif($line eq $smpIndex){
$options = "$options smp ";
last;
} elsif($line eq $pxshmIndex){
$options = "$options pxshm ";
last;
}
}
}
#================ Choose Compiler =================================
# Lookup list of compilers
my $cs = `./build charm++ $arch help 2>&1 | grep "Supported compilers"`;
# prune away beginning of the line
$cs =~ m/Supported compilers: (.*)/;
$cs = $1;
# split the line into an array
my @c_list = split(" ", $cs);
# print list of compilers
my $numc = @c_list;
if ($numc > 0) {
print "\nDo you want to specify a compiler? [y/N]";
my $p = promptUserYN();
if($p eq "yes" ){
print "Choose a compiler: [1-$numc] \n";
my $i = 1;
foreach my $c (@c_list){
print "\t$i)\t$c\n";
$i++;
}
# Choose compiler
while(my $line = <>){
chomp $line;
if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
$compilers = $c_list[$1-1];
last;
} else {
print "Invalid option, please try again :P\n"
}
}
}
}
#================ Choose Options =================================
#Create a hash table containing descriptions of various options
my %explanations = ();
$explanations{"ooc"} = "Out-of-core execution support in Charm++";
$explanations{"tcp"} = "Charm++ over TCP instead of UDP for net versions. TCP is slower";
$explanations{"ifort"} = "Use Intel's ifort fortran compiler";
$explanations{"gfortran"} = "Use gfortran compiler for fortran";
$explanations{"g95"} = "Use g95 compiler";
$explanations{"ifort"} = "Use Intel's ifort fortran compiler";
$explanations{"pgf90"} = "Use Portland Group's pgf90 fortran compiler";
$explanations{"ifc"} = "Use Intel's ifc compiler";
$explanations{"ammasso"} = "Use native RDMA support on Ammasso interconnect";
$explanations{"syncft"} = "Use initial fault tolerance support";
$explanations{"mlogft"} = "Use message logging fault tolerance support";
$explanations{"causalft"} = "Use causal message logging fault tolerance support";
# Produce list of options
$opts = `./build charm++ $arch help 2>&1 | grep "Supported options"`;
# prune away beginning of line
$opts =~ m/Supported options: (.*)/;
$opts = $1;
my @option_list = split(" ", $opts);
# Prune out entries that would already have been chosen above, such as smp
my @option_list_pruned = ();
foreach my $o (@option_list){
if($o ne "smp" && $o ne "ibverbs" && $o ne "gm" && $o ne "mx"){
@option_list_pruned = (@option_list_pruned , $o);
}
}
# sort the list
@option_list_pruned = sort @option_list_pruned;
if (@option_list_pruned > 0) {
print "\nDo you want to specify any Charm++ build options, such as fortran compilers? [y/N]";
my $special_options = promptUserYN();
if($special_options eq "yes"){
# print out list for user to select from
print "Please enter one or more numbers separated by spaces\n";
print "Choices:\n";
my $i = 1;
foreach my $o (@option_list_pruned){
my $exp = $explanations{$o};
print "\t$i)\t$o";
# pad whitespace before options
for(my $j=0;$j<20-length($o);$j++){
print " ";
}
print ": $exp";
print "\n";
$i++;
}
print "\t$i)\tNone Of The Above\n";
my $num_options = @option_list_pruned;
while(my $line = <>){
chomp $line;
$line =~ m/([0-9 ]*)/;
my @entries = split(" ",$1);
@entries = sort(@entries);
my $additional_options = "";
foreach my $e (@entries) {
if($e>=1 && $e<= $num_options){
my $estring = $option_list_pruned[$e-1];
$additional_options = "$additional_options $estring";
} elsif ($e == $num_options+1){
# user chose "None of the above"
# clear the options we may have seen before
$additional_options = " ";
}
}
# if the user input something reasonable, we can break out of this loop
if($additional_options ne ""){
$options = "$options ${additional_options} ";
last;
}
}
}
}
# Choose compiler flags
print << "EOF";
Choose a set of compiler flags [1-5]
1) none
2) debug mode -g -O0
3) production build [default] --with-production
4) production build w/ projections --with-production --enable-tracing
5) custom
EOF
my $compiler_flags = "";
while(my $line = <>){
chomp $line;
if($line eq "1"){
last;
} elsif($line eq "2"){
$compiler_flags = "-g -O0";
last;
} elsif($line eq "4" ){
$compiler_flags = "--with-production --enable-tracing";
last;
} elsif($line eq "3" || $line eq ""){
$compiler_flags = "--with-production";
last;
} elsif($line eq "5"){
print "Enter compiler options: ";
my $input_line = <>;
chomp($input_line);
$compiler_flags = $input_line;
last;
} else {
print "Invalid option, please try again :P\n"
}
}
# Determine the target to build.
# We want this simple so we just give 2 options
my $target = "";
print << "EOF";
What do you want to build?
1) Charm++ [default] (choose this if you are building NAMD)
2) Charm++, AMPI, ParFUM, FEM and other libraries
EOF
while(my $line = <>){
chomp $line;
if($line eq "1" || $line eq ""){
$target = "charm++";
last;
} elsif($line eq "2"){
$target = "LIBS";
last;
} else {
print "Invalid option, please try again :P\n"
}
}
# Determine whether to use a -j flag for faster building
my $j = "";
print << "EOF";
Do you want to compile in parallel?
1) No
2) Build with -j2
3) Build with -j4
4) Build with -j8
5) Build with -j16 [default]
6) Build with -j32
7) Build with -j
EOF
while(my $line = <>) {
chomp $line;
if($line eq "1"){
$j = "";
last;
} elsif($line eq "2") {
$j = "-j2";
last;
} elsif($line eq "3") {
$j = "-j4";
last;
} elsif($line eq "4") {
$j = "-j8";
last;
} elsif($line eq "5" || $line eq "") {
$j = "-j16";
last;
} elsif($line eq "6") {
$j = "-j32";
last;
} elsif($line eq "7") {
$j = "-j";
last;
} else {
print "Invalid option, please try again :P\n";
}
}
# Compose the build line
my $build_line = "./build $target $arch $compilers $options $j $nobs ${compiler_flags}\n";
# Save the build line in the log
open(BUILDLINE, ">>smart-build.log");
print BUILDLINE `date`;
print BUILDLINE "Using the following build command:\n";
print BUILDLINE "$build_line\n";
close(BUILDLINE);
print "We have determined a suitable build line is:\n";
print "\t$build_line\n\n";
# Execute the build line if the appropriate architecture directory exists
print "Do you want to start the build now? [Y/n]";
my $p = promptUserYN();
if($p eq "yes" || $p eq "default"){
if(-e "src/arch/$arch"){
print "Building with: ${build_line}\n";
# Execute the build line
system($build_line);
} else {
print "We could not figure out how to build charm with those options on this platform, please manually build\n";
print "Try something similar to: ${build_line}\n";
}
}