- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, Colleagues,
What does a Release-2015-compiler-produced executable do if it wants 4 cores [ CALL OMP_SET_NUM_THREADS(4) ] and it is run on a machine with an old Intel chip there are only two cores? We're trying to predict behavior on user machines that date back a while.
David
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you explicitly set the number of threads, that's what you get. Note that threads are an OS abstraction and have no direct relationship to cores. If you don't specify the number of threads, OpenMP will by default give you as many threads as there are execution streams on the processor (sockets * cores * threads/core). People were doing multithread programming on single-core processors for decades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. Yes, I understand the abstraction aspect, but what is the behavior? Is an attempt made to execute all 4 (in this case) threads more-or-less simultaneously? That is, being switched in-and-out of available execution streams. (Which sounds very inefficient). Or are individual threads allowed to run to completion in one of the execution streams?
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The OS manages this - and in general it will cycle among the threads, giving each one some time before swapping in another. Note that it's already doing this to some degree if there are ANY other processes or threads on the system, which there always will be. As for inefficient, it depends on the application, but certainly no individual thread will get 100% of a core's resources.
Also keep in mind that with Hyperthreading, such as almost all modern Intel CPUs have, typically two threads run per core, sharing some hardware resources.
What you describe is called "oversubscribing", and it is usually, but not always, a bad thing. Some applications do ok with some oversubscription.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. It's clear now. It sounds best if we avoid (possible) oversubscribing -- we'll add code that limits the number of threads we'll use to the number of physical cores we find on the host system.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or you could simply not specify the number of threads and let the runtime figure it out on its own. OMP_GET_NUM_PROCS will get you the number, or if you want more details, see the ProcessorInfo sample in Win32.zip.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page