• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing Software for Multicore System

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i want to utilise the multicore CPU as much as possible, is it simply by making my program spawning as much threads as possible? Assuming I can break down my program into parallell running units and it handles thread-safety issue manually.

If yes, then how many threads are optimal? Since I cannot foresee the number of cores the target systems will have.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many threads are optimal? That depends a lot on the program - what it does, and how many processors are available. There is no way to really predict it. The best thing you can do is make your program with a configurable number of Threads (a Thread Pool comes to mind - see ExecutorService for more). Then test the number of Threads that get you the correct performance.

You can also get a bit more detailed, depending on the work that you are doing. You may need to balance threads that 'get' data (producers) and threads that use data (consumers) - or threads that use I/O like disks, or databases, with those that don't. So there is no magic number, you have to code and test to see.
 
reply
    Bookmark Topic Watch Topic
  • New Topic