|
|
@@ -6,7 +6,7 @@ |
|
|
# ./cudalucas2.sh <N> "$USER" "$HOSTNAME" 100 10 |
|
|
# ./cudalucas2.sh <N> ANONYMOUS |
|
|
|
|
|
DIR1="cudalucas" |
|
|
DIR="cudalucas" |
|
|
if [[ $# -lt 1 || $# -gt 5 ]]; then |
|
|
echo "Usage: $0 <Computer number> [PrimeNet User ID] [Computer name] [Type of work] [Idle time to run (mins)]" >&2 |
|
|
exit 1 |
|
|
@@ -16,6 +16,7 @@ USERID=${2:-$USER} |
|
|
COMPUTER=${3:-$HOSTNAME} |
|
|
TYPE=${4:-100} |
|
|
TIME=${5:-10} |
|
|
DEVICE=0 |
|
|
RE='^[0-9]+$' |
|
|
if ! [[ $N =~ $RE ]]; then |
|
|
echo "Usage: <Computer number> must be a number" >&2 |
|
|
@@ -68,13 +69,13 @@ if ! command -v python3 >/dev/null; then |
|
|
exit 1 |
|
|
fi |
|
|
TIME=$(echo "$TIME" | awk '{ printf "%g", $1 * 60 }') |
|
|
if [[ -d "$DIR1" && -x "$DIR1/CUDALucas" ]]; then |
|
|
if [[ -d "$DIR" && -x "$DIR/CUDALucas" ]]; then |
|
|
echo -e "CUDALucas is already downloaded\n" |
|
|
cd "$DIR1" |
|
|
cd "$DIR" |
|
|
else |
|
|
echo -e "Downloading CUDALucas\n" |
|
|
svn checkout https://svn.code.sf.net/p/cudalucas/code/trunk "$DIR1" |
|
|
cd "$DIR1" |
|
|
svn checkout https://svn.code.sf.net/p/cudalucas/code/trunk "$DIR" |
|
|
cd "$DIR" |
|
|
echo -e "\nSetting up CUDALucas\n" |
|
|
sed -i 's/^OptLevel = 1/OptLevel = 3/' Makefile |
|
|
CUDA=$(command -v nvcc | sed 's/\/bin\/nvcc$//') |
|
|
@@ -86,12 +87,12 @@ else |
|
|
int main() |
|
|
{ |
|
|
cudaDeviceProp prop; |
|
|
cudaError_t status = cudaGetDeviceProperties(&prop, 0); |
|
|
cudaError_t status = cudaGetDeviceProperties(&prop, $DEVICE); |
|
|
if (status != cudaSuccess) { |
|
|
fprintf(stderr, "cudaGetDeviceProperties() for device 0 failed: %s\n", cudaGetErrorString(status)); |
|
|
fprintf(stderr, "cudaGetDeviceProperties() for device $DEVICE failed: %s\n", cudaGetErrorString(status)); |
|
|
return 1; |
|
|
} |
|
|
int v = prop.major * 10 + prop.minor; |
|
|
const int v = prop.major * 10 + prop.minor; |
|
|
printf("--generate-code arch=compute_%d,code=sm_%d\n", v, v); |
|
|
return 0; |
|
|
} |
|
|
@@ -124,7 +125,7 @@ if [[ -f "primenet.py" ]]; then |
|
|
else |
|
|
echo -e "\nDownloading the PrimeNet script\n" |
|
|
if [[ -e ../primenet.py ]]; then |
|
|
cp ../primenet.py . |
|
|
cp -v ../primenet.py . |
|
|
else |
|
|
wget https://raw.github.com/tdulcet/Distributed-Computing-Scripts/master/primenet.py -nv |
|
|
fi |
|
|
@@ -138,20 +139,21 @@ fi |
|
|
cp CUDALucas.ini "CUDALucas$N.ini" |
|
|
sed -i "s/^WorkFile=worktodo.txt/WorkFile=worktodo$N.txt/" "CUDALucas$N.ini" |
|
|
sed -i "s/^ResultsFile=results.txt/ResultsFile=results$N.txt/" "CUDALucas$N.ini" |
|
|
sed -i "s/^DeviceNumber=0/DeviceNumber=$DEVICE/" "CUDALucas$N.ini" |
|
|
echo -e "\nRegistering computer with PrimeNet\n" |
|
|
ARGS=() |
|
|
if command -v nvidia-smi >/dev/null && nvidia-smi >/dev/null; then |
|
|
mapfile -t GPU < <(nvidia-smi --query-gpu=gpu_name --format=csv,noheader) |
|
|
ARGS+=( --cpu_model="${GPU[0]}" ) |
|
|
ARGS+=( --cpu_model="${GPU[DEVICE]}" ) |
|
|
|
|
|
mapfile -t GPU_FREQ < <(nvidia-smi --query-gpu=clocks.max.gr --format=csv,noheader,nounits | grep -iv 'not supported') |
|
|
if [[ -n "$GPU_FREQ" ]]; then |
|
|
ARGS+=( --frequency="${GPU_FREQ[0]}" ) |
|
|
ARGS+=( --frequency="${GPU_FREQ[DEVICE]}" ) |
|
|
fi |
|
|
|
|
|
mapfile -t TOTAL_GPU_MEM < <(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | grep -iv 'not supported') |
|
|
if [[ -n "$TOTAL_GPU_MEM" ]]; then |
|
|
ARGS+=( -m "${TOTAL_GPU_MEM[0]}" ) |
|
|
ARGS+=( -m "${TOTAL_GPU_MEM[DEVICE]}" ) |
|
|
fi |
|
|
fi |
|
|
python3 primenet.py -d -t 0 -T "$TYPE" -u "$USERID" -i "worktodo$N.txt" -r "results$N.txt" -l "local$N.ini" --cudalucas "cudalucas$N.out" -H "$COMPUTER" "${ARGS[@]}" |
|
|
@@ -168,6 +170,6 @@ echo -e "\nStarting CUDALucas\n" |
|
|
nohup nice ./CUDALucas -i "CUDALucas$N.ini" >> "cudalucas$N.out" & |
|
|
sleep 1 |
|
|
echo -e "\nSetting it to start if the computer has not been used in the specified idle time and stop it when someone uses the computer\n" |
|
|
#crontab -l | { cat; echo "cd \"$DIR\" && nohup nice ./CUDALucas -i \"CUDALucas$N.ini\" >> \"cudalucas$N.out\" &"; } | crontab - |
|
|
#crontab -l | { cat; echo "cd \"$DIR\" && nohup python3 primenet.py -d -t 21600 -l \"local$N.ini\" >> \"primenet$N.out\" &"; } | crontab - |
|
|
crontab -l | { cat; echo "* * * * * if who -s | awk '{ print \$2 }' | (cd /dev && xargs -r stat -c '\%U \%X') | awk '{if ('\"\${EPOCHSECONDS:-\$(date +\%s)}\"'-\$2<$TIME) { print \$1\"\t\"'\"\${EPOCHSECONDS:-\$(date +\%s)}\"'-\$2; ++count }} END{if (count>0) { exit 1 }}' >/dev/null; then pgrep -x CUDALucas >/dev/null || (cd \"$DIR\" && nohup nice ./CUDALucas -i \"CUDALucas$N.ini\" >> \"cudalucas$N.out\" &); pgrep -f '^python3 primenet\.py' >/dev/null || (cd \"$DIR\" && nohup python3 primenet.py -d -t 21600 -l \"local$N.ini\" >> \"primenet$N.out\" &); else pgrep -x CUDALucas >/dev/null && killall CUDALucas; fi"; } | crontab - |
|
|
#crontab -l | { cat; echo "cd ${DIR@Q} && nohup nice ./CUDALucas -i 'CUDALucas$N.ini' >> 'cudalucas$N.out' &"; } | crontab - |
|
|
#crontab -l | { cat; echo "cd ${DIR@Q} && nohup python3 primenet.py -d -t 21600 -l 'local$N.ini' >> 'primenet$N.out' &"; } | crontab - |
|
|
crontab -l | { cat; echo "* * * * * if who -s | awk '{ print \$2 }' | (cd /dev && xargs -r stat -c '\%U \%X') | awk '{if ('\"\${EPOCHSECONDS:-\$(date +\%s)}\"'-\$2<$TIME) { print \$1\"\t\"'\"\${EPOCHSECONDS:-\$(date +\%s)}\"'-\$2; ++count }} END{if (count>0) { exit 1 }}' >/dev/null; then pgrep -x CUDALucas >/dev/null || (cd ${DIR@Q} && exec nohup nice ./CUDALucas -i 'CUDALucas$N.ini' >> 'cudalucas$N.out' &); pgrep -f '^python3 primenet\.py' >/dev/null || (cd ${DIR@Q} && exec nohup python3 primenet.py -d -t 21600 -l 'local$N.ini' >> 'primenet$N.out' &); else pgrep -x CUDALucas >/dev/null && killall CUDALucas; fi"; } | crontab - |