Solved

How to make program use 2 processors in Visual C++

Posted on 2004-08-31
7
207 Views
Last Modified: 2010-04-01
How can I make my program use two processors? I can't make the code more lighter, so I need more processor speed. Most of the programs however can't use another processor and there is no any help of another processor if program can't use it.

So, I need to know what kind of code I need to make processor nro:2 calculate too.
I'm working with MS Visual C++ 6.
0
Comment
Question by:Tonde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 11941019
First you need a OS that can handle multiple CPU's.  Windows XP can do it, although IIRC you have to download a new HAL.

Then you have to split up the slow parts of your program into at least two threads.  The rest is mostly automatic, the OS will assign the CPU's among the threads.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11941263
Read this interesting article:
http://www.codeproject.com/cpp/rtl_scaling.asp
0
 
LVL 13

Accepted Solution

by:
SteH earned 250 total points
ID: 11941290
As grg99 stated you need to have at least two threads for your application. The OS will assign CPU cycles to each thread waiting for execution. Having 2 CPUs two threads can be executed simulatious. Main question/difficulty is how to split the code that you really can profit from using both CPUs. Try to find seperatable jobs in your code and assign a thread to each of them. Synchronizing two CPUs is even more problematic than two threads executed on the same processor. So care needs to be taken that they are not waiting for each other every so often.

One simplistic approach is to have the GUI run on one CPU and do calculations on the other. Depending on how good jobs can be seperated you can create more than those two threads.

The actual scheduling on the CPUs is done by the OS; you don't have to worry.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:AlexFM
ID: 11941480
See also:
SetThreadIdealProcessor
GetProcessAffinityMask
SetProcessAffinityMask
SetThreadAffinityMask
0
 
LVL 22

Expert Comment

by:grg99
ID: 11941640
You might also consider posting your code so we can see if we can speed it up.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12328008
Provided the author with theoretical and practical information.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question