-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·74 lines (66 loc) · 2.61 KB
/
test.sh
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
#!/bin/bash
################################################################
# File: test.sh
# Author: Šimon Stupinský
# University: Brno University of Technology
# Faculty: Faculty of Information Technology
# Course: Parallel and Distributed Algorithms
# Date: 04.04.2020
# Last change:08.04.2020
#
# Subscribe: The test shell script to run algorithm that solve
# parallel Line-Of-Sight problem with use max-prescan.
#
################################################################
#####
# @file test.sh
# @brief The script firstly check whether the required input was
# entered on the command line. When was entered also the
# second argument then is computed the relevant number
# of processors according to the numbers of the altitudes
# in the given line-of-sight. Then this script builds the
# program and subseqenlty runs with the computed numbers
# of processors. In the end it removes all created files
# during its execution.
#####
# check whether the input line of sight was entered, otherwise error
if [ "$#" -eq 1 ] || [ "$#" -eq 2 ];
then
LINE_OF_SIGHT=$1
else
echo "Missing string LINE_OF_SIGHT! Usage: ./test.sh LINE_OF_SIGHT"
exit 1
fi
IFS=',' # hyphen (-) is set as delimiter
read -ra ARR <<< "$LINE_OF_SIGHT" # str is read into an array as tokens separated by IFS
IFS=' '
POINTS_NUMBER=${#ARR[@]}
# comput the numbers of processor according to given second argument or by default
if [ "$#" -eq 2 ]
then
# compute the number of processor according to formula n/p >= lg p
if [ "$2" -eq 1 ]
then
PROCESSORS=$(python3 -c "from scipy import optimize; import scipy; import numpy; print(int(numpy.ceil(scipy.optimize.fsolve(lambda x: $POINTS_NUMBER - numpy.lib.scimath.log2(x) * x, 5)[0])))")
# number of processor is equal to n/2
elif [ "$2" -eq 2 ]
then
PROCESSORS=$(python3 -c "from math import ceil; print(ceil($POINTS_NUMBER/2.0))")
# number of processor is equal to n
elif [ "$2" -eq 3 ]
then
PROCESSORS=$(python3 -c "from math import ceil; print(ceil($POINTS_NUMBER))")
# number of processor is equal to 1
else
PROCESSORS=1
fi
# default value is compute according to the rule n/p >= lg p
else
PROCESSORS=$(python3 -c "from scipy import optimize; import scipy; import numpy; print(int(numpy.ceil(scipy.optimize.fsolve(lambda x: $POINTS_NUMBER - numpy.lib.scimath.log2(x) * x, 5)[0])))")
fi
# compile source code
mpic++ --prefix /usr/local/share/OpenMPI -o vid vid.cpp
# run binary
mpirun --prefix /usr/local/share/OpenMPI -np "$PROCESSORS" vid "$LINE_OF_SIGHT"
# clean directory
rm -f vid