Hi. I'm writing code to carry out a big matrix multiplication and I'm splitting up the job to the 4 CPUs I have available. I'm finding that I'm only using about 70 or 80 percent of each CPU. Because this job takes a long time, I want to maximize this number. Other than closing out of the other processes on my computer, is there any other way of maximizing CPU usage?
Just in case, I'll attach some of the code. The important part is the matrix vector multiplication being split up by pthread. Thanks so much for your time!
#include<pthread.h>
int NUM_THREADS = 4;
double *tzin;
struct Position
{
int start;
int end;
double *out;
};
Position* pos;
pthread_t *threads;
DIAG = new double[NBASIS];
init_diagonal(ccco, DIAG);
pos= new Position[NUM_THREADS];
threads = new pthread_t[NUM_THREADS];
int k=0;
int st;
st = 0;
int Length = NBASIS / NUM_THREADS;
do{
pos[k].start = st;
pos[k].end = st + Length;
st = pos[k].end;
pos[k].out = new double[NBASIS];
k++;
}while(k<NUM_THREADS);
pos[NUM_THREADS-1].end = NBASIS;
tzin = new double[NBASIS];
Threads will use all available CPU time given to them unless you tell them otherwise (typically with a Sleep() command or something similar). The only other thing that would slow them down is some kind of blocking function call (which I don't see here)
The only thing you could try is to give your threads a higher priority. That'll make it more likely that your threads get CPU time than other processes running on the machine.