Assuming I have three integer vectors:
- mainVect of size 8 million element
- vect1 of size 1.5 million element
- vect2 of size 1.5 million element
I want to run the following code:
int i,j;
for ( i = 0; i < vect1.size(); i++)
{
for ( j = 0; j < mainVect.size(); j++)
{
if (vect1[i] == mainVect[j])
{
vect2[i]++;
}
}
}
It took a very long time without finishing yet...How I can speed up the run, I have multiprocessors. As a try, I've added the following sentence before the previous code (I read that it run in parallel)
#pragma omp parallel for private(i, j) shared( mainVect, vect1, vect2)
But still slow ...
If I divide the for loop into 4 sections; for example, how I can make these for loops run simultaneously such as
for ( i = 0; i < vect1.size()/4; i++)
{
}
for ( i = vect1.size()/4; i < vect1.size()/2; i++)
{
}
.... and so on
Or any other methods ...
P.S.: Windows google cloud machine, n1-standard-4 (4 vCPUs, 15 GB memory) .. CPU utilization only 27% when run the above code.