Closed Sumit112192 closed 2 months ago
*beep* *bop* Hi human, I ran ruff on the latest commit (1a47b9bea931c7e7f8b3cfcb2028c58f8e13759c). Here are the outputs produced. Results can also be downloaded as artifacts here. Summarised output:
Complete output(might be large):
@andrewfullard Are there any disadvantages to running the parallel loop that I made?
Attention: Patch coverage is 0%
with 2 lines
in your changes missing coverage. Please review.
Project coverage is 69.25%. Comparing base (
7231707
) to head (1a47b9b
). Report is 4 commits behind head on master.
Files | Patch % | Lines |
---|---|---|
...ardis/transport/montecarlo/montecarlo_main_loop.py | 0.00% | 2 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
*beep* *bop*
Hi, human.
The docs
workflow has succeeded :heavy_check_mark:
Click here to see your results.
Benchmark the change to check if threading overloads shadows the parallel execution to increase run_time.
from numba import njit, prange
from numba.typed import List
import numpy as np
from tardis.transport.montecarlo.packet_trackers import RPacketTracker
@njit()
def aNumbaFuncWithoutParallel(no_of_packets):
length = 100
rpacket_trackers = List()
for i in range(no_of_packets):
rpacket_trackers.append(RPacketTracker(length))
for i in range(no_of_packets):
random_num_interaction = np.random.randint(2, length)
rpacket_trackers[i].num_interactions = random_num_interaction
for rpacket_tracker in rpacket_trackers:
rpacket_tracker.finalize_array()
%timeit aNumbaFuncWithoutParallel(40000)
308 ms ± 6.33 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithoutParallel(100000)
795 ms ± 56.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithoutParallel(200000)
1.52 s ± 70.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithoutParallel(400000)
3.04 s ± 88.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
from numba import njit, prange
from numba.typed import List
import numpy as np
from tardis.transport.montecarlo.packet_trackers import RPacketTracker
@njit(parallel=True)
def aNumbaFuncWithParallel(no_of_packets):
length = 100
rpacket_tracker = List()
for i in range(no_of_packets):
rpacket_tracker.append(RPacketTracker(length))
for i in range(no_of_packets):
random_num_interaction = np.random.randint(1, length)
rpacket_tracker[i].num_interactions = random_num_interaction
for i in prange(no_of_packets):
rpacket_tracker[i].finalize_array()
%timeit aNumbaFuncWithParallel(40000)
/tmp/ipykernel_34215/2781711506.py:12: NumbaTypeSafetyWarning: [1m[1m[1munsafe cast from uint64 to int64. Precision may be lost.[0m[0m[0m
rpacket_tracker[i].finalize_array()
346 ms ± 34.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithParallel(100000)
783 ms ± 63.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithParallel(200000)
1.51 s ± 35.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit aNumbaFuncWithParallel(400000)
3.01 s ± 64.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Since the runtime is nearly the same even with parallel execution, I am closing this PR.
:pencil: Description
Type: :roller_coaster:
infrastructure
Run the loop in montecarlo_main_loop related to
finalize_array
in parallel.