Solved

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

Posted on 2004-08-31
7
194 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 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.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now