4 # This is an interactive script that knows
5 # common ways to build Charm++ and AMPI.
7 # Authors: dooley, becker
12 # Get location of script
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');
21 # Turn off I/O buffering
26 # A subroutine that reads from input and returns a yes/no/default
30 if(lc($line) eq "y" || lc($line) eq "yes" ){
32 } elsif(lc($line) eq "n" || lc($line) eq "no" ){
34 } elsif( $line eq "" ){
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
52 #Variables to hold the portions of the configuration:
58 #remove newlines from these strings:
66 } elsif ($os eq "Darwin") {
68 } elsif ($os =~ m/BSD/ ) {
70 } elsif ($os =~ m/OSF1/ ) {
79 # Determine architecture (x86, ppc, ...)
80 if($cpu =~ m/i[0-9]86/){
82 } elsif($cpu =~ m/x86\_64/){
84 } elsif($cpu =~ m/powerpc/){
86 } elsif($cpu =~ m/ppc*/){
88 } elsif($cpu =~ m/arm7/){
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") {
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";
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";
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;
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";
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";
170 if($skip_choosing eq "false"){
171 my $ofi_found = index(`cc $tempfile -Wl,-lfabric 2>&1`, "-lfabric") == -1;
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";
186 if($skip_choosing eq "false"){
187 my $MPI_ROOT = $ENV{'MPI_ROOT'};
188 if (not defined $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;
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";
207 if($skip_choosing eq "false"){
208 my $verbs_found = index(`cc $tempfile -Wl,-libverbs 2>&1`, "-libverbs") == -1;
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";
223 if($skip_choosing eq "false"){
224 my $mpi_found = "false";
225 my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
231 $m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
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
();
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
();
258 Choose an interconnect from below
: [1-10]
260 2) Infiniband
(verbs
)
264 6) Intel Omni
-Path
(ofi
)
269 while(my $line = <>){
272 $converse_network_type = "mpi";
274 } elsif($line eq "2"){
275 $converse_network_type = "verbs";
277 } elsif($line eq "3"){
278 $arch = "gni-crayxe";
280 } elsif($line eq "4"){
281 $arch = "gni-crayxc";
283 } elsif($line eq "5"){
284 $arch = "pamilrts-bluegeneq";
286 } elsif($line eq "6"){
287 $converse_network_type = "ofi";
289 } elsif($line eq "7"){
290 $converse_network_type = "pamilrts";
293 print "Invalid option, please try again :P\n"
300 # construct an $arch string if we did not explicitly set one above
302 $arch = "${converse_network_type}-${arch_os}";
304 $arch = $arch . "-x86_64";
306 $arch = $arch . "-ppc64le";
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: (.*)/;
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
338 $smp_opts = $smp_opts . " $counter) SMP\n";
339 $smpIndex = $counter;
343 if($opts =~ m/pxshm/){
345 $smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
346 $pxshmIndex = $counter;
350 print "How do you want to handle SMP/Multicore: [1-$counter]\n";
353 while(my $line = <>){
355 if($line eq "" || $line eq "1"){
357 } elsif($line eq $smpIndex){
358 $options = "$options smp ";
360 } elsif($line eq $pxshmIndex){
361 $options = "$options pxshm ";
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: (.*)/;
375 # split the line into an array
376 my @c_list = split(" ", $cs);
378 # print list of compilers
382 print "\nDo you want to specify a compiler? [y/N]: ";
383 my $p = promptUserYN
();
385 print "Choose a compiler: [1-$numc] \n";
388 foreach my $c (@c_list){
394 while(my $line = <>){
396 if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
397 $compilers = $c_list[$1-1];
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: (.*)/;
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);
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";
469 foreach my $o (@option_list_pruned){
470 my $exp = $explanations{$o};
472 # pad whitespace before options
473 for(my $j=0;$j<20-length($o);$j++){
480 print "\t$i)\tNone Of The Above\n";
482 my $num_options = @option_list_pruned;
484 while(my $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} ";
513 # Choose compiler flags
516 Choose a set of compiler flags
[1-5]
519 3) production build
[default] --with
-production
520 4) production build w
/ projections
--with
-production
--enable
-tracing
525 my $compiler_flags = "";
527 while(my $line = <>){
531 } elsif($line eq "2"){
532 $compiler_flags = "-g -O0";
534 } elsif($line eq "4" ){
535 $compiler_flags = "--with-production --enable-tracing";
537 } elsif($line eq "3" || $line eq ""){
538 $compiler_flags = "--with-production";
540 } elsif($line eq "5"){
542 print "Enter compiler options: ";
545 $compiler_flags = $input_line;
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
562 What
do you want to build?
563 1) Charm
++ [default] (choose this
if you are building NAMD
)
565 3) Charm
++, AMPI
, ParFUM
, FEM
and other libraries
569 while(my $line = <>){
571 if($line eq "1" || $line eq ""){
574 } elsif($line eq "2"){
577 } elsif($line eq "3"){
581 print "Invalid option, please try again :P\n"
586 # Determine whether to use a -j flag for faster building
590 Do you want to compile
in parallel?
595 5) Build with
-j16
[default]
601 while(my $line = <>) {
606 } elsif($line eq "2") {
609 } elsif($line eq "3") {
612 } elsif($line eq "4") {
615 } elsif($line eq "5" || $line eq "") {
618 } elsif($line eq "6") {
621 } elsif($line eq "7") {
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";
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
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";