Skip to content

Commit

Permalink
Calculate number of CPU??
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Aug 13, 2024
1 parent 71b1dc5 commit 1e2bded
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion before-notebook.d/41_setup-hq-computer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ verdi daemon stop || echo "stop fail"
# Setup hyperqueue computer if needed
HQ_COMPUTER="local-hq"

# XXX: duplicate as 42_??.sh, set in one place as script and reuse?
# Compute number of cpus allocated to the container
CPU_LIMIT=$(awk '{print $1}' /sys/fs/cgroup/cpu.max)
CPU_PERIOD=$(awk '{print $2}' /sys/fs/cgroup/cpu.max)

if [ "$CPU_PERIOD" -ne 0 ]; then
CPU_NUMBER=$(echo "scale=2; $CPU_LIMIT / $CPU_PERIOD" | bc)
echo "Number of CPUs allocated: $CPU_NUMBER"

# for HQ setting round to integer number of CPUs, the left are for system tasks
HQ_CPU_NUMBER=$(echo "scale=0; $CPU_LIMIT / $CPU_PERIOD" | bc)
else
# if no limit (with local OCI without setting cpu limit, use all CPUs)
HQ_CPU_NUMBER=$(nproc)
echo "No CPU limit set"
fi

computer_list=$(verdi computer list)
if echo ${computer_list} | grep -q ${HQ_COMPUTER}; then
echo "${HQ_COMPUTER} already setup"
Expand All @@ -23,7 +40,7 @@ else
--scheduler hyperqueue \
--work-dir /home/${NB_USER}/aiida_run/ \
--mpirun-command "mpirun -np {tot_num_mpiprocs}" \
--mpiprocs-per-machine ${LOCAL_MPI_PROCS}
--mpiprocs-per-machine ${HQ_CPU_NUMBER}

verdi computer configure core.local "${HQ_COMPUTER}" \
--non-interactive \
Expand Down

0 comments on commit 1e2bded

Please sign in to comment.