Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill a detection of jot, which produce an error message on pipol, breaking the output...
[simgrid.git] / src / smpi / smpirun.in
1 #!/bin/bash
2 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
3 DEFAULT_LOOPBACK_LATENCY="0.000004"
4 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
5 DEFAULT_NETWORK_LATENCY="0.000005"
6 DEFAULT_NUMPROCS="4"
7 DEFAULT_POWER="100"
8
9 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
10 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
11 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
12 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
13 NUMPROCS="${DEFAULT_NUMPROCS}"
14 POWER="${DEFAULT_POWER}"
15
16 while true; do
17   case "$1" in
18    "-np" | "-n")
19       NUMPROCS="$2"
20       shift 2
21     ;;
22    "-bandwidth")
23       NETWORK_BANDWIDTH="$2"
24       shift 2
25     ;;
26    "-latency")
27       NETWORK_LATENCY="$2"
28       shift 2
29     ;;
30    "-platform")
31         PLATFORM="$2"
32       if [ ! -f ${PLATFORM} ]; then
33                 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
34                 exit 1
35       fi
36         shift 2
37     ;;
38    "-hostfile")
39         HOSTFILE="$2"
40       if [ ! -f ${HOSTFILE} ]; then
41                 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
42                 exit 1
43       fi
44         shift 2
45     ;;
46
47    "-map")
48         MAPOPT="true"
49       shift 1
50    ;;
51
52    "-keep-temps")
53         KEEP="true"
54       shift 1
55    ;;
56
57    "-help" | "--help" | "-h")
58       echo "usage:"
59       echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] -platform <xmldesc> -hostfile <hostfile> [-map] program [program-options]"
60       echo "or (deprecated usage):"
61       echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
62       echo
63       exit
64    ;;
65
66    "--cfg="*|"--log="*)
67      for OPT in ${1#*=}
68      do
69        SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
70      done
71      shift 1
72    ;;
73     *)
74       break
75     ;;
76   esac
77 done
78
79 EXEC="$1"
80 shift
81
82 ##-----------------------------------
83
84
85
86
87 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
88 if [ -z "${PLATFORM}" ]; then
89         PLATFORMTMP="$(mktemp tmpXXXXXX)"
90
91         cat > ${PLATFORMTMP} <<PLATFORMHEAD
92 <?xml version='1.0'?>
93 <!DOCTYPE platform SYSTEM "simgrid.dtd">
94 <platform version="2">
95 PLATFORMHEAD
96
97 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
98   echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
99   echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
100   echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
101 done
102
103 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
104   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
105     if [ $i -eq $j ]; then
106       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
107     else
108       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"link$i\"/><link:ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
109     fi
110   done
111 done
112
113 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
114 </platform>
115 PLATFORMFOOT
116
117 else
118         PLATFORMTMP=${PLATFORM}
119 fi
120 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
121
122 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
123 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
124 #APPLICATIONTMP="app.xml"
125
126
127 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
128 <?xml version='1.0'?>
129 <!DOCTYPE platform SYSTEM "simgrid.dtd">
130 <platform version="2">
131 APPLICATIONHEAD
132
133 ##---- cache hostnames of hostfile---------------
134 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
135         hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
136       NUMHOSTS=`cat ${HOSTFILE} | wc -l`
137 fi
138
139 ##----------------------------------------------------------
140 ##  generate application.xml with hostnames from hostfile:
141 ##  the name of host_i (1<=i<=p, where -np p) is the line i
142 ##  in hostfile (where -hostfile hostfile), or "host$i" if
143 ##  hostfile has less than i lines.
144 ##----------------------------------------------------------
145
146 HAVE_SEQ="`which seq 2>/dev/null`"
147
148 if [ -n "${HAVE_SEQ}" ]; then
149         SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
150 else
151       cnt=0
152         while (( $cnt < ${NUMPROCS} )) ; do
153             SEQ="$SEQ $cnt"
154             cnt=$((cnt + 1));
155         done
156 fi
157
158 ##---- generate <process> tags------------------------------
159
160 for i in ${SEQ}
161 do
162   if [ -n "${HOSTFILE}" ]; then
163         j=$(( $i % ${NUMHOSTS} ))
164   fi
165   ##---- optional display of ranks to process mapping
166   if [ -n "${MAPOPT}" ]; then
167         echo "[rank $i] -> ${hostnames[$j]}"
168   fi
169
170   if [ -z "${hostnames[$j]}" ]; then
171         host="host"$(($j+1))
172   else
173         host="${hostnames[$j]}"
174   fi
175   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
176   echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
177   for ARG in $*; do
178     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
179   done
180   echo "  </process>" >> ${APPLICATIONTMP}
181 done
182
183 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
184 </platform>
185 APPLICATIONFOOT
186 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
187
188 if [ -n "${KEEP}" ] ; then
189   echo ${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
190 fi
191 ${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
192
193 if [ -z "${KEEP}" ] ; then
194    if [ -z "${PLATFORM}" ]; then
195         rm ${PLATFORMTMP}
196    fi
197    rm ${APPLICATIONTMP}
198 fi