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 # Turn off I/O buffering
21 # A subroutine that reads from input and returns a yes/no/default
25 if(lc($line) eq "y" || lc($line) eq "yes" ){
27 } elsif(lc($line) eq "n" || lc($line) eq "no" ){
29 } elsif( $line eq "" ){
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
47 #Variables to hold the portions of the configuration:
53 #remove newlines from these strings:
61 } elsif ($os eq "Darwin") {
63 } elsif ($os =~ m/BSD/ ) {
65 } elsif ($os =~ m/OSF1/ ) {
74 # Determine architecture (x86, ppc, ...)
75 if($cpu =~ m/i[0-9]86/){
77 } elsif($cpu =~ m/x86\_64/){
79 } elsif($cpu =~ m/powerpc/){
81 } elsif($cpu =~ m/ppc*/){
83 } elsif($cpu =~ m/arm7/){
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") {
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";
108 my $mpi_found = "false";
109 my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
115 $m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
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
();
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
();
139 Choose an interconnect from below
: [1-10]
141 2) Infiniband
(ibverbs
)
145 6) Intel Omni
-Path
(ofi
)
149 while(my $line = <>){
152 $converse_network_type = "mpi";
154 } elsif($line eq "2"){
155 $converse_network_type = "verbs";
157 } elsif($line eq "3"){
158 $arch = "gni-crayxe";
160 } elsif($line eq "4"){
161 $arch = "gni-crayxc";
163 } elsif($line eq "5"){
164 $arch = "pamilrts-bluegeneq";
166 } elsif($line eq "6"){
167 $converse_network_type = "ofi";
170 print "Invalid option, please try again :P\n"
177 # construct an $arch string if we did not explicitly set one above
179 $arch = "${converse_network_type}-${arch_os}";
181 $arch = $arch . "-x86_64";
183 $arch = $arch . "-ppc";
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: (.*)/;
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
215 $smp_opts = $smp_opts . " $counter) SMP\n";
216 $smpIndex = $counter;
220 if($opts =~ m/pxshm/){
222 $smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
223 $pxshmIndex = $counter;
227 print "How do you want to handle SMP/Multicore: [1-$counter]\n";
230 while(my $line = <>){
232 if($line eq "" || $line eq "1"){
234 } elsif($line eq $smpIndex){
235 $options = "$options smp ";
237 } elsif($line eq $pxshmIndex){
238 $options = "$options pxshm ";
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: (.*)/;
252 # split the line into an array
253 my @c_list = split(" ", $cs);
255 # print list of compilers
259 print "\nDo you want to specify a compiler? [y/N]";
260 my $p = promptUserYN
();
262 print "Choose a compiler: [1-$numc] \n";
265 foreach my $c (@c_list){
271 while(my $line = <>){
273 if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
274 $compilers = $c_list[$1-1];
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: (.*)/;
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);
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";
334 foreach my $o (@option_list_pruned){
335 my $exp = $explanations{$o};
337 # pad whitespace before options
338 for(my $j=0;$j<20-length($o);$j++){
345 print "\t$i)\tNone Of The Above\n";
347 my $num_options = @option_list_pruned;
349 while(my $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} ";
378 # Choose compiler flags
381 Choose a set of compiler flags
[1-5]
384 3) production build
[default] --with
-production
385 4) production build w
/ projections
--with
-production
--enable
-tracing
390 my $compiler_flags = "";
392 while(my $line = <>){
396 } elsif($line eq "2"){
397 $compiler_flags = "-g -O0";
399 } elsif($line eq "4" ){
400 $compiler_flags = "--with-production --enable-tracing";
402 } elsif($line eq "3" || $line eq ""){
403 $compiler_flags = "--with-production";
405 } elsif($line eq "5"){
407 print "Enter compiler options: ";
410 $compiler_flags = $input_line;
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
427 What
do you want to build?
428 1) Charm
++ [default] (choose this
if you are building NAMD
)
430 3) Charm
++, AMPI
, ParFUM
, FEM
and other libraries
434 while(my $line = <>){
436 if($line eq "1" || $line eq ""){
439 } elsif($line eq "2"){
442 } elsif($line eq "3"){
446 print "Invalid option, please try again :P\n"
451 # Determine whether to use a -j flag for faster building
455 Do you want to compile
in parallel?
460 5) Build with
-j16
[default]
466 while(my $line = <>) {
471 } elsif($line eq "2") {
474 } elsif($line eq "3") {
477 } elsif($line eq "4") {
480 } elsif($line eq "5" || $line eq "") {
483 } elsif($line eq "6") {
486 } elsif($line eq "7") {
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";
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
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";