diff --git a/dev_container b/dev_container index 278616037..47c35486d 100755 --- a/dev_container +++ b/dev_container @@ -874,6 +874,7 @@ build_and_run_desc() { c_echo 'Build and run a requested application in a Docker --run_args : Run the app with additional args --verbose : Print extra output to console --dryrun : View build and run commands without doing anything + --parallel_jobs: Set the # of parallel build jobs, e.g. $(($(nproc)-1)) ' } @@ -892,6 +893,7 @@ build_and_run() { local run_app=1 local install="" local configure_args="" + local parallel_jobs="" # Parse CLI arguments next while [[ $# -gt 0 ]]; do @@ -1014,6 +1016,16 @@ build_and_run() { exit 1 fi ;; + --parallel_jobs) + if [[ -n "$2" ]]; then + parallel_jobs="--parallel '$2'" + shift 2 + else + echo "Error: --parallel_jobs requires a value" + build_and_run_desc + exit 1 + fi + ;; *) if [[ -z "$app_name" ]]; then app_name="$1" @@ -1057,7 +1069,7 @@ build_and_run() { run_command ${SCRIPT_DIR}/dev_container build "${container_build_args[@]}" if [[ $build_app == 1 ]]; then c_echo "Building application..." - run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name $install $extra_build_with $extra_build_args" + run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name $install $parallel_jobs $extra_build_with $extra_build_args" fi if [[ $run_app == 1 ]]; then diff --git a/run b/run index 30c80f343..f9b6c2be2 100755 --- a/run +++ b/run @@ -557,6 +557,9 @@ build_desc() { echo " --configure-args : Additional configuration arguments" echo " multiple arguments can be passed between quotes" echo " or using several --configure-args in the command line" + echo " --parallel : Build in parallel using the given number of jobs." + echo " Only needed to override the native build tool's default." + echo " Example: --parallel $(($(nproc)-1))" echo "" echo "Prior to the first build use './run setup' to install the required dependencies" echo "" @@ -619,6 +622,7 @@ build() { local build_path="${CMAKE_BUILD_PATH}" local benchmark=false local install=false + local parallel_jobs="" for i in "${!ARGS[@]}"; do arg="${ARGS[i]}" @@ -650,6 +654,10 @@ build() { elif [ "$arg" = "--buildpath" ]; then build_path="${ARGS[i+1]}" skipnext=1 + elif [ "$arg" = "--parallel" ]; then + parallel_jobs="${ARGS[i+1]}" + echo "Setting the number of parallel build jobs: ${ARGS[i+1]}" + skipnext=1 elif [[ $arg = -* ]]; then print_error "Unknown option $arg" exit 1 @@ -692,7 +700,8 @@ build() { run_command cmake -S . -B ${build_path} ${cmake_extra_args} -DCMAKE_BUILD_TYPE=${build_type} ${holoscan_sdk} ${application} ret=$? check_exit_code $ret "Error building application." - run_command cmake --build ${build_path} -j + # Job concurrency determined by the underlying build tool unless a number is specified + run_command cmake --build ${build_path} -j ${parallel_jobs} ret=$? check_exit_code $ret "Error building application."