comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: How many hardware threads?
Date: Mon, 12 Jul 2010 04:04:12 -0700 (PDT)
Date: 2010-07-12T04:04:12-07:00	[thread overview]
Message-ID: <dd3f13b7-d064-43ae-bee3-a14e80f67493@w12g2000yqj.googlegroups.com> (raw)
In-Reply-To: 4c3a65d7$0$2405$4d3efbfe@news.sover.net

I can see the value in having your program discover the number of
hardware threads and starting one task on each. This value, however,
is only for quick and dirty solutions. A proper, more long-term and
Ada-like solution, takes into account a lot of factors:

* if a single processor core provides several threads, these threads
share execution units in the core, so assigning compute-intensive
tasks to such threads is counter-productive; in contrast, assigning
tasks that spend a lot of time waiting for external events to occur is
a good idea. So, for your problem, you probably want at most one task
per core, not one task per thread.

* if hardware threads or cores share a common data cache, using too
many tasks may result in cache contention and slow-downs.

* each task will need virtual memory; possibly lots of it; and backed
up by physical memory or you'll cause thrashing. So the number of
tasks you can run is constrained not only by the amount of hardware
threads and cores but also by the amount of physical memory you can
allocate to your program.

* finally, the system administrator must have the last word on how
many tasks your program should use; they might choose to spare one
processor core for the OS or interactive use while your program runs
in the background; or they can run several programs concurrently and
only allocate a fraction of the processors available to your program.

So, having your program discover the number of threads (more usefully,
cores) in the system should only provide a hint as to how many tasks
you can start and you should also provide at least a command-line
option for use by the administrator.

HTH

--
Ludovic Brenta.



  parent reply	other threads:[~2010-07-12 11:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-12  0:47 How many hardware threads? Peter C. Chapin
2010-07-12  2:31 ` Jeffrey R. Carter
2010-07-12 17:04   ` Pascal Obry
2010-08-16 19:36     ` Yannick Duchêne (Hibou57)
2010-08-17  3:45       ` Randy Brukardt
2010-08-17  9:27       ` Pascal Obry
2010-07-12  2:38 ` tmoran
2010-07-12  7:40 ` Dmitry A. Kazakov
2010-07-12 17:14   ` Warren
2010-07-13  0:01   ` Gene
2010-07-13  1:09     ` Shark8
2010-07-12 10:08 ` anon
2010-07-12 11:04 ` Ludovic Brenta [this message]
2010-07-12 11:47 ` Egil Høvik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox