Skip to content
Permalink
Browse files
Updated scripts for Mlucas v20.
  • Loading branch information
tdulcet committed Aug 1, 2021
1 parent 9f98771 commit d7907eb8bded348515be29d162a906656e5f78d8
Showing with 316 additions and 135 deletions.
  1. +1 −1 README.md
  2. +16 −15 cudalucas.sh
  3. +17 −15 cudalucas2.sh
  4. +1 −1 google-colab/GoogleColabCPU.ipynb
  5. +1 −1 google-colab/GoogleColabGPU.ipynb
  6. +60 −31 mlucas.sh
  7. +3 −0 mprime-python-port/exp.py
  8. +1 −1 mprime-python-port/mprime.py
  9. +3 −0 mprime.exp
  10. +12 −5 mprime.sh
  11. +3 −0 mprime2.exp
  12. +12 −5 mprime2.sh
  13. +186 −60 primenet.py
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/tdulcet/Distributed-Computing-Scripts.svg?branch=master)](https://travis-ci.org/tdulcet/Distributed-Computing-Scripts)
[![Build Status](https://travis-ci.com/tdulcet/Distributed-Computing-Scripts.svg?branch=master)](https://travis-ci.com/tdulcet/Distributed-Computing-Scripts)
[![Actions Status](https://github.com/tdulcet/Distributed-Computing-Scripts/workflows/CI/badge.svg?branch=master)](https://github.com/tdulcet/Distributed-Computing-Scripts/actions)

# Distributed Computing Scripts
@@ -6,7 +6,7 @@
# ./cudalucas.sh "$USER" "$HOSTNAME" 100 10
# ./cudalucas.sh ANONYMOUS

DIR1="cudalucas"
DIR="cudalucas"
if [[ $# -gt 4 ]]; then
echo "Usage: $0 [PrimeNet User ID] [Computer name] [Type of work] [Idle time to run (mins)]" >&2
exit 1
@@ -15,6 +15,7 @@ USERID=${1:-$USER}
COMPUTER=${2:-$HOSTNAME}
TYPE=${3:-100}
TIME=${4:-10}
DEVICE=0
RE='^10[0124]$'
if ! [[ $TYPE =~ $RE ]]; then
echo "Usage: [Type of work] must be a number" >&2
@@ -34,7 +35,7 @@ if [[ -e idletime.sh ]]; then
else
wget https://raw.github.com/tdulcet/Distributed-Computing-Scripts/master/idletime.sh -qO - | bash -s
fi
if [[ -d "$DIR1" ]]; then
if [[ -d "$DIR" ]]; then
echo "Error: CUDALucas is already downloaded" >&2
exit 1
fi
@@ -67,12 +68,12 @@ if ! command -v python3 >/dev/null; then
fi
TIME=$(echo "$TIME" | awk '{ printf "%g", $1 * 60 }')
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"
DIR=$PWD
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
@@ -95,12 +96,12 @@ cat << EOF > /tmp/cudaComputeVersion.cu
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;
}
@@ -131,16 +132,16 @@ 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.txt" --cudalucas "cudalucas.out" -H "$COMPUTER" "${ARGS[@]}"
@@ -154,9 +155,9 @@ echo -e "\nOptimizing CUDALucas for your computer and GPU\nThis may take a while
# ./CUDALucas -r 1
# ./CUDALucas 6972593
echo -e "\nStarting CUDALucas\n"
nohup nice ./CUDALucas >> "cudalucas.out" &
nohup nice ./CUDALucas -d $DEVICE >> "cudalucas.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 >> \"cudalucas.out\" &"; } | crontab -
#crontab -l | { cat; echo "cd \"$DIR\" && nohup python3 primenet.py -d -t 21600 >> \"primenet.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 >> \"cudalucas.out\" &); pgrep -f '^python3 primenet\.py' >/dev/null || (cd \"$DIR\" && nohup python3 primenet.py -d -t 21600 >> \"primenet.out\" &); else pgrep -x CUDALucas >/dev/null && killall CUDALucas; fi"; } | crontab -
#crontab -l | { cat; echo "cd ${DIR@Q} && nohup nice ./CUDALucas -d $DEVICE >> 'cudalucas.out' &"; } | crontab -
#crontab -l | { cat; echo "cd ${DIR@Q} && nohup python3 primenet.py -d -t 21600 >> 'primenet.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} && nohup nice ./CUDALucas -d $DEVICE >> 'cudalucas.out' &); pgrep -f '^python3 primenet\.py' >/dev/null || (cd ${DIR@Q} && nohup python3 primenet.py -d -t 21600 >> 'primenet.out' &); else pgrep -x CUDALucas >/dev/null && killall CUDALucas; fi"; } | crontab -
@@ -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 -
@@ -82,7 +82,7 @@
" !sed -i 's/\"mprime\"/\"mprime_cpu\"/' mprime2.sh # Name the folder specific to the runtime type\n",
" !sed -i '/^nohup / s/^/# /' mprime2.sh # Do not start Prime95\n",
" !sed -i '/^crontab / s/^/# /' mprime2.sh # Do not create a cronjob\n",
" !sed -i '/^expect {/a \\\\t\"Upload bandwidth limit in Mbps (*):\" { sleep 1; send -- \"10000\\\\r\"; exp_continue }\\n\\t\"Skip advanced resource settings (*):\" { sleep 1; send -- \"n\\\\r\"; exp_continue }\\n\\t\"Optional directory to hold *:\" { sleep 1; send -- \"\\\\r\"; exp_continue }\\n\\t\"stage 2 memory in GB (*):\" { sleep 1; send -- \"6\\\\r\"; exp_continue }\\n\\t\"Max emergency memory in GB/worker (*):\" { sleep 1; send -- \"3\\\\r\"; exp_continue }\\n\\t\"Get occasional proof certification work (*):\" { sleep 1; send -- \"PROOF_CERTIFICATION_WORK\\\\r\"; exp_continue }' mprime2.exp\n",
" !sed -i '/^expect {/a \\\\t\"Max emergency memory in GB/worker (*):\" { sleep 1; send -- \"3\\\\r\"; exp_continue }\\n\\t\"Get occasional proof certification work (*):\" { sleep 1; send -- \"PROOF_CERTIFICATION_WORK\\\\r\"; exp_continue }' mprime2.exp\n",
" !sed -i 's/PROOF_CERTIFICATION_WORK/'$proof_certification_work'/' mprime2.exp\n",
" ![[ -d 'mprime_cpu' ]] && cd mprime_cpu && chmod 777 mprime\n",
" !bash -- mprime2.sh $computer_number $prime_ID $computer_name $type_of_work # Run script\n",
@@ -108,7 +108,7 @@
" !sed -i 's/\"mprime\"/\"mprime_gpu\"/' mprime2.sh # Name the folder specific to the runtime type\n",
" !sed -i '/^nohup / s/^/# /' mprime2.sh # Do not start Prime95\n",
" !sed -i '/^crontab / s/^/# /' mprime2.sh # Do not create a cronjob\n",
" !sed -i '/^expect {/a \\\\t\"Upload bandwidth limit in Mbps (*):\" { sleep 1; send -- \"10000\\\\r\"; exp_continue }\\n\\t\"Skip advanced resource settings (*):\" { sleep 1; send -- \"n\\\\r\"; exp_continue }\\n\\t\"Optional directory to hold *:\" { sleep 1; send -- \"\\\\r\"; exp_continue }\\n\\t\"stage 2 memory in GB (*):\" { sleep 1; send -- \"6\\\\r\"; exp_continue }\\n\\t\"Max emergency memory in GB/worker (*):\" { sleep 1; send -- \"3\\\\r\"; exp_continue }\\n\\t\"Get occasional proof certification work (*):\" { sleep 1; send -- \"CPU_PROOF_CERTIFICATION_WORK\\\\r\"; exp_continue }' mprime2.exp\n",
" !sed -i '/^expect {/a \\\\t\"Max emergency memory in GB/worker (*):\" { sleep 1; send -- \"3\\\\r\"; exp_continue }\\n\\t\"Get occasional proof certification work (*):\" { sleep 1; send -- \"CPU_PROOF_CERTIFICATION_WORK\\\\r\"; exp_continue }' mprime2.exp\n",
" !sed -i 's/CPU_PROOF_CERTIFICATION_WORK/'$CPU_proof_certification_work'/' mprime2.exp\n",
" ![[ -d 'mprime_gpu' ]] && cd mprime_gpu && chmod 777 mprime\n",
" !bash -- mprime2.sh $computer_number $prime_ID $computer_name $CPU_type_of_work # Run script\n",

0 comments on commit d7907eb

Please sign in to comment.