Skip to content

Commit f477b47

Browse files
committed
add progress bar
1 parent af4d31b commit f477b47

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

juhpc

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,41 @@ check_dir() {
6565

6666
julia_pref() {
6767
local cmd="$1"
68+
local progress="${2:-}" # The second argument is optional, default to an empty string if not provided
69+
6870
if [[ "$JUHPC_VERBOSE" -gt 1 ]]; then
6971
julia --project="$JULIA_PREFDIR" -e "$cmd" 2>&1 | tee -a "$JUHPC_SETUP_INSTALLLOG"
7072
else
7173
julia --project="$JULIA_PREFDIR" -e "$cmd" >> "$JUHPC_SETUP_INSTALLLOG" 2>&1
7274
fi
75+
76+
if [[ -n "$progress" ]]; then
77+
progress_bar "$progress"
78+
fi
79+
}
80+
81+
percent() {
82+
local p=00$(($1*100000/$2))
83+
printf -v "$3" %.2f ${p::-3}.${p: -3}
84+
}
85+
86+
progress_bar() {
87+
local progress=$1
88+
local width=${2:-50} # Default to a width of 50 if not provided
89+
local percent_var
90+
percent "$progress" 100 percent_var # Always assume total is 100
91+
local filled_length=$((width * progress / 100))
92+
local bar=""
93+
94+
if [[ "$JUHPC_VERBOSE" -lt 2 ]]; then
95+
for ((i=0; i<filled_length; i++)); do
96+
bar+=""
97+
done
98+
for ((i=filled_length; i<width; i++)); do
99+
bar+=""
100+
done
101+
printf '\r|%s| %s%%' "$bar" "$percent_var"
102+
fi
73103
}
74104

75105

@@ -144,15 +174,17 @@ export JULIA_PREF_PROJECT="$JULIA_PREFDIR/Project.toml"
144174
export JULIA_PREFS="$JULIA_PREFDIR/LocalPreferences.toml"
145175
mkdir -p "$JULIA_PREFDIR" || { error "failed to create directory: $JULIA_PREFDIR"; }
146176

177+
progress_bar 1 # Initialize progress bar.
178+
147179
if [[ -n "${JUHPC_CUDA_HOME}" || -n "${JUHPC_ROCM_HOME}" ]]; then
148-
julia_pref 'using Pkg; Pkg.add("Preferences")'
180+
julia_pref 'using Pkg; Pkg.add("Preferences")' 5
149181
echo "[extras]" >> "$JULIA_PREF_PROJECT"
150182
fi
151183

152184
if [ -n "${JUHPC_CUDA_HOME}" ]; then # Set preference for using the local CUDA runtime before any installation of CUDA.jl to avoid downloading of artifacts
153185
echo 'CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"' >> "$JULIA_PREF_PROJECT"
154186

155-
julia_pref 'using Preferences; set_preferences!("CUDA_Runtime_jll", "local"=>true)'
187+
julia_pref 'using Preferences; set_preferences!("CUDA_Runtime_jll", "local"=>true)' 10
156188
if [ -n "${JUHPC_CUDA_RUNTIME_VERSION}" ]; then
157189
julia_pref 'using Preferences; set_preferences!("CUDA_Runtime_jll", "version"=>join(split(ENV["JUHPC_CUDA_RUNTIME_VERSION"],".")[1:2],"."))'
158190
fi
@@ -161,28 +193,28 @@ fi
161193
if [ -n "${JUHPC_ROCM_HOME}" ]; then # Set preference for using the local ROCm runtime before any installation of AMDGPU.jl to avoid downloading of artifacts
162194
echo 'AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"' >> "$JULIA_PREF_PROJECT"
163195

164-
julia_pref 'using Preferences; set_preferences!("AMDGPU", "use_artifacts"=>false, "eager_gc"=>false)'
196+
julia_pref 'using Preferences; set_preferences!("AMDGPU", "use_artifacts"=>false, "eager_gc"=>false)' 15
165197
fi
166198

167199
if [ -n "${JUHPC_CUDA_HOME}" ]; then export CUDA_HOME="$JUHPC_CUDA_HOME"; fi
168200
if [ -n "${JUHPC_ROCM_HOME}" ]; then export ROCM_PATH="$JUHPC_ROCM_HOME"; fi
169201

170-
julia_pref 'using Pkg; Pkg.add([p for (p,l) in [("MPIPreferences", "JUHPC_MPI_VENDOR"), ("MPIPreferences", "JUHPC_MPI_HOME"), ("CUDA", "JUHPC_CUDA_HOME"), ("AMDGPU", "JUHPC_ROCM_HOME"), ("HDF5", "JUHPC_HDF5_HOME")] if haskey(ENV,l) && ENV[l]!=""])'
202+
julia_pref 'using Pkg; Pkg.add([p for (p,l) in [("MPIPreferences", "JUHPC_MPI_VENDOR"), ("MPIPreferences", "JUHPC_MPI_HOME"), ("CUDA", "JUHPC_CUDA_HOME"), ("AMDGPU", "JUHPC_ROCM_HOME"), ("HDF5", "JUHPC_HDF5_HOME")] if haskey(ENV,l) && ENV[l]!=""])' 50
171203

172204
if [ -n "${JUHPC_CUDA_HOME}" ]; then # Set preference for using the local CUDA runtime in a more stable way (in case the previous would not be valid anymore)
173-
julia_pref 'using CUDA; CUDA.set_runtime_version!((VersionNumber(join(split(ENV[key],".")[1:2],".")) for key in ["JUHPC_CUDA_RUNTIME_VERSION"] if haskey(ENV,key) && ENV[key]!=="")...; local_toolkit=true)'
205+
julia_pref 'using CUDA; CUDA.set_runtime_version!((VersionNumber(join(split(ENV[key],".")[1:2],".")) for key in ["JUHPC_CUDA_RUNTIME_VERSION"] if haskey(ENV,key) && ENV[key]!=="")...; local_toolkit=true)' 60
174206
fi
175207

176208
if [ -n "${JUHPC_ROCM_HOME}" ]; then # Set preference for using the local ROCm runtime in a more stable way (in case the previous would not be valid anymore)
177-
julia_pref 'using AMDGPU; AMDGPU.ROCmDiscovery.use_artifacts!(false)'
209+
julia_pref 'using AMDGPU; AMDGPU.ROCmDiscovery.use_artifacts!(false)' 70
178210
fi
179211

180212
if [ -n "${JUHPC_MPI_VENDOR}" ]; then
181213
check_var "JUHPC_MPI_EXEC"
182-
julia_pref 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), vendor=ENV["JUHPC_MPI_VENDOR"])'
214+
julia_pref 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), vendor=ENV["JUHPC_MPI_VENDOR"])' 90
183215
elif [ -n "${JUHPC_MPI_HOME}" ]; then
184216
check_var "JUHPC_MPI_EXEC"
185-
julia_pref 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), extra_paths=["$(ENV["JUHPC_MPI_HOME"])/lib"])'
217+
julia_pref 'using MPIPreferences; MPIPreferences.use_system_binary(mpiexec=split(ENV["JUHPC_MPI_EXEC"]), extra_paths=["$(ENV["JUHPC_MPI_HOME"])/lib"])' 90
186218
fi
187219

188220
if [ -n "${JUHPC_HDF5_HOME}" ]; then
@@ -191,6 +223,8 @@ fi
191223

192224
if [ ! -s "$JULIA_PREFS" ]; then error "preferences file is missing or empty."; fi
193225

226+
progress_bar 100 # Finalize progress bar.
227+
194228
info "Preferences:\n$(cat "$JULIA_PREFS")" 1
195229

196230
info "... done: preferences created."
@@ -295,7 +329,9 @@ info "... done: activate script created."
295329

296330
if [ -n "${JUHPC_POST_INSTALL_JL}" ]; then
297331
info "Executing site-specific post-installation julia script (using the project where preferences were set)..."
332+
progress_bar 1 # Initialize progress bar.
298333
julia --project="$JULIA_PREFDIR" "$JUHPC_POST_INSTALL_JL"
334+
progress_bar 100 # Finalize progress bar.
299335
info "... done: post-installation script completed."
300336
fi
301337

0 commit comments

Comments
 (0)