Solved

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

Posted on 2004-08-31
7
193 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

23 Experts available now in Live!

Get 1:1 Help Now