Skip to content
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

Closed

Conversation

Sumit112192
Copy link
Contributor

📝 Description

Type: 🎢 infrastructure

Run the loop in montecarlo_main_loop related to finalize_array in parallel.

@tardis-bot
Copy link
Contributor

*beep* *bop*
Hi human,
I ran ruff on the latest commit (1a47b9b).
Here are the outputs produced.
Results can also be downloaded as artifacts here.
Summarised output:

Complete output(might be large):

@Sumit112192
Copy link
Contributor Author

@andrewfullard Are there any disadvantages to running the parallel loop that I made?

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

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 ⚠️
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.
📢 Have feedback on the report? Share it here.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

The docs workflow has succeeded ✔️

Click here to see your results.

@Sumit112192
Copy link
Contributor Author

Benchmark the change to check if threading overloads shadows the parallel execution to increase run_time.

@Sumit112192
Copy link
Contributor Author

Without Parallel

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)

@Sumit112192
Copy link
Contributor Author

With Parallel

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)

@Sumit112192
Copy link
Contributor Author

Since the runtime is nearly the same even with parallel execution, I am closing this PR.

@Sumit112192 Sumit112192 closed this Aug 3, 2024
@Sumit112192 Sumit112192 deleted the ParallelFinalizeArrayLoop branch September 8, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants