?
Solved

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

Posted on 2004-08-31
7
Medium Priority
?
220 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 750 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: 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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

752 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