rccerun 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #! /bin/bash
  2. #
  3. # Copyright 2010 Intel Corporation
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. #set ECHO_COMAND to 1 to see what gets executed
  18. ECHO_COMMAND=1
  19. if [ $# -lt 3 ]; then
  20. echo "Usage: \"$0 -nue <number of UEs> [-f HOSTFILE] [-clock GHz] <executable> [executable parameters]\""
  21. exit 0
  22. fi
  23. # set defaults
  24. # NUESET: set to 1 once number of UEs has been read
  25. # OMPEMULATOR: set to one if the emulator is to be used, zero otherwise
  26. # HOSTFILESET: set to 1 if a host file has been specified explicitly
  27. # MAXCORES: maximum available number of cores on the chip
  28. # REFCLOCKGHZ: nominal frequency of chip in GHz
  29. # HOSTFILE: name of file from which core IDs are read
  30. # STOP: set to 1 once name of executable has been retrieved from command line
  31. NUESET=0
  32. OMPEMULATOR=0
  33. HOSTFILESET=0
  34. MAXCORES=48
  35. REFCLOCKGHZ=0.533
  36. HOSTFILE=hosts/rc.hosts
  37. STOP=0
  38. #store the PID for use in the creation of temporary files
  39. PID=$$
  40. #record number of command line parameters of the script
  41. NUMPARS=$#
  42. # process command line parameters (skip #0, i.e. name of this script)
  43. PAR=1
  44. while [ $PAR -le $NUMPARS ] && [ $STOP -ne 1 ]; do
  45. eval OPT=\$$PAR
  46. # determine if the parameter starts with a hyphen (i.e. it is a RCCE option)
  47. STRIPOPT=`echo $OPT | sed -e 's/^-//'`
  48. if [ $OPT != $STRIPOPT ]; then
  49. OPTNAME=$STRIPOPT
  50. if [ $OPTNAME != emulator ]; then
  51. PAR=`expr $PAR + 1`
  52. eval OPTVAL=\$$PAR
  53. fi
  54. case $OPTNAME in
  55. nue ) NUE=$OPTVAL; NUESET=1 ;;
  56. f ) HOSTFILE=$OPTVAL; HOSTFILESET=1 ;;
  57. clock ) REFCLOCKGHZ=$OPTVAL ;;
  58. emulator ) OMPEMULATOR=1 ;;
  59. * ) echo Error: wrong option $OPTNAME; exit ;;
  60. esac
  61. else
  62. # if the parameter did not start with a hyphen, we have reached the
  63. # place where an executable should be (implies NUE must have been set)
  64. if [ $NUESET = 1 ]; then
  65. EXE=$OPT
  66. # PARSTART is sequence number of script parameters where parameters for executable start
  67. PARSTART=`expr $PAR + 1`
  68. STOP=1
  69. else
  70. echo Error: Did not find number of UEs ; exit
  71. fi
  72. fi
  73. PAR=`expr $PAR + 1`
  74. done
  75. if [ $NUE -lt 1 ] || [ $NUE -gt $MAXCORES ]; then
  76. echo Error: number of UEs invalid: $NUE
  77. exit
  78. fi
  79. if [ $STOP -ne 1 ]; then
  80. echo Error: no executable specified
  81. exit
  82. fi
  83. # test whether the rc.hosts file exists. If it does, read as many
  84. # lines from it as there are UEs requested for this run. Host file
  85. # should contain list of core IDs (one per line), no duplications,
  86. # no empty lines.
  87. if [ ! -r $HOSTFILE ]; then
  88. echo Error: Could not find or read hostfile
  89. exit
  90. fi
  91. HOSTLINES=`wc -l $HOSTFILE | awk '{ print $1 }'`
  92. if [ $HOSTLINES -lt $NUE ]; then
  93. echo Error: Number of UEs requested exceeds number of available UEs
  94. exit
  95. fi
  96. # compose list of command line parameters for the executable
  97. # First three parameters are always the same, namely executable name,
  98. # number of UEs, and reference clock frequency in GHz.
  99. ARGS="$NUE $REFCLOCKGHZ"
  100. # In the next loop we record the core IDs from the host file.
  101. # Need to do some obscure redirecting to prevent starting subshells,
  102. # see page 48 of "Portable Shell Programming" by Bruce Blinn.
  103. # If we are not in OpenMP emulation mode, we also need to create a
  104. # (temporary) file with the right syntax to feed to the pssh
  105. # command.
  106. if [ $OMPEMULATOR -eq 0 ]; then
  107. TEMPFILE=PSSH_HOST_FILE.$PID
  108. # if the file already exists, keep on padding its tail until
  109. # a unique name is created
  110. while [ -f $TEMPFILE ]; do
  111. TEMPFILE=$TEMPFILE.$PID
  112. done
  113. fi
  114. NUEaux=0
  115. exec 3<&0 < $HOSTFILE
  116. while read LINE && [ $NUEaux -lt $NUE ]; do
  117. ARGS="$ARGS $LINE"
  118. if [ $OMPEMULATOR -eq 0 ]; then
  119. echo rck$LINE root >> $TEMPFILE
  120. fi
  121. NUEaux=`expr $NUEaux + 1`
  122. done
  123. # Undo obscure redirecting
  124. exec 0<&3 3<&-
  125. # add the parameters for the actual executable; to avoid running over
  126. # the maximum allowed number of arguments (10), we shift the parameter
  127. # list after each reading of a parameter
  128. PAR=$PARSTART
  129. while [ $PAR -le $NUMPARS ]; do
  130. eval PARAMETER=\$$PARSTART
  131. ARGS="$ARGS $PARAMETER"
  132. shift
  133. PAR=`expr $PAR + 1`
  134. done
  135. if [ $OMPEMULATOR -eq 1 ]; then
  136. # start single executable, which will be multithreaded inside the
  137. # OpenMP emulator
  138. if [ $ECHO_COMMAND -eq 1 ]; then
  139. echo $EXE $ARGS
  140. fi
  141. $EXE $ARGS
  142. EXITCODE=$?
  143. else
  144. # clear the MPB and the test&set registers on the execution core set
  145. cp /home/herc/bRCCE_V2.0/bin/SCC_LINUX/mpb mpb.$PID
  146. if [ $ECHO_COMMAND -eq 1 ]; then
  147. echo pssh -h $TEMPFILE -t -1 -p $NUE `pwd`/mpb.$PID "< /dev/null"
  148. fi
  149. pssh -h $TEMPFILE -t -1 -p $NUE `pwd`/mpb.$PID < /dev/null
  150. rm mpb.$PID
  151. # run the code on the actual Rock Creek chip, using pssh. Make
  152. # sure there is no timeout (-t -1), that the number of cores is
  153. # set appropriately (-p $NUE), and that output is displayed (-P).
  154. if [ $ECHO_COMMAND -eq 1 ]; then
  155. echo pssh -h $TEMPFILE -t -1 -P -p $NUE `pwd`/$EXE $ARGS "< /dev/null"
  156. fi
  157. pssh -h $TEMPFILE -t -1 -P -p $NUE `pwd`/$EXE $ARGS < /dev/null
  158. # EXITCODE below only returns status of pssh, not of the RCCE
  159. # executable. would need to do substantial work to get more details
  160. EXITCODE=$?
  161. rm -f $TEMPFILE
  162. fi
  163. exit $EXITCODE