4 # This is an interactive script that knows
5 # common ways to build Charm++ and AMPI.
7 # Authors: dooley, becker
12 # Turn off I/O buffering
17 # A subroutine that reads from input and returns a yes/no/default
21 if(lc($line) eq "y" || lc($line) eq "yes" ){
23 } elsif(lc($line) eq "n" || lc($line) eq "no" ){
25 } elsif( $line eq "" ){
32 # The beginning of the good stuff:
33 print "\n============================================================\n";
34 print "\nBegin interactive charm configuration ...\n";
35 print "If you are a poweruser expecting a list of options, please use ./build --help\n";
36 print "\n============================================================\n\n\n";
39 # Use uname to get the cpu type and OS information
43 #Variables to hold the portions of the configuration:
49 #remove newlines from these strings:
57 } elsif ($os eq "Darwin") {
59 } elsif ($os =~ m/BSD/ ) {
61 } elsif ($os =~ m/OSF1/ ) {
70 # Determine architecture (x86, ppc, ...)
71 if($cpu =~ m/i[0-9]86/){
73 } elsif($cpu =~ m/x86\_64/){
75 } elsif($cpu =~ m/powerpc/){
77 } elsif($cpu =~ m/ppc*/){
79 } elsif($cpu =~ m/arm7/){
85 my $converse_network_type = "netlrts";
86 my $skip_choosing = "false";
88 print "Are you building to run just on the local machine, and not across multiple nodes? [";
89 if($arch_os eq "darwin") {
95 my $p = promptUserYN
();
96 if($p eq "yes" || ($arch_os eq "darwin" && $p eq "default")){
97 $converse_network_type = "multicore";
98 $skip_choosing = "true";
104 my $mpi_found = "false";
105 my $m = system("which mpicc mpiCC > /dev/null 2>/dev/null") / 256;
111 $m = system("which mpicc mpicxx > /dev/null 2>/dev/null") / 256;
114 $mpioption = "mpicxx";
117 # Give option of just using the mpi version if mpicc and mpiCC are found
118 if($skip_choosing eq "false" && $mpi_found eq "true"){
119 print "\nI found that you have an mpicc available in your path.\nDo you want to build Charm++ on this MPI? [y/N]: ";
120 my $p = promptUserYN
();
122 $converse_network_type = "mpi";
123 $skip_choosing = "true";
124 $options = "$options $mpioption";
128 if($skip_choosing eq "false") {
130 print "\nDo you have a special network interconnect? [y/N]: ";
131 my $p = promptUserYN
();
135 Choose an interconnect from below
: [1-10]
137 2) Infiniband
(ibverbs
)
144 while(my $line = <>){
147 $converse_network_type = "mpi";
149 } elsif($line eq "2"){
150 $converse_network_type = "verbs";
152 } elsif($line eq "3"){
153 $arch = "gni-crayxe";
155 } elsif($line eq "4"){
156 $arch = "gni-crayxc";
158 } elsif($line eq "5"){
159 $arch = "pamilrts-bluegeneq";
162 print "Invalid option, please try again :P\n"
169 # construct an $arch string if we did not explicitly set one above
171 $arch = "${converse_network_type}-${arch_os}";
173 $arch = $arch . "-x86_64";
175 $arch = $arch . "-ppc";
177 $arch = $arch . "-arm7";
181 # Fixup $arch to match the inconsistent directories in src/archs
183 if($arch eq "netlrts-darwin"){
184 $arch = "netlrts-darwin-x86_64";
185 } elsif($arch eq "multicore-linux-arm7"){
186 $arch = "multicore-arm7";
190 #================ Choose SMP/PXSHM =================================
192 # find what options are available
193 my $opts = `./build charm++ $arch help 2>&1 | grep "Supported options"`;
194 $opts =~ m/Supported options: (.*)/;
197 my $smp_opts = <<EOF;
198 1) single-threaded [default]
201 # only add the smp or pxshm options if they are available
202 my $counter = 1; # the last index used in the list
207 $smp_opts = $smp_opts . " $counter) SMP\n";
208 $smpIndex = $counter;
212 if($opts =~ m/pxshm/){
214 $smp_opts = $smp_opts . " $counter) POSIX Shared Memory\n";
215 $pxshmIndex = $counter;
219 print "How do you want to handle SMP/Multicore: [1-$counter]\n";
222 while(my $line = <>){
224 if($line eq "" || $line eq "1"){
226 } elsif($line eq $smpIndex){
227 $options = "$options smp ";
229 } elsif($line eq $pxshmIndex){
230 $options = "$options pxshm ";
237 #================ Choose Compiler =================================
239 # Lookup list of compilers
240 my $cs = `./build charm++ $arch help 2>&1 | grep "Supported compilers"`;
241 # prune away beginning of the line
242 $cs =~ m/Supported compilers: (.*)/;
244 # split the line into an array
245 my @c_list = split(" ", $cs);
247 # print list of compilers
251 print "\nDo you want to specify a compiler? [y/N]";
252 my $p = promptUserYN
();
254 print "Choose a compiler: [1-$numc] \n";
257 foreach my $c (@c_list){
263 while(my $line = <>){
265 if($line =~ m/([0-9]*)/ && $1 > 0 && $1 <= $numc){
266 $compilers = $c_list[$1-1];
269 print "Invalid option, please try again :P\n"
278 #================ Choose Options =================================
280 #Create a hash table containing descriptions of various options
281 my %explanations = ();
282 $explanations{"ooc"} = "Out-of-core execution support in Charm++";
283 $explanations{"tcp"} = "Charm++ over TCP instead of UDP for net versions. TCP is slower";
284 $explanations{"gfortran"} = "Use gfortran compiler for fortran";
285 $explanations{"ifort"} = "Use Intel's ifort fortran compiler";
286 $explanations{"pgf90"} = "Use Portland Group's pgf90 fortran compiler";
287 $explanations{"syncft"} = "Use fault tolerance support";
288 $explanations{"mlogft"} = "Use message logging fault tolerance support";
289 $explanations{"causalft"} = "Use causal message logging fault tolerance support";
295 # Produce list of options
297 $opts = `./build charm++ $arch help 2>&1 | grep "Supported options"`;
298 # prune away beginning of line
299 $opts =~ m/Supported options: (.*)/;
302 my @option_list = split(" ", $opts);
305 # Prune out entries that would already have been chosen above, such as smp
306 my @option_list_pruned = ();
307 foreach my $o (@option_list){
308 if($o ne "smp" && $o ne "ibverbs" && $o ne "gm" && $o ne "mx"){
309 @option_list_pruned = (@option_list_pruned , $o);
314 @option_list_pruned = sort @option_list_pruned;
315 if (@option_list_pruned > 0) {
317 print "\nDo you want to specify any Charm++ build options, such as fortran compilers? [y/N]";
318 my $special_options = promptUserYN
();
320 if($special_options eq "yes"){
322 # print out list for user to select from
323 print "Please enter one or more numbers separated by spaces\n";
326 foreach my $o (@option_list_pruned){
327 my $exp = $explanations{$o};
329 # pad whitespace before options
330 for(my $j=0;$j<20-length($o);$j++){
337 print "\t$i)\tNone Of The Above\n";
339 my $num_options = @option_list_pruned;
341 while(my $line = <>){
343 $line =~ m/([0-9 ]*)/;
344 my @entries = split(" ",$1);
345 @entries = sort(@entries);
347 my $additional_options = "";
348 foreach my $e (@entries) {
349 if($e>=1 && $e<= $num_options){
350 my $estring = $option_list_pruned[$e-1];
351 $additional_options = "$additional_options $estring";
352 } elsif ($e == $num_options+1){
353 # user chose "None of the above"
354 # clear the options we may have seen before
355 $additional_options = " ";
359 # if the user input something reasonable, we can break out of this loop
360 if($additional_options ne ""){
361 $options = "$options ${additional_options} ";
370 # Choose compiler flags
373 Choose a set of compiler flags
[1-5]
376 3) production build
[default] --with
-production
377 4) production build w
/ projections
--with
-production
--enable
-tracing
382 my $compiler_flags = "";
384 while(my $line = <>){
388 } elsif($line eq "2"){
389 $compiler_flags = "-g -O0";
391 } elsif($line eq "4" ){
392 $compiler_flags = "--with-production --enable-tracing";
394 } elsif($line eq "3" || $line eq ""){
395 $compiler_flags = "--with-production";
397 } elsif($line eq "5"){
399 print "Enter compiler options: ";
402 $compiler_flags = $input_line;
406 print "Invalid option, please try again :P\n"
413 # Determine the target to build.
414 # We want this simple so we just give 2 options
419 What
do you want to build?
420 1) Charm
++ [default] (choose this
if you are building NAMD
)
422 3) Charm
++, AMPI
, ParFUM
, FEM
and other libraries
426 while(my $line = <>){
428 if($line eq "1" || $line eq ""){
431 } elsif($line eq "2"){
434 } elsif($line eq "3"){
438 print "Invalid option, please try again :P\n"
443 # Determine whether to use a -j flag for faster building
447 Do you want to compile
in parallel?
452 5) Build with
-j16
[default]
458 while(my $line = <>) {
463 } elsif($line eq "2") {
466 } elsif($line eq "3") {
469 } elsif($line eq "4") {
472 } elsif($line eq "5" || $line eq "") {
475 } elsif($line eq "6") {
478 } elsif($line eq "7") {
482 print "Invalid option, please try again :P\n";
487 # Compose the build line
488 my $build_line = "./build $target $arch $compilers $options $j $nobs ${compiler_flags}\n";
491 # Save the build line in the log
492 open(BUILDLINE
, ">>smart-build.log");
493 print BUILDLINE
`date`;
494 print BUILDLINE
"Using the following build command:\n";
495 print BUILDLINE
"$build_line\n";
499 print "We have determined a suitable build line is:\n";
500 print "\t$build_line\n\n";
503 # Execute the build line if the appropriate architecture directory exists
504 print "Do you want to start the build now? [Y/n]";
505 my $p = promptUserYN
();
506 if($p eq "yes" || $p eq "default"){
507 if(-e
"src/arch/$arch"){
508 print "Building with: ${build_line}\n";
509 # Execute the build line
512 print "We could not figure out how to build charm with those options on this platform, please manually build\n";
513 print "Try something similar to: ${build_line}\n";