-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·118 lines (94 loc) · 3.38 KB
/
run.sh
File metadata and controls
executable file
·118 lines (94 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
# Define constants
BUILD_DIRECTORY_LIST="build cmake-build-release cmake-build-debug"
EXEC_NAME="raft"
MIN_COMMAND_COUNT=10
MAX_COMMAND_COUNT=99
print_usage()
{
if [ $# -eq 1 ]; then
echo "ERROR: $1"
fi
echo "USAGE: ./run.sh client_count server_count generate_command_list [build_path]"
echo " client_count: (int) number of client to create"
echo " server_count: (int) number of server to create"
echo " generate_command_list: (yes or no) if yes will generate a command list file for each client"
echo " build_path: (path, optional) path to the directory containing the executable"
exit 1
}
generate_command_list_file()
{
client_index="$1"
file_name="/tmp/command_list_client_${client_index}.txt"
rm -f "${file_name}"
command_count="$(shuf -i ${MIN_COMMAND_COUNT}-${MAX_COMMAND_COUNT} -n 1)"
for command_index in $(seq -w "${command_count}"); do
random_number="$(shuf -i 1-10000 -n 1)"
command="${command_index} command_test ${random_number}"
echo "${command}" >> "${file_name}"
done
}
generate_command_list_files()
{
client_count="$1"
for client_index in $(seq "${client_count}"); do
generate_command_list_file "${client_index}"
done
}
# Check the number of arguments
if [ $# -lt 3 ]; then
print_usage "Invalid number of arguments"
fi
client_count="$1"
server_count="$2"
generate_command_list="$3"
build_path="$4"
number_regex="^[0-9]+$"
# Check if the first and second arguments are numbers
if ! echo "${client_count}" | grep -E "${number_regex}" > /dev/null; then
print_usage "First argument must be a number"
fi
if ! echo "${server_count}" | grep -E "${number_regex}" > /dev/null; then
print_usage "Second argument must be a number"
fi
total_size=$((client_count + server_count + 1))
# Check the generate_command_list
if [ "${generate_command_list}" != "yes" ] && [ "${generate_command_list}" != "no" ]; then
print_usage "Third argument must be 'yes' or 'no'"
fi
# Check the build path (location of the executable)
if [ $# -lt 4 ]; then
echo "No build directory given, looking for one ..."
for path in $BUILD_DIRECTORY_LIST; do
if [ -d "${path}" ] && [ -x "${path}/${EXEC_NAME}" ]; then
build_path="${path}"
echo "Found path ${path}"
break
fi
done
if [ -z "${build_path}" ]; then
print_usage "No build path were found"
fi
fi
# Check if the executable is inside the build path
if ! [ -x "${path}/${EXEC_NAME}" ]; then
print_usage "No executable found in the build path"
fi
# Generate command list files if needed
command_list_files=""
if [ "${generate_command_list}" = "yes" ] && [ "${client_count}" -gt 0 ]; then
generate_command_list_files "${client_count}"
for client_index in $(seq "${client_count}"); do
command_list_files="${command_list_files} /tmp/command_list_client_${client_index}.txt"
done
fi
echo "--------------------------------------------------------------------------"
echo "Running with the following parameters:"
echo "Client count: ${client_count}"
echo "Server count: ${server_count}"
echo "Command list: ${generate_command_list}"
if [ "${generate_command_list}" = "yes" ]; then
echo "Command list files:${command_list_files}"
fi
echo ""
mpirun -np ${total_size} --oversubscribe ./"${build_path}/${EXEC_NAME}" "${client_count}" "${server_count}" ${command_list_files}