-
Notifications
You must be signed in to change notification settings - Fork 1
/
factor.sh
105 lines (91 loc) · 2.07 KB
/
factor.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
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
#!/bin/bash
path=/tmp/
nfile=${path}n.txt
polyfile=${path}poly.txt
basefile=${path}factorbase.txt
pairfile1=${path}abpairs1.txt
pairfile2=${path}abpairs2.txt
factorfile=${path}factor.txt
sieve=./sieve
ccred=$(echo -e "\033[0;31m")
ccgreen=$(echo -e "\033[0;32m")
ccend=$(echo -e "\033[0m")
info="[${ccgreen}Info${ccend}]: "
error="[${ccred}Error${ccend}]: "
if [[ -z "$1" || (! "$(grep "^[ [:digit:] ]*$" <<< $1)") ]]; then
n=$(python -c 'print 2**92+1')
else
n=$1
shift
fi
sievearg=""
np="-np 4"
while [ -n "$1" ]; do
if [ "$1" == "-lattice" ]; then
sieve="latticesieve"
shift
fi
if [ "$1" == "-linear" ]; then
sieve="sieve"
shift
fi
if [ "$1" == "-b" ]; then
sievearg="$sievearg -b $2"
shift 2
fi
if [ "$1" == "-a" ]; then
sievearg="$sievearg -a $2"
shift 2
fi
if [ "$1" == "-s" ]; then
sievearg="$sievearg -s $2"
shift 2
fi
if [ "$1" == "-np" ]; then
np="-np $2"
shift 2
fi
done
echo "${info}Factoring $n..."
echo $n > $nfile
echo "${info}Selecting polynomial..."
./polyselect $nfile $polyfile
if [ $? != "0" ]; then
echo "${error}polyselect failed!"
exit 1
fi
echo "${info}Forming factor bases..."
./factorbase $polyfile $basefile
if [ $? != "0" ]; then
echo "${error}factorbase failed!"
exit 1
fi
echo "${info}Sieving..."
printf "${info}"
/usr/bin/time -f %e -o /tmp/timefile mpirun $np ./$sieve $basefile $pairfile1 $sievearg
if [ $? != "0" ]; then
echo "${error}$sieve failed!"
exit 1
fi
echo "${info}Time consumed by $sieve: $(head -n 1 /tmp/timefile)s"
echo "${info}Checking if there is redundancy in the sieved pairs..."
./checkredundancy $pairfile1
if [ $? != "0" ]; then
echo "${error}checkredundancy failed!"
exit 1
fi
echo "${info}No redundant."
echo "${info}Solving linear system..."
/usr/bin/time -f %e -o /tmp/timefile ./linear $pairfile1 $pairfile2
if [ $? != "0" ]; then
echo "${error}linear failed!"
exit 1
fi
echo "${info}Time consumed by linear: $(head -n 1 /tmp/timefile)s"
echo "${info}Sqrting..."
./sqrt $pairfile2 $factorfile
if [ $? != "0" ]; then
echo "${error}sqrt failed!"
exit 1
fi
echo "${info}Result: $(cat $factorfile)"