'Using OMP parallel to add to count in for loop
I'm trying to speed up some processing with OMP parallel
but the cnt value is different every time, it's not adding across all for some reason. thanks.
RGBTRIPLE rgb;
COLORREF color;
int cnt = 0;
#pragma omp parallel for private(color, rgb) shared(cnt)
for(short ii=0;ii<cx;ii = ii + 1)
{
for(short j=0;j<cy;j = j + 1)
{
color = pDC->GetPixel(ii,j);
rgb.rgbtRed = GetRValue(color);
rgb.rgbtGreen = GetGValue(color);
rgb.rgbtBlue = GetBValue(color);
if(rgb.rgbtRed>0 && rgb.rgbtRed<255)
{
#pragma omp critical
cnt++;
//TRACE("color: %d,%d,%d\n",rgb.rgbtRed,rgb.rgbtGreen,rgb.rgbtBlue);
}
}
}
#pragma omp single
{}
CString msg; msg.Format("%d done",cnt);
AfxMessageBox(msg);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
