Multi-core Cpus - Why doesn’t my application use all the processor cores?

Asked

Viewed 1,619 times

16

I have a doubt I can’t find a convincing answer.

There is an application developed in Delphi 7, and in an extremely complex routine (it takes about 2 hours) we notice that it is only used for the same the first core of the processor, in this case an Intel Core-i7 (8 core), and the other cores remain idle (at least the Windows feature monitor demonstrates).

In this regard I have several questions, the main ones being the following:

  • Why does this happen?
  • That’s a Delphi 7 problem, or Delphi problem?
  • This can be solved using Delphi 7?
  • Other technology such as . net and Java, are already prepared to use efficiently Multi-core Cpus?
  • In the case of other technologies such as . net and Java. Something needs to be done in the application or it will happen automatically and managed by the Framework?
  • 3

    In your application you have multiple threads or just one?

  • 1

    As @Math commented, have you tried running this time-consuming process in more than one thread? http://stackoverflow.com/questions/9630686/delphi-7-how-to-implement-multi-threading

  • 2

    To use all COLORS, your programming has to have been designed for this. Even in . Net should use specific libraries and techniques to take advantage of all cores

  • @Math, only a single theads, but it is a unique process that could not be divided into threads. But a same thead could not send instructions to all processor cores?

  • 5

    As far as I know you have to split into multi threads so that each one is rotated into a core, and you may still have to do something more than that. I’m no expert in threads, but surely if you put a single thread to run it won’t split into multiple cores, because there’s no way the processor can parallelize your code if your code is all, say, sequential.

  • 2

    You need to modify your application using system threads so that your application uses more than one core. This is not a limitation or problem of Delphi.

  • Related: http://answall.com/q/1946/101

Show 2 more comments

2 answers

10

Serial Algorithm vs Parallel Algorithm

To solve your problem, you will need to change your algorithm.

Today what you have is an application that runs all your logic in a single thread that will be run by a single processor. Called serial algorithm or sequentially.

Which means that all your logic is executed sequentially. You would have to rewrite part of your application by dividing it into subtasks - subtasks, and delivering them to threads - this would be the parallel algorithm. An addendum is not possible to parallelize your entire algorithm, you can only divide to a certain point.

The number of threads should be the number of processors available and for each thread you submit your tasks. Each thread is run by a processor. Do not confuse parallel computing with concurrent programming.

Other technologies such as . net and Java are already ready to use efficiently Multi-core Cpus?

Java has always provided Apis and frameworks for concurrent programming and parallel computing. From Java 1.5 a framework called Executor Framework has been added. It offers several utility classes, interfaces, methods for manufacturing Thread Pools and methods for submitting tasks.

Already in Java 1.7 we won the Fork/Join framework. Which allows you to program an algorithm by defining Thresholds processing, which are limits, when this limit is reached you want the task in two - Fork. Once it is executed and the other tasks are completed, you make the Jois of them for the final result. Interestingly, this framework implements an algorithm called work-stealing. It’s a technique where when a thread finishes executing its task it steals the task from another thread that hasn’t finished executing it.

Last but not least

If you take over the project of migrating a new execution model, I recommend that you study the amdahl’s law that predicts the maximum time it is possible to optimize a program using multiple processors.

Sources: Serial algorithm: https://en.wikipedia.org/wiki/Sequential_algorithm

Parallel algorithm: https://en.wikipedia.org/wiki/Parallel_algorithm

Parallel computing: https://en.wikipedia.org/? title=Parallel_computing

  • 1

    It is worth mentioning that although Java allows parallel and concurrent computing, nothing is magical and you need to learn how to use multiple threads etc... The same is possible in Delphi.

  • has also an abstraction over thread, which is the models of Actors - Actors Model, greatly simplifies. Akka Framework can help. https://en.wikipedia.org/wiki/Actor_model

1

Explaining a way WELL simplified differences between execution models:

Multitasking:

  • Multiple processes in one core.
  • Run concurrently.

Multiprocessing

Multiprocessing:

  • Multiple processes in multiple cores.
  • Run in parallel

inserir a descrição da imagem aqui

Multithreading:

  • A process using multiple threads.
  • Computation is divided between cores
  • PS: (Run in parallel or not, depending on your code and hardware)

Multithreading

Browser other questions tagged

You are not signed in. Login or sign up in order to post.