-
Notifications
You must be signed in to change notification settings - Fork 7
/
mfakto.sh
executable file
·81 lines (63 loc) · 1.74 KB
/
mfakto.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
#!/bin/bash
# by teknohog
# Trial Division with OpenCL
# http://mersenneforum.org/showthread.php?t=15646
# https://github.com/Bdot42/mfakto
# https://github.com/teknohog/primetools
# This script runs mfloop.py in the background and mfakto in the
# foreground, so that new work can be fetched while another number is
# being factorized. This needs -n 2 or higher in WORKOPTS, as the
# ongoing work unit is counted as one.
# To use -n 1, there is the alternative wrapper script mfaktc.sh which
# does not use background fetch. You can also use the -1 option here
# to fetch, factor and return a single batch of work, including -n 1
# for a single work unit.
LOOP="mfloop.py"
BASEOPTS="-u teknohog -p topsecret -d"
WORKOPTS="-n 2"
# Prefer gpu72.com work assignments; 72 is hardcoded minimum, but a
# lower -e still works for the Primenet fallback
#BASEOPTS="-u teknohog -p topsecret -U teknohog -P setecastronomy -d"
BASEDIR=~/sources/mfakto
FACT="mfakto"
# Defaults
DEVICE=1
FLUSH=false
ONESHOT=false
while getopts 1d:f opt; do
case $opt in
1)
ONESHOT=true
;;
d)
DEVICE=$OPTARG
;;
f)
FLUSH=true
;;
esac
done
cd $BASEDIR
# mfloop.py lockfiles may be left over after crashes
rm *.txt.lck
# 2024-02-08 From mfaktc.sh
if $ONESHOT; then
# 2020-09-02 Fetch, process and send one batch of work
$LOOP $BASEOPTS $WORKOPTS -t 0
FLUSH=true
fi
if $FLUSH; then
# Complete current work and submit results only at the end
./$FACT -d $DEVICE
$LOOP $BASEOPTS -n 0 -t 0
exit
fi
# Default: run indefinitely, getting new work in a loop
$LOOP $BASEOPTS $WORKOPTS &
LOOPID=$!
# Wait for initial work
while [ ! -e worktodo.txt ] || [ "$(wc -w < worktodo.txt)" == "0" ]; do
sleep 2
done
./$FACT -d $DEVICE
kill $LOOPID