#!/usr/bin/perl

#To run on CGM6 use just run

#To run on the Intel Phi Mic cards set the following environment vars
#export MPIRUN=/usr/local/bin/mpirun 
#export MPI_HOSTS=host_file_mics 

@program_names = ("mpi_hello_world");
%program_nodes = ("mpi_hello_world", 32); # 32 threads called

$program_to_run = $ARGV[0];
if (!$program_to_run || !$program_nodes{$program_to_run}) {
  die "Must enter program name to run. Possible programs are: " .
      "\n@program_names\n";
} else {
  if ($ENV{"MPIRUN"}) {
    $mpirun = $ENV{"MPIRUN"};
  } else {
    $mpirun = "mpirun";
  }
  if ($ENV{"MPI_HOSTS"}) {
    $hosts = "-default-hostfile " . $ENV{"MPI_HOSTS"};
  } else {
    $hosts = "";
  }

# mpirun -n "processes" program_to_run 
  print "$mpirun -n $program_nodes{$program_to_run} $hosts ./$program_to_run\n";
  system("$mpirun -n $program_nodes{$program_to_run} $hosts ./$program_to_run");
}
