Skip to content

Commit c78cb82

Browse files
authored
chore: Add memsuspend to parallel in bootstrap (#11040)
Adds an optional memsuspend flag to parallel to prevent parallel from consuming too much memory while running.
1 parent 6fc5673 commit c78cb82

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

noir-projects/noir-contracts/bootstrap.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ cmd=${1:-}
2020

2121
export RAYON_NUM_THREADS=${RAYON_NUM_THREADS:-16}
2222
export HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16}
23-
export PARALLELISM=${PARALLELISM:-16}
2423
export PLATFORM_TAG=any
2524

2625
export BB=${BB:-../../barretenberg/cpp/build/bin/bb}
@@ -38,6 +37,13 @@ function on_exit() {
3837
trap on_exit EXIT
3938
mkdir -p $tmp_dir
4039

40+
# Set flags for parallel
41+
export PARALLELISM=${PARALLELISM:-16}
42+
export PARALLEL_FLAGS="-j$PARALLELISM --halt now,fail=1"
43+
if [[ -n "${MEMSUSPEND-}" ]]; then
44+
export PARALLEL_FLAGS="$PARALLEL_FLAGS --memsuspend $MEMSUSPEND"
45+
fi
46+
4147
# This computes a vk and adds it to the input function json if it's private, else returns same input.
4248
# stdin has the function json.
4349
# stdout receives the function json with the vk added (if private).
@@ -117,7 +123,7 @@ function compile {
117123
# .[1] is the updated functions on stdin (-)
118124
# * merges their fields.
119125
jq -c '.functions[]' $json_path | \
120-
parallel -j$PARALLELISM --keep-order -N1 --block 8M --pipe --halt now,fail=1 process_function | \
126+
parallel $PARALLEL_FLAGS --keep-order -N1 --block 8M --pipe process_function | \
121127
jq -s '{functions: .}' | jq -s '.[0] * {functions: .[1].functions}' $json_path - > $tmp_dir/$filename
122128
mv $tmp_dir/$filename $json_path
123129
}
@@ -132,7 +138,7 @@ function build {
132138
set +e
133139
echo_stderr "Compiling contracts (bb-hash: $BB_HASH)..."
134140
grep -oP '(?<=contracts/)[^"]+' Nargo.toml | \
135-
parallel -j$PARALLELISM --joblog joblog.txt -v --line-buffer --tag --halt now,fail=1 compile {}
141+
parallel $PARALLEL_FLAGS --joblog joblog.txt -v --line-buffer --tag compile {}
136142
code=$?
137143
cat joblog.txt
138144
return $code
@@ -164,7 +170,7 @@ function test {
164170
done
165171

166172
echo "Starting test run..."
167-
test_cmds | (cd $root; NARGO_FOREIGN_CALL_TIMEOUT=300000 parallel --bar --halt now,fail=1 'dump_fail {} >/dev/null')
173+
test_cmds | (cd $root; NARGO_FOREIGN_CALL_TIMEOUT=300000 parallel --bar $PARALLEL_FLAGS 'dump_fail {} >/dev/null')
168174
}
169175

170176
case "$cmd" in

noir-projects/noir-protocol-circuits/bootstrap.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ CMD=${1:-}
66

77
export RAYON_NUM_THREADS=${RAYON_NUM_THREADS:-16}
88
export HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16}
9-
export PARALLELISM=${PARALLELISM:-16}
109

1110
export PLATFORM_TAG=any
1211
export BB=${BB:-../../barretenberg/cpp/build/bin/bb}
1312
export NARGO=${NARGO:-../../noir/noir-repo/target/release/nargo}
1413
export BB_HASH=$(cache_content_hash ../../barretenberg/cpp/.rebuild_patterns)
1514
export NARGO_HASH=$(cache_content_hash ../../noir/.rebuild_patterns)
1615

16+
# Set flags for parallel
17+
export PARALLELISM=${PARALLELISM:-16}
18+
export PARALLEL_FLAGS="-j$PARALLELISM -v --line-buffer --tag --halt now,fail=1"
19+
if [[ -n "${MEMSUSPEND-}" ]]; then
20+
export PARALLEL_FLAGS="$PARALLEL_FLAGS --memsuspend $MEMSUSPEND"
21+
fi
22+
1723
tmp_dir=./target/tmp
1824
key_dir=./target/keys
1925

@@ -126,7 +132,7 @@ function build {
126132
echo "$(basename $dir)"
127133
fi
128134
done | \
129-
parallel -j$PARALLELISM --joblog joblog.txt -v --line-buffer --tag --halt now,fail=1 compile {}
135+
parallel $PARALLEL_FLAGS --joblog joblog.txt compile {}
130136
code=$?
131137
cat joblog.txt
132138
return $code

0 commit comments

Comments
 (0)