run-experiment-ssh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 P0 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. # In addition, all three players must have the same number of cores
  21. # available. Use PRAC_NUMA_P[012] to set all the players to use the
  22. # same number of cores if needed.
  23. # Get the IP addresses
  24. p0addr=$PRAC_SSH_P0_IP
  25. p1addr=$PRAC_SSH_P1_IP
  26. # Gather options and arguments
  27. preproc=0
  28. opts=""
  29. while getopts paot:ex arg; do
  30. opts+=" -${arg} ${OPTARG}"
  31. if [ "$arg" = "p" -o "$arg" = "a" ]; then
  32. preproc=1
  33. fi
  34. done
  35. shift $((OPTIND-1))
  36. # Get the number of cores usable by each party
  37. ncores_p0=1
  38. ncores_p1=1
  39. ncores_p2=1
  40. if [ "$whichexps" != "none" ]; then
  41. ncores_p0=`ssh -n $PRAC_SSH_P0_SSHOPTS $PRAC_SSH_P0_USERHOST $PRAC_NUMA_P0 nproc 2>/dev/null`
  42. ncores_p1=`ssh -n $PRAC_SSH_P1_SSHOPTS $PRAC_SSH_P1_USERHOST $PRAC_NUMA_P1 nproc 2>/dev/null`
  43. ncores_p2=`ssh -n $PRAC_SSH_P2_SSHOPTS $PRAC_SSH_P2_USERHOST $PRAC_NUMA_P2 nproc 2>/dev/null`
  44. fi
  45. if [ $ncores_p0 != $ncores_p1 -o $ncores_p1 != $ncores_p2 ]; then
  46. echo "Error: all players must have the same number of cores available to use." >&2
  47. echo "Use PRAC_NUMA_P[012] to set that if needed." >&2
  48. exit 1
  49. fi
  50. ptarg_p0=""
  51. ptarg_p1=""
  52. ptarg_p2=""
  53. targ_p0=""
  54. targ_p1=""
  55. targ_p2=""
  56. if [ "$preproc" = 1 ]; then
  57. ptarg_p0="p:${ncores_p0}"
  58. ptarg_p1="p:${ncores_p1}"
  59. ptarg_p2="p:${ncores_p2}"
  60. else
  61. targ_p0="-t ${ncores_p0}"
  62. targ_p1="-t ${ncores_p1}"
  63. targ_p2="-t ${ncores_p2}"
  64. fi
  65. echo ===== Running prac $opts -- $*
  66. date "+===== Start %s %F %T"
  67. # Run, saving the output
  68. savefile0=$$.p0.out
  69. savefile1=$$.p1.out
  70. savefile2=$$.p2.out
  71. 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 $* $ptarg_p0 > $savefile0 2>&1" &
  72. 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 $* $ptarg_p1 > $savefile1 2>&1" &
  73. 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 $* $ptarg_p2 > $savefile2 2>&1" &
  74. wait
  75. echo ===== P0 output
  76. ssh -n $PRAC_SSH_P0_SSHOPTS $PRAC_SSH_P0_USERHOST "cd $PRAC_SSH_P0_DIR && cat $savefile0 && rm -f $savefile0"
  77. echo ===== P1 output
  78. ssh -n $PRAC_SSH_P1_SSHOPTS $PRAC_SSH_P1_USERHOST "cd $PRAC_SSH_P1_DIR && cat $savefile1 && rm -f $savefile1"
  79. echo ===== P2 output
  80. ssh -n $PRAC_SSH_P2_SSHOPTS $PRAC_SSH_P2_USERHOST "cd $PRAC_SSH_P2_DIR && cat $savefile2 && rm -f $savefile2"
  81. date "+===== End %s %F %T"