Skip to content

Printing from qmap #30

@mikkoku

Description

@mikkoku

I tried using qmap for 70 work tasks with runtime between 1-100 min. Printing progress once after each task caused really bad performance. I believe print in all but thread 1 caused the thread to wait until thread 1 finished its current task.

Below is an MWE that I would expect to finish in 3 seconds if using more than 1 threads, but for me using 4 threads it takes 15 seconds

using ThreadPools

function do_work(t)
  # work for t seconds
  t0 = time_ns()
  while (time_ns() - t0) * 1e-9 < t
    nothing
  end
end

function test(n)
  qmap(1:n) do i
    if Threads.threadid() == 1
      do_work(3)
    else
      println(i)
    end
  end
  nothing
end

@time test(10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions