> On Apr 9, 2015, at 2:23 PM, Clark Smith Cox III <clark....@apple.com> > wrote: > >> On Apr 9, 2015, at 12:07, Carl Hoefs <newsli...@autonomy.caltech.edu> >> wrote: >>> >>> I have a highly CPU-bound project that parallelizes well. A small case >>> has >>> about 5000 tasks that can execute concurrently (max is ~100,000). I >>> would >>> like to use GCD queues to take advantage of the 24 cores I have on my >>> MacPro. Does GCD automatically limit the number of tasks that become >>> current on its queues to the number of cores (hw.logicalcpu)? >> >> Yes. > > Well, it's not as simple as limiting to the number of cores. It will > continue to spawn worker threads so long as there is spare overall system > capacity (up to some internal limit, but that's not the number of cores). > > If there are other processes/threads doing work on your system, your > process will use fewer threads than cores. > > If some of your tasks are blocked (due to I/O or locks or even sleeps), > then you may have more tasks in flight than there are cores, because the > blocked tasks don't consume CPU capacity. This can actually be a problem > if you have tasks which are mixed I/O and computation, because GCD will > over-subscribe the CPU. When the tasks unblock, there are more tasks > wanting CPU than there are cores. > > As much as possible, use dispatch I/O or dispatch sources for I/O. Keep > tasks segregated to doing either I/O or computation, not a mix. If you > can't use dispatch I/O or sources, then try to self-limit the number of > I/O tasks in flight at once (for example by submitting them to a serial > queue or low-concurrency-limit NSOperationQueue per device). Once you do > that, you should be safe to submit large numbers of CPU tasks and let GCD > manage them.
Interesting point. That could present a problem, as I do some I/O within the block. I'll have to try it out and see how it performs. Or perhaps there is there a way to tell a GCD concurrent queue to limit itself to N tasks? On another note, I don't know why this is having trouble: dispatch_apply(4950, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(size_t idx) { <--- error }); Incompatible block pointer types passing 'int (^)(size_t)' to parameter of type 'void (^)(size_t)' -Carl _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com