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

Bug: @timeit would created a infinitely nested TimerOutput within a @threads block #162

Closed
jingc769 opened this issue Apr 24, 2023 · 2 comments

Comments

@jingc769
Copy link

 using TimerOutputs, Base.Threads
 function parallel_task()
           to = TimerOutput()

           # define the loop to be run in parallel
           @threads for i in 1:10
               # measure the execution time of each loop iteration using @timeit
               @timeit to "within threads" begin
                   # perform some time-consuming task here
                   sleep(rand())
               end
           end

           # print the timing results
           to
       end


Would produce result like

 ─────────────────────────────────────────────────────────────────────────────────────
                                             Time                    Allocations
                                    ───────────────────────   ────────────────────────
          Tot / % measured:              1.64s /  16.4%           2.77MiB /   0.3%

 Section                    ncalls     time    %tot     avg     alloc    %tot      avg
 ─────────────────────────────────────────────────────────────────────────────────────
 within threads                  1    270ms  100.0%   270ms   9.86KiB  100.0%  9.86KiB
   within threads                1    335ms  124.1%   335ms    439KiB  4447.7%   439KiB
     within threads              2    1.58s  586.1%   791ms   1.53MiB  15867.6%   782KiB
       within threads            1    273ms  100.9%   273ms   13.0KiB  131.5%  13.0KiB
         within threads          4    2.31s  857.0%   579ms   2.77MiB  28808.8%   710KiB
           within threads        1    545ms  201.9%   545ms    862KiB  8740.7%   862KiB
 ─────────────────────────────────────────────────────────────────────────────────────

I guess the issue is because multi-threads messed up with "previous_timer" and "timer_stack".

@KristofferC
Copy link
Owner

Yeah, this package doesn't work well in a concurrent context right now.

@KristofferC
Copy link
Owner

I'll close this in favour of #72.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants