CHANGES: Add release notes for 6.8.1
[charm.git] / smart-build.pl
blob271b2bb00c8ab5e0fffc3eedfbba9903b8d7b658
1 #!/usr/bin/env perl
4 # This is an interactive script that knows
5 # common ways to build Charm++ and AMPI.
7 # Authors: dooley, becker
9 use strict;
10 use warnings;
12 # Get location of script
13 use File::Basename;
14 my $dirname = dirname(__FILE__);
16 # Turn off I/O buffering
17 $| = 1;
21 # A subroutine that reads from input and returns a yes/no/default
22 sub promptUserYN {
23 while(my $line = <>){
24 chomp $line;
25 if(lc($line) eq "y" || lc($line) eq "yes" ){
26 return "yes";
27 } elsif(lc($line) eq "n" || lc($line) eq "no" ){
28 return "no";
29 } elsif( $line eq "" ){
30 return "default";
36 # The beginning of the good stuff:
37 print "\n============================================================\n";
38 print "\nBegin interactive charm configuration ...\n";
39 print "If you are a poweruser expecting a list of options, please use ./build --help\n";
40 print "\n============================================================\n\n\n";
43 # Use uname to get the cpu type and OS information
44 my $os = `uname -s`;
45 my $cpu = `uname -m`;
47 #Variables to hold the portions of the configuration:
48 my $nobs = "";
49 my $arch = "";
50 my $compilers = "";
51 my $options = "";
53 #remove newlines from these strings:
54 chomp($os);
55 chomp ($cpu);
57 my $arch_os;
58 # Determine OS kernel
59 if ($os eq "Linux") {
60 $arch_os = "linux";
61 } elsif ($os eq "Darwin") {
62 $arch_os = "darwin";
63 } elsif ($os =~ m/BSD/ ) {
64 $arch_os = "linux";
65 } elsif ($os =~ m/OSF1/ ) {
66 $arch_os = "linux";
70 my $x86;
71 my $amd64;
72 my $ppc;
73 my $arm7;
74 # Determine architecture (x86, ppc, ...)
75 if($cpu =~ m/i[0-9]86/){
76 $x86 = 1;
77 } elsif($cpu =~ m/x86\_64/){
78 $amd64 = 1;
79 } elsif($cpu =~ m/powerpc/){
80 $ppc = 1;
81 } elsif($cpu =~ m/ppc*/){
82 $ppc = 1;
83 } elsif($cpu =~ m/arm7/){
84 $arm7 = 1;
88 # default to netlrts
89 my $converse_network_type = "netlrts";
90 my $skip_choosing = "false";
92 print "Are you building to run just on the local machine, and not across multiple nodes? [";
93 if($arch_os eq "darwin") {
94 print "Y/n]\n";
95 } else {
96 print "y/N]\n";
99 my $p = promptUserYN();
100 if($p eq "yes" || ($arch_os eq "darwin" && $p eq "default")){
101 $converse_network_type = "multicore";
102 $skip_choosing = "true";
106 # check for MPI
108 my $mpi_found = "false";
109 my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
110 my $mpioption;
111 if($m == 0){
112 $mpi_found = "true";
113 $mpioption = "";
115 $m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
116 if($m == 0){
117 $mpi_found = "true";
118 $mpioption = "mpicxx";
121 # Give option of just using the mpi version if mpicc and mpiCC are found
122 if($skip_choosing eq "false" && $mpi_found eq "true"){
123 print "\nI found that you have an mpicc available in your path.\nDo you want to build Charm++ on this MPI? [y/N]: ";
124 my $p = promptUserYN();
125 if($p eq "yes"){
126 $converse_network_type = "mpi";
127 $skip_choosing = "true";
128 $options = "$options $mpioption";
132 if($skip_choosing eq "false") {
134 print "\nDo you have a special network interconnect? [y/N]: ";
135 my $p = promptUserYN();
136 if($p eq "yes"){
137 print << "EOF";
139 Choose an interconnect from below: [1-10]
140 1) MPI
141 2) Infiniband (ibverbs)
142 3) Cray XE, XK
143 4) Cray XC
144 5) Blue Gene/Q
145 6) Intel Omni-Path (ofi)
149 while(my $line = <>){
150 chomp $line;
151 if($line eq "1"){
152 $converse_network_type = "mpi";
153 last;
154 } elsif($line eq "2"){
155 $converse_network_type = "verbs";
156 last;
157 } elsif($line eq "3"){
158 $arch = "gni-crayxe";
159 last;
160 } elsif($line eq "4"){
161 $arch = "gni-crayxc";
162 last;
163 } elsif($line eq "5"){
164 $arch = "pamilrts-bluegeneq";
165 last;
166 } elsif($line eq "6"){
167 $converse_network_type = "ofi";
168 last;
169 } else {
170 print "Invalid option, please try again :P\n"
177 # construct an $arch string if we did not explicitly set one above
178 if($arch eq ""){
179 $arch = "${converse_network_type}-${arch_os}";
180 if($amd64) {
181 $arch = $arch . "-x86_64";
182 } elsif($ppc){
183 $arch = $arch . "-ppc";
184 } elsif($arm7){
185 $arch = $arch . "-arm7";
189 # Fixup $arch to match the inconsistent directories in src/archs
191 if($arch eq "netlrts-darwin"){
192 $arch = "netlrts-darwin-x86_64";
193 } elsif($arch eq "multicore-linux-arm7"){
194 $arch = "multicore-arm7";
198 #================ Choose SMP/PXSHM =================================
200 # find what options are available
201 my $opts = `$dirname/build charm++ $arch help 2>&1 | grep "Supported options"`;
202 $opts =~ m/Supported options: (.*)/;
203 $opts = $1;
205 my $smp_opts = <<EOF;
206 1) single-threaded [default]
209 # only add the smp or pxshm options if they are available
210 my $counter = 1; # the last index used in the list
212 my $smpIndex = -1;
213 if($opts =~ m/smp/){
214 $counter ++;
215 $smp_opts = $smp_opts . " $counter) SMP\n";
216 $smpIndex = $counter;
219 my $pxshmIndex = -1;
220 if($opts =~ m/pxshm/){
221 $counter ++;
222 $smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
223 $pxshmIndex = $counter;
226 if ($counter != 1) {
227 print "How do you want to handle SMP/Multicore: [1-$counter]\n";
228 print $smp_opts;
230 while(my $line = <>){
231 chomp $line;
232 if($line eq "" || $line eq "1"){
233 last;
234 } elsif($line eq $smpIndex){
235 $options = "$options smp ";
236 last;
237 } elsif($line eq $pxshmIndex){
238 $options = "$options pxshm ";
239 last;
245 #================ Choose Compiler =================================
247 # Lookup list of compilers
248 my $cs = `$dirname/build charm++ $arch help 2>&1 | grep "Supported compilers"`;
249 # prune away beginning of the line
250 $cs =~ m/Supported compilers: (.*)/;
251 $cs = $1;
252 # split the line into an array
253 my @c_list = split(" ", $cs);
255 # print list of compilers
256 my $numc = @c_list;
258 if ($numc > 0) {
259 print "\nDo you want to specify a compiler? [y/N]";
260 my $p = promptUserYN();
261 if($p eq "yes" ){
262 print "Choose a compiler: [1-$numc] \n";
264 my $i = 1;
265 foreach my $c (@c_list){
266 print "\t$i)\t$c\n";
267 $i++;
270 # Choose compiler
271 while(my $line = <>){
272 chomp $line;
273 if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
274 $compilers = $c_list[$1-1];
275 last;
276 } else {
277 print "Invalid option, please try again :P\n"
286 #================ Choose Options =================================
288 #Create a hash table containing descriptions of various options
289 my %explanations = ();
290 $explanations{"ooc"} = "Out-of-core execution support in Charm++";
291 $explanations{"tcp"} = "Charm++ over TCP instead of UDP for net versions. TCP is slower";
292 $explanations{"gfortran"} = "Use gfortran compiler for fortran";
293 $explanations{"ifort"} = "Use Intel's ifort fortran compiler";
294 $explanations{"pgf90"} = "Use Portland Group's pgf90 fortran compiler";
295 $explanations{"syncft"} = "Use fault tolerance support";
296 $explanations{"mlogft"} = "Use message logging fault tolerance support";
297 $explanations{"causalft"} = "Use causal message logging fault tolerance support";
303 # Produce list of options
305 $opts = `$dirname/build charm++ $arch help 2>&1 | grep "Supported options"`;
306 # prune away beginning of line
307 $opts =~ m/Supported options: (.*)/;
308 $opts = $1;
310 my @option_list = split(" ", $opts);
313 # Prune out entries that would already have been chosen above, such as smp
314 my @option_list_pruned = ();
315 foreach my $o (@option_list){
316 if($o ne "smp" && $o ne "ibverbs" && $o ne "gm" && $o ne "mx"){
317 @option_list_pruned = (@option_list_pruned , $o);
321 # sort the list
322 @option_list_pruned = sort @option_list_pruned;
323 if (@option_list_pruned > 0) {
325 print "\nDo you want to specify any Charm++ build options, such as fortran compilers? [y/N]";
326 my $special_options = promptUserYN();
328 if($special_options eq "yes"){
330 # print out list for user to select from
331 print "Please enter one or more numbers separated by spaces\n";
332 print "Choices:\n";
333 my $i = 1;
334 foreach my $o (@option_list_pruned){
335 my $exp = $explanations{$o};
336 print "\t$i)\t$o";
337 # pad whitespace before options
338 for(my $j=0;$j<20-length($o);$j++){
339 print " ";
341 print ": $exp";
342 print "\n";
343 $i++;
345 print "\t$i)\tNone Of The Above\n";
347 my $num_options = @option_list_pruned;
349 while(my $line = <>){
350 chomp $line;
351 $line =~ m/([0-9 ]*)/;
352 my @entries = split(" ",$1);
353 @entries = sort(@entries);
355 my $additional_options = "";
356 foreach my $e (@entries) {
357 if($e>=1 && $e<= $num_options){
358 my $estring = $option_list_pruned[$e-1];
359 $additional_options = "$additional_options $estring";
360 } elsif ($e == $num_options+1){
361 # user chose "None of the above"
362 # clear the options we may have seen before
363 $additional_options = " ";
367 # if the user input something reasonable, we can break out of this loop
368 if($additional_options ne ""){
369 $options = "$options ${additional_options} ";
370 last;
378 # Choose compiler flags
379 print << "EOF";
381 Choose a set of compiler flags [1-5]
382 1) none
383 2) debug mode -g -O0
384 3) production build [default] --with-production
385 4) production build w/ projections --with-production --enable-tracing
386 5) custom
390 my $compiler_flags = "";
392 while(my $line = <>){
393 chomp $line;
394 if($line eq "1"){
395 last;
396 } elsif($line eq "2"){
397 $compiler_flags = "-g -O0";
398 last;
399 } elsif($line eq "4" ){
400 $compiler_flags = "--with-production --enable-tracing";
401 last;
402 } elsif($line eq "3" || $line eq ""){
403 $compiler_flags = "--with-production";
404 last;
405 } elsif($line eq "5"){
407 print "Enter compiler options: ";
408 my $input_line = <>;
409 chomp($input_line);
410 $compiler_flags = $input_line;
412 last;
413 } else {
414 print "Invalid option, please try again :P\n"
421 # Determine the target to build.
422 # We want this simple so we just give 2 options
423 my $target = "";
425 print << "EOF";
427 What do you want to build?
428 1) Charm++ [default] (choose this if you are building NAMD)
429 2) Charm++ and AMPI
430 3) Charm++, AMPI, ParFUM, FEM and other libraries
434 while(my $line = <>){
435 chomp $line;
436 if($line eq "1" || $line eq ""){
437 $target = "charm++";
438 last;
439 } elsif($line eq "2"){
440 $target = "AMPI";
441 last;
442 } elsif($line eq "3"){
443 $target = "LIBS";
444 last;
445 } else {
446 print "Invalid option, please try again :P\n"
451 # Determine whether to use a -j flag for faster building
452 my $j = "";
453 print << "EOF";
455 Do you want to compile in parallel?
456 1) No
457 2) Build with -j2
458 3) Build with -j4
459 4) Build with -j8
460 5) Build with -j16 [default]
461 6) Build with -j32
462 7) Build with -j
466 while(my $line = <>) {
467 chomp $line;
468 if($line eq "1"){
469 $j = "";
470 last;
471 } elsif($line eq "2") {
472 $j = "-j2";
473 last;
474 } elsif($line eq "3") {
475 $j = "-j4";
476 last;
477 } elsif($line eq "4") {
478 $j = "-j8";
479 last;
480 } elsif($line eq "5" || $line eq "") {
481 $j = "-j16";
482 last;
483 } elsif($line eq "6") {
484 $j = "-j32";
485 last;
486 } elsif($line eq "7") {
487 $j = "-j";
488 last;
489 } else {
490 print "Invalid option, please try again :P\n";
495 # Compose the build line
496 my $build_line = "$dirname/build $target $arch $compilers $options $j $nobs ${compiler_flags}\n";
499 # Save the build line in the log
500 open(BUILDLINE, ">>smart-build.log");
501 print BUILDLINE `date`;
502 print BUILDLINE "Using the following build command:\n";
503 print BUILDLINE "$build_line\n";
504 close(BUILDLINE);
507 print "We have determined a suitable build line is:\n";
508 print "\t$build_line\n\n";
511 # Execute the build line if the appropriate architecture directory exists
512 print "Do you want to start the build now? [Y/n]";
513 my $p = promptUserYN();
514 if($p eq "yes" || $p eq "default"){
515 if(-e "$dirname/src/arch/$arch"){
516 print "Building with: ${build_line}\n";
517 # Execute the build line
518 system($build_line);
519 } else {
520 print "We could not figure out how to build charm with those options on this platform, please manually build\n";
521 print "Try something similar to: ${build_line}\n";