Solved

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

Posted on 2004-08-31
7
200 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Interoperability issue between VC++ (ocx) & VB.NET applications 7 100
C++ get user from AD  (VS6) 7 82
Gaming Software 1 19
I could not set window to top 4 20
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

840 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