Using Multi-Cores.
Visual C++ Express by default generates code that works on one thread and on one core of your processor.
I came across an easy way of multi-coring your work out. OMP
Say for example we process through a list of Objects and do a little work on each one, normally we would work on the first, complete that and then start work on the second.... and so on.
What if we could get core one of the machine to work on the first few and core two to work on the next few (at the SAME time).
This basic example has a few requirements. The data processed works in it own little discrete space (i.e. we arnt sorting the data or changing variables that might be accessed by other lines of the data). All that is possible, but you will need to explore omp for yourself....
To Use:
Inside the Properties Page -> Configuration Properties -> C/C++ -> Language screen - set OpenMP Support to Yes (/openmp)
Say we have the following code....
void MoveObjects(void)
{
// Move the objects. (if they can)
for (long i = 0; i<MAX_OBJECTS; i++)
{
if (Objects[i]!= NULL)
{
Objects[i]->DecreaseDelay();
if (Objects[i]->CanWork())
{
Objects[i]->MoveToTarget(i);
}
}
} // end of [For i = 0 to max_objects]
}
To multi-core it...
#include "omp.h"
void MoveObjects(void)
{
// Move the objects. (if they can)
#pragma omp parallel for
for (long i = 0; i<MAX_OBJECTS; i++)
{
if (Objects[i]!= NULL)
{
Objects[i]->DecreaseDelay();
if (Objects[i]->CanWork())
{
Objects[i]->MoveToTarget(i);
}
}
} // end of [For i = 0 to max_objects]
}
How simple is that!
The compiler will do the rest. Nice thing is - doesnt matter if you are on a quad or duel core, it will use what is available.
More information is of course available, but I will leave that up to you to find.