-
-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run the loop in parallel #2769
Run the loop in parallel #2769
Conversation
@andrewfullard Are there any disadvantages to running the parallel loop that I made? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2769 +/- ##
==========================================
- Coverage 69.86% 69.25% -0.61%
==========================================
Files 192 196 +4
Lines 15048 15002 -46
==========================================
- Hits 10513 10390 -123
- Misses 4535 4612 +77 ☔ View full report in Codecov by Sentry. |
*beep* *bop* Hi, human. The Click here to see your results. |
Benchmark the change to check if threading overloads shadows the parallel execution to increase run_time. |
Without Parallelfrom 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)
%timeit aNumbaFuncWithoutParallel(100000)
%timeit aNumbaFuncWithoutParallel(200000)
%timeit aNumbaFuncWithoutParallel(400000)
|
With Parallelfrom 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)
%timeit aNumbaFuncWithParallel(100000)
%timeit aNumbaFuncWithParallel(200000)
%timeit aNumbaFuncWithParallel(400000)
|
Since the runtime is nearly the same even with parallel execution, I am closing this PR. |
📝 Description
Type: 🎢
infrastructure
Run the loop in montecarlo_main_loop related to
finalize_array
in parallel.