run-experiment-ssh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Run an experiment using ssh to real hosts, not in dockers
  3. # We need these environment variables set:
  4. # PRAC_SSH_P0_USERHOST: the user@host to ssh to for P0
  5. # PRAC_SSH_P0_SSHOPTS: any options to ssh you need to ssh to P0
  6. # PRAC_SSH_P0_IP: the IP address P0 can listen for connections on (P0
  7. # listens on ports 2115 and 2116)
  8. # PRAC_SSH_P0_DIR: the directory relative to the homedir where the prac
  9. # repo is checked out and built
  10. # PRAC_SSH_P1_USERHOST: the user@host to ssh to for P1
  11. # PRAC_SSH_P1_SSHOPTS: any options to ssh you need to ssh to P1
  12. # PRAC_SSH_P1_IP: the IP address P1 can listen for connections on (P1
  13. # listens on port 2117)
  14. # PRAC_SSH_P1_DIR: the directory relative to the homedir where the prac
  15. # repo is checked out and built
  16. # PRAC_SSH_P2_USERHOST: the user@host to ssh to for P2
  17. # PRAC_SSH_P2_SSHOPTS: any options to ssh you need to ssh to P2
  18. # PRAC_SSH_P2_DIR: the directory relative to the homedir where the prac
  19. # repo is checked out and built
  20. # Get the IP addresses
  21. p0addr=$PRAC_SSH_P0_IP
  22. p1addr=$PRAC_SSH_P1_IP
  23. # Gather options and arguments
  24. preproc=0
  25. opts=""
  26. while getopts paot:ex arg; do
  27. opts+=" -${arg} ${OPTARG}"
  28. if [ "$arg" = "p" -o "$arg" = "a" ]; then
  29. preproc=1
  30. fi
  31. done
  32. shift $((OPTIND-1))
  33. # Get the number of cores usable by each party
  34. ncores_p0=1
  35. ncores_p1=1
  36. ncores_p2=1
  37. if [ "$whichexps" != "none" ]; then
  38. ncores_p0=`ssh -n $PRAC_SSH_P0_SSHOPTS $PRAC_SSH_P0_USERHOST $PRAC_NUMA_P0 nproc 2>/dev/null`
  39. ncores_p1=`ssh -n $PRAC_SSH_P1_SSHOPTS $PRAC_SSH_P1_USERHOST $PRAC_NUMA_P1 nproc 2>/dev/null`
  40. ncores_p2=`ssh -n $PRAC_SSH_P2_SSHOPTS $PRAC_SSH_P2_USERHOST $PRAC_NUMA_P2 nproc 2>/dev/null`
  41. fi
  42. targ_p0="-t ${ncores_p0}"
  43. targ_p1="-t ${ncores_p1}"
  44. targ_p2="-t ${ncores_p2}"
  45. echo ===== Running prac $opts -- $*
  46. date "+===== Start %s %F %T"
  47. # Run, saving the output
  48. savefile0=$$.p0.out
  49. savefile1=$$.p1.out
  50. savefile2=$$.p2.out
  51. ssh -n $PRAC_SSH_P0_SSHOPTS $PRAC_SSH_P0_USERHOST "cd $PRAC_SSH_P0_DIR && $PRAC_NUMA_P0 stdbuf -o 0 ./prac $opts $targ_p0 0 $* > $savefile0 2>&1" &
  52. ssh -n $PRAC_SSH_P1_SSHOPTS $PRAC_SSH_P1_USERHOST "cd $PRAC_SSH_P1_DIR && $PRAC_NUMA_P1 stdbuf -o 0 ./prac $opts $targ_p1 1 $p0addr $* > $savefile1 2>&1" &
  53. ssh -n $PRAC_SSH_P2_SSHOPTS $PRAC_SSH_P2_USERHOST "cd $PRAC_SSH_P2_DIR && $PRAC_NUMA_P2 stdbuf -o 0 ./prac $opts $targ_p2 2 $p0addr $p1addr $* > $savefile2 2>&1" &
  54. wait
  55. echo ===== P0 output
  56. ssh -n $PRAC_SSH_P0_SSHOPTS $PRAC_SSH_P0_USERHOST "cd $PRAC_SSH_P0_DIR && cat $savefile0 && rm -f $savefile0"
  57. echo ===== P1 output
  58. ssh -n $PRAC_SSH_P1_SSHOPTS $PRAC_SSH_P1_USERHOST "cd $PRAC_SSH_P1_DIR && cat $savefile1 && rm -f $savefile1"
  59. echo ===== P2 output
  60. ssh -n $PRAC_SSH_P2_SSHOPTS $PRAC_SSH_P2_USERHOST "cd $PRAC_SSH_P2_DIR && cat $savefile2 && rm -f $savefile2"
  61. date "+===== End %s %F %T"