ROMIO: Fix configure step portably
[charm.git] / smart-build.pl
blobbae8789ad8445f9240f538a39dc4b33126a92b5b
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 # Create temporary file for compiler tests
17 use File::Temp qw(tempfile);
18 my $tempfile = new File::Temp(UNLINK => 1, SUFFIX => '.c');
19 print $tempfile "\n";
21 # Turn off I/O buffering
22 $| = 1;
26 # A subroutine that reads from input and returns a yes/no/default
27 sub promptUserYN {
28 while(my $line = <>){
29 chomp $line;
30 if(lc($line) eq "y" || lc($line) eq "yes" ){
31 return "yes";
32 } elsif(lc($line) eq "n" || lc($line) eq "no" ){
33 return "no";
34 } elsif( $line eq "" ){
35 return "default";
41 # The beginning of the good stuff:
42 print "\n============================================================\n";
43 print "\nInteractive Charm++/AMPI configuration ...\n";
44 print "If you are a power user expecting a list of options, please use ./build --help\n";
45 print "\n============================================================\n\n\n";
48 # Use uname to get the cpu type and OS information
49 my $os = `uname -s`;
50 my $cpu = `uname -m`;
52 #Variables to hold the portions of the configuration:
53 my $nobs = "";
54 my $arch = "";
55 my $compilers = "";
56 my $options = "";
58 #remove newlines from these strings:
59 chomp($os);
60 chomp ($cpu);
62 my $arch_os;
63 # Determine OS kernel
64 if ($os eq "Linux") {
65 $arch_os = "linux";
66 } elsif ($os eq "Darwin") {
67 $arch_os = "darwin";
68 } elsif ($os =~ m/BSD/ ) {
69 $arch_os = "linux";
70 } elsif ($os =~ m/OSF1/ ) {
71 $arch_os = "linux";
75 my $x86;
76 my $amd64;
77 my $ppc;
78 my $arm7;
79 # Determine architecture (x86, ppc, ...)
80 if($cpu =~ m/i[0-9]86/){
81 $x86 = 1;
82 } elsif($cpu =~ m/x86\_64/){
83 $amd64 = 1;
84 } elsif($cpu =~ m/powerpc/){
85 $ppc = 1;
86 } elsif($cpu =~ m/ppc*/){
87 $ppc = 1;
88 } elsif($cpu =~ m/arm7/){
89 $arm7 = 1;
93 # default to netlrts
94 my $converse_network_type = "netlrts";
95 my $skip_choosing = "false";
97 print "Are you building to run just on the local machine, and not across multiple nodes? [";
98 if($arch_os eq "darwin") {
99 print "Y/n]: ";
100 } else {
101 print "y/N]: ";
104 my $p = promptUserYN();
105 if($p eq "yes" || ($arch_os eq "darwin" && $p eq "default")){
106 $converse_network_type = "multicore";
107 $skip_choosing = "true";
112 # check for BG/Q
114 if($skip_choosing eq "false"){
115 my $BGQ_FLOOR = $ENV{'BGQ_FLOOR'};
116 if (not defined $BGQ_FLOOR) {
117 $BGQ_FLOOR = "/bgsys/drivers/ppcfloor";
120 my $bgq_found = system("which \"$BGQ_FLOOR/gnu-linux/bin/powerpc64-bgq-linux-cpp\" 2>/dev/null") / 256;
122 if ($bgq_found == 0) {
123 print "\nI found that you have a Blue Gene/Q toolchain available in your path.\nDo you want to build Charm++ targeting BG/Q? [Y/n]: ";
124 my $p = promptUserYN();
125 if($p eq "yes" || $p eq "default") {
126 $arch = "pamilrts-bluegeneq";
127 $skip_choosing = "true";
133 # check for GNI
135 if($skip_choosing eq "false"){
136 my $craycc_found = index(`which CC 2>/dev/null`, "/opt/cray/") != -1;
138 my $PE_PRODUCT_LIST = $ENV{'PE_PRODUCT_LIST'};
139 if (not defined $PE_PRODUCT_LIST) {
140 $PE_PRODUCT_LIST = "";
143 my $CRAY_UGNI_found = index(":$PE_PRODUCT_LIST:", ":CRAY_UGNI:") != -1;
145 my $gni_found = $craycc_found || $CRAY_UGNI_found;
147 if ($gni_found) {
148 my $CRAYPE_INTERLAGOS_found = index(":$PE_PRODUCT_LIST:", ":CRAYPE_INTERLAGOS:") != -1;
149 if ($CRAYPE_INTERLAGOS_found) {
150 print "\nI found that you have a Cray environment with Interlagos processors.\nDo you want to build Charm++ targeting Cray XE? [Y/n]: ";
151 my $p = promptUserYN();
152 if($p eq "yes" || $p eq "default") {
153 $arch = "gni-crayxe";
154 $skip_choosing = "true";
156 } else {
157 print "\nI found that you have a Cray environment.\nDo you want to build Charm++ targeting Cray XC? [Y/n]: ";
158 my $p = promptUserYN();
159 if($p eq "yes" || $p eq "default") {
160 $arch = "gni-crayxc";
161 $skip_choosing = "true";
168 # check for OFI
170 if($skip_choosing eq "false"){
171 my $ofi_found = index(`cc $tempfile -Wl,-lfabric 2>&1`, "-lfabric") == -1;
173 if ($ofi_found) {
174 print "\nI found that you have libfabric available in your toolchain.\nDo you want to build Charm++ targeting OFI? [Y/n]: ";
175 my $p = promptUserYN();
176 if($p eq "yes" || $p eq "default") {
177 $converse_network_type = "ofi";
178 $skip_choosing = "true";
184 # check for PAMI
186 if($skip_choosing eq "false"){
187 my $MPI_ROOT = $ENV{'MPI_ROOT'};
188 if (not defined $MPI_ROOT) {
189 $MPI_ROOT = "";
192 my $pami_found = index(`cc $tempfile -Wl,-L,"$MPI_ROOT/lib/pami_port" -Wl,-L,/usr/lib/powerpc64le-linux-gnu -Wl,-lpami 2>&1`, "-lpami") == -1;
194 if ($pami_found) {
195 print "\nI found that you have libpami available in your toolchain.\nDo you want to build Charm++ targeting PAMI? [Y/n]: ";
196 my $p = promptUserYN();
197 if($p eq "yes" || $p eq "default") {
198 $converse_network_type = "pamilrts";
199 $skip_choosing = "true";
205 # check for Verbs
207 if($skip_choosing eq "false"){
208 my $verbs_found = index(`cc $tempfile -Wl,-libverbs 2>&1`, "-libverbs") == -1;
210 if ($verbs_found) {
211 print "\nI found that you have libibverbs available in your toolchain.\nDo you want to build Charm++ targeting Infiniband Verbs? [Y/n]: ";
212 my $p = promptUserYN();
213 if($p eq "yes" || $p eq "default") {
214 $converse_network_type = "verbs";
215 $skip_choosing = "true";
221 # check for MPI
223 if($skip_choosing eq "false"){
224 my $mpi_found = "false";
225 my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
226 my $mpioption;
227 if($m == 0){
228 $mpi_found = "true";
229 $mpioption = "";
231 $m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
232 if($m == 0){
233 $mpi_found = "true";
234 $mpioption = "mpicxx";
237 # Give option of just using the mpi version if mpicc and mpiCC are found
238 if($mpi_found eq "true"){
239 print "\nI found that you have an mpicc available in your path.\nDo you want to build Charm++ on this MPI? [y/N]: ";
240 my $p = promptUserYN();
241 if($p eq "yes"){
242 $converse_network_type = "mpi";
243 $skip_choosing = "true";
244 $options = "$options $mpioption";
250 if($skip_choosing eq "false") {
252 print "\nDo you have a special network interconnect? [y/N]: ";
253 my $p = promptUserYN();
254 if($p eq "yes"){
256 print << "EOF";
258 Choose an interconnect from below: [1-10]
259 1) MPI
260 2) Infiniband (verbs)
261 3) Cray XE, XK
262 4) Cray XC
263 5) Blue Gene/Q
264 6) Intel Omni-Path (ofi)
265 7) PAMI
269 while(my $line = <>){
270 chomp $line;
271 if($line eq "1"){
272 $converse_network_type = "mpi";
273 last;
274 } elsif($line eq "2"){
275 $converse_network_type = "verbs";
276 last;
277 } elsif($line eq "3"){
278 $arch = "gni-crayxe";
279 last;
280 } elsif($line eq "4"){
281 $arch = "gni-crayxc";
282 last;
283 } elsif($line eq "5"){
284 $arch = "pamilrts-bluegeneq";
285 last;
286 } elsif($line eq "6"){
287 $converse_network_type = "ofi";
288 last;
289 } elsif($line eq "7"){
290 $converse_network_type = "pamilrts";
291 last;
292 } else {
293 print "Invalid option, please try again :P\n"
300 # construct an $arch string if we did not explicitly set one above
301 if($arch eq ""){
302 $arch = "${converse_network_type}-${arch_os}";
303 if($amd64) {
304 $arch = $arch . "-x86_64";
305 } elsif($ppc){
306 $arch = $arch . "-ppc64le";
307 } elsif($arm7){
308 $arch = $arch . "-arm7";
312 # Fixup $arch to match the inconsistent directories in src/archs
314 if($arch eq "netlrts-darwin"){
315 $arch = "netlrts-darwin-x86_64";
316 } elsif($arch eq "multicore-linux-arm7"){
317 $arch = "multicore-arm7";
321 #================ Choose SMP/PXSHM =================================
323 # find what options are available
324 my $opts = `$dirname/build charm++ $arch help 2>&1 | grep "Supported options"`;
325 $opts =~ m/Supported options: (.*)/;
326 $opts = $1;
328 my $smp_opts = <<EOF;
329 1) single-threaded [default]
332 # only add the smp or pxshm options if they are available
333 my $counter = 1; # the last index used in the list
335 my $smpIndex = -1;
336 if($opts =~ m/smp/){
337 $counter ++;
338 $smp_opts = $smp_opts . " $counter) SMP\n";
339 $smpIndex = $counter;
342 my $pxshmIndex = -1;
343 if($opts =~ m/pxshm/){
344 $counter ++;
345 $smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
346 $pxshmIndex = $counter;
349 if ($counter != 1) {
350 print "How do you want to handle SMP/Multicore: [1-$counter]\n";
351 print $smp_opts;
353 while(my $line = <>){
354 chomp $line;
355 if($line eq "" || $line eq "1"){
356 last;
357 } elsif($line eq $smpIndex){
358 $options = "$options smp ";
359 last;
360 } elsif($line eq $pxshmIndex){
361 $options = "$options pxshm ";
362 last;
368 #================ Choose Compiler =================================
370 # Lookup list of compilers
371 my $cs = `$dirname/build charm++ $arch help 2>&1 | grep "Supported compilers"`;
372 # prune away beginning of the line
373 $cs =~ m/Supported compilers: (.*)/;
374 $cs = $1;
375 # split the line into an array
376 my @c_list = split(" ", $cs);
378 # print list of compilers
379 my $numc = @c_list;
381 if ($numc > 0) {
382 print "\nDo you want to specify a compiler? [y/N]: ";
383 my $p = promptUserYN();
384 if($p eq "yes" ){
385 print "Choose a compiler: [1-$numc] \n";
387 my $i = 1;
388 foreach my $c (@c_list){
389 print "\t$i)\t$c\n";
390 $i++;
393 # Choose compiler
394 while(my $line = <>){
395 chomp $line;
396 if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
397 $compilers = $c_list[$1-1];
398 last;
399 } else {
400 print "Invalid option, please try again :P\n"
409 #================ Choose Options =================================
411 #Create a hash table containing descriptions of various options
412 my %explanations = ();
413 $explanations{"ooc"} = "Enable Out-of-core execution support in Charm++";
414 $explanations{"tcp"} = "Charm++ over TCP instead of UDP for net versions. TCP is slower";
415 $explanations{"gfortran"} = "Use the gfortran compiler for Fortran";
416 $explanations{"flang"} = "Use the flang compiler for Fortran";
417 $explanations{"ifort"} = "Use Intel's ifort Fortran compiler";
418 $explanations{"pgf90"} = "Use Portland Group's pgf90 Fortran compiler";
419 $explanations{"syncft"} = "Use fault tolerance support";
420 $explanations{"mlogft"} = "Use message logging fault tolerance support";
421 $explanations{"causalft"} = "Use causal message logging fault tolerance support";
422 $explanations{"omp"} = "Build Charm++ with integrated OpenMP support";
423 $explanations{"papi"} = "Enable PAPI performance counters";
424 $explanations{"pedantic"} = "Enable pedantic compiler warnings";
425 $explanations{"bigemulator"} = "Build additional BigSim libraries";
426 $explanations{"bigsim"} = "Compile Charm++ as running on the BigSim emulator";
427 $explanations{"nolb"} = "Build without load balancing support";
428 $explanations{"perftools"} = "Build with support for the Cray perftools";
429 $explanations{"persistent"} = "Build the persistent communication interface";
430 $explanations{"slurmpmi"} = "Use Slurm PMI for task launching";
431 $explanations{"slurmpmi2"} = "Use Slurm PMI2 for task launching";
432 $explanations{"tsan"} = "Compile Charm++ with support for Thread Sanitizer";
438 # Produce list of options
440 $opts = `$dirname/build charm++ $arch help 2>&1 | grep "Supported options"`;
441 # prune away beginning of line
442 $opts =~ m/Supported options: (.*)/;
443 $opts = $1;
445 my @option_list = split(" ", $opts);
448 # Prune out entries that would already have been chosen above, such as smp
449 my @option_list_pruned = ();
450 foreach my $o (@option_list){
451 if($o ne "smp" && $o ne "ibverbs" && $o ne "gm" && $o ne "mx"){
452 @option_list_pruned = (@option_list_pruned , $o);
456 # sort the list
457 @option_list_pruned = sort @option_list_pruned;
458 if (@option_list_pruned > 0) {
460 print "\nDo you want to specify any Charm++ build options, such as Fortran compilers? [y/N]: ";
461 my $special_options = promptUserYN();
463 if($special_options eq "yes"){
465 # print out list for user to select from
466 print "Please enter one or more numbers separated by spaces\n";
467 print "Choices:\n";
468 my $i = 1;
469 foreach my $o (@option_list_pruned){
470 my $exp = $explanations{$o};
471 print "\t$i)\t$o";
472 # pad whitespace before options
473 for(my $j=0;$j<20-length($o);$j++){
474 print " ";
476 print "$exp";
477 print "\n";
478 $i++;
480 print "\t$i)\tNone Of The Above\n";
482 my $num_options = @option_list_pruned;
484 while(my $line = <>){
485 chomp $line;
486 $line =~ m/([0-9 ]*)/;
487 my @entries = split(" ",$1);
488 @entries = sort(@entries);
490 my $additional_options = "";
491 foreach my $e (@entries) {
492 if($e>=1 && $e<= $num_options){
493 my $estring = $option_list_pruned[$e-1];
494 $additional_options = "$additional_options $estring";
495 } elsif ($e == $num_options+1){
496 # user chose "None of the above"
497 # clear the options we may have seen before
498 $additional_options = " ";
502 # if the user input something reasonable, we can break out of this loop
503 if($additional_options ne ""){
504 $options = "$options ${additional_options} ";
505 last;
513 # Choose compiler flags
514 print << "EOF";
516 Choose a set of compiler flags [1-5]
517 1) none
518 2) debug mode -g -O0
519 3) production build [default] --with-production
520 4) production build w/ projections --with-production --enable-tracing
521 5) custom
525 my $compiler_flags = "";
527 while(my $line = <>){
528 chomp $line;
529 if($line eq "1"){
530 last;
531 } elsif($line eq "2"){
532 $compiler_flags = "-g -O0";
533 last;
534 } elsif($line eq "4" ){
535 $compiler_flags = "--with-production --enable-tracing";
536 last;
537 } elsif($line eq "3" || $line eq ""){
538 $compiler_flags = "--with-production";
539 last;
540 } elsif($line eq "5"){
542 print "Enter compiler options: ";
543 my $input_line = <>;
544 chomp($input_line);
545 $compiler_flags = $input_line;
547 last;
548 } else {
549 print "Invalid option, please try again :P\n"
556 # Determine the target to build.
557 # We want this simple so we just give 2 options
558 my $target = "";
560 print << "EOF";
562 What do you want to build?
563 1) Charm++ [default] (choose this if you are building NAMD)
564 2) Charm++ and AMPI
565 3) Charm++, AMPI, ParFUM, FEM and other libraries
569 while(my $line = <>){
570 chomp $line;
571 if($line eq "1" || $line eq ""){
572 $target = "charm++";
573 last;
574 } elsif($line eq "2"){
575 $target = "AMPI";
576 last;
577 } elsif($line eq "3"){
578 $target = "LIBS";
579 last;
580 } else {
581 print "Invalid option, please try again :P\n"
586 # Determine whether to use a -j flag for faster building
587 my $j = "";
588 print << "EOF";
590 Do you want to compile in parallel?
591 1) No
592 2) Build with -j2
593 3) Build with -j4
594 4) Build with -j8
595 5) Build with -j16 [default]
596 6) Build with -j32
597 7) Build with -j
601 while(my $line = <>) {
602 chomp $line;
603 if($line eq "1"){
604 $j = "";
605 last;
606 } elsif($line eq "2") {
607 $j = "-j2";
608 last;
609 } elsif($line eq "3") {
610 $j = "-j4";
611 last;
612 } elsif($line eq "4") {
613 $j = "-j8";
614 last;
615 } elsif($line eq "5" || $line eq "") {
616 $j = "-j16";
617 last;
618 } elsif($line eq "6") {
619 $j = "-j32";
620 last;
621 } elsif($line eq "7") {
622 $j = "-j";
623 last;
624 } else {
625 print "Invalid option, please try again :P\n";
630 # Compose the build line
631 my $build_line = "$dirname/build $target $arch $compilers $options $j $nobs ${compiler_flags}\n";
634 # Save the build line in the log
635 open(BUILDLINE, ">>smart-build.log");
636 print BUILDLINE `date`;
637 print BUILDLINE "Using the following build command:\n";
638 print BUILDLINE "$build_line\n";
639 close(BUILDLINE);
642 print "We have determined a suitable build line is:\n";
643 print "\t$build_line\n\n";
646 # Execute the build line if the appropriate architecture directory exists
647 print "Do you want to start the build now? [Y/n]: ";
648 my $p = promptUserYN();
649 if($p eq "yes" || $p eq "default"){
650 if(-e "$dirname/src/arch/$arch"){
651 print "Building with: ${build_line}\n";
652 # Execute the build line
653 system($build_line);
654 } else {
655 print "We could not figure out how to build charm with those options on this platform, please manually build\n";
656 print "Try something similar to: ${build_line}\n";