OpenMP cleanup part 1.

removes dependency on thread number id.
This commit is contained in:
janrinze 2010-10-23 19:46:41 +02:00
parent 8a7df207ae
commit ab148c8c9a
7 changed files with 66 additions and 51 deletions

View File

@ -334,9 +334,11 @@ template<class T, class A> void bilateral25 (T** src, T** dst, T** buffer, int W
// main bilateral filter // main bilateral filter
template<class T, class A> void bilateral (T** src, T** dst, T** buffer, int W, int H, double sigma, double sens, bool multiThread) { template<class T, class A> void bilateral (T** src, T** dst, T** buffer, int W, int H, double sigma, double sens, bool multiThread) {
//parallel if (multiThread)
if (sigma<0.45) if (sigma<0.45)
#pragma omp parallel for if (multiThread) #ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) { for (int i=0; i<H; i++) {
memcpy (buffer[i], src[i], W*sizeof(T)); memcpy (buffer[i], src[i], W*sizeof(T));
memcpy (dst[i], buffer[i], W*sizeof(T)); memcpy (dst[i], buffer[i], W*sizeof(T));

View File

@ -31,13 +31,12 @@
template<class T> void gaussHorizontal3 (T** src, T** dst, T* buffer, int W, int H, const float c0, const float c1, bool multiThread) { template<class T> void gaussHorizontal3 (T** src, T** dst, T* buffer, int W, int H, const float c0, const float c1, bool multiThread) {
#pragma omp parallel for if (multiThread)
for (int i=0; i<H; i++) {
#ifdef _OPENMP #ifdef _OPENMP
T* temp = buffer + omp_get_thread_num() * W; #pragma omp for
#else
T* temp = buffer;
#endif #endif
for (int i=0; i<H; i++) {
T* temp = buffer;
for (int j=1; j<W-1; j++) for (int j=1; j<W-1; j++)
temp[j] = (T)(c1 * (src[i][j-1] + src[i][j+1]) + c0 * src[i][j]); temp[j] = (T)(c1 * (src[i][j-1] + src[i][j+1]) + c0 * src[i][j]);
dst[i][0] = src[i][0]; dst[i][0] = src[i][0];
@ -48,13 +47,12 @@ template<class T> void gaussHorizontal3 (T** src, T** dst, T* buffer, int W, int
template<class T> void gaussVertical3 (T** src, T** dst, T* buffer, int W, int H, const float c0, const float c1, bool multiThread) { template<class T> void gaussVertical3 (T** src, T** dst, T* buffer, int W, int H, const float c0, const float c1, bool multiThread) {
#pragma omp parallel for if (multiThread) //#pragma omp parallel for if (multiThread)
for (int i=0; i<W; i++) {
#ifdef _OPENMP #ifdef _OPENMP
T* temp = buffer + omp_get_thread_num() * H; #pragma omp for
#else
T* temp = buffer;
#endif #endif
for (int i=0; i<W; i++) {
T* temp = buffer;
for (int j = 1; j<H-1; j++) for (int j = 1; j<H-1; j++)
temp[j] = (T)(c1 * (src[j-1][i] + src[j+1][i]) + c0 * src[j][i]); temp[j] = (T)(c1 * (src[j-1][i] + src[j+1][i]) + c0 * src[j][i]);
dst[0][i] = src[0][i]; dst[0][i] = src[0][i];
@ -114,14 +112,10 @@ template<class T> void gaussHorizontal (T** src, T** dst, AlignedBuffer<double>*
for (int i=0; i<3; i++) for (int i=0; i<3; i++)
for (int j=0; j<3; j++) for (int j=0; j<3; j++)
M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3); M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3);
// if (multiThread)
#pragma omp parallel for if (multiThread) #pragma omp for
for (int i=0; i<H; i++) { for (int i=0; i<H; i++) {
#ifdef _OPENMP
double* temp2 = buffer->data + omp_get_thread_num() * W;
#else
double* temp2 = buffer->data; double* temp2 = buffer->data;
#endif
temp2[0] = B * src[i][0] + b1*src[i][0] + b2*src[i][0] + b3*src[i][0]; temp2[0] = B * src[i][0] + b1*src[i][0] + b2*src[i][0] + b3*src[i][0];
temp2[1] = B * src[i][1] + b1*temp2[0] + b2*src[i][0] + b3*src[i][0]; temp2[1] = B * src[i][1] + b1*temp2[0] + b2*src[i][0] + b3*src[i][0];
temp2[2] = B * src[i][2] + b1*temp2[1] + b2*temp2[0] + b3*src[i][0]; temp2[2] = B * src[i][2] + b1*temp2[1] + b2*temp2[0] + b3*src[i][0];
@ -192,14 +186,11 @@ template<class T> void gaussVertical (T** src, T** dst, AlignedBuffer<double>* b
for (int i=0; i<3; i++) for (int i=0; i<3; i++)
for (int j=0; j<3; j++) for (int j=0; j<3; j++)
M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3); M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3);
#pragma omp parallel for if (multiThread)
for (int i=0; i<W; i++) {
#ifdef _OPENMP #ifdef _OPENMP
double* temp2 = buffer->data + omp_get_thread_num() * H; #pragma omp for
#else
double* temp2 = buffer->data;
#endif #endif
for (int i=0; i<W; i++) {
double* temp2 = buffer->data;
temp2[0] = B * src[0][i] + b1*src[0][i] + b2*src[0][i] + b3*src[0][i]; temp2[0] = B * src[0][i] + b1*src[0][i] + b2*src[0][i] + b3*src[0][i];
temp2[1] = B * src[1][i] + b1*temp2[0] + b2*src[0][i] + b3*src[0][i]; temp2[1] = B * src[1][i] + b1*temp2[0] + b2*src[0][i] + b3*src[0][i];
temp2[2] = B * src[2][i] + b1*temp2[1] + b2*temp2[0] + b3*src[0][i]; temp2[2] = B * src[2][i] + b1*temp2[1] + b2*temp2[0] + b3*src[0][i];

View File

@ -164,7 +164,7 @@ std::vector<std::string> ICCStore::parseDir (Glib::ustring pdir) {
// ignore directories // ignore directories
if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) { if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) {
int lastdot = sname.find_last_of ('.'); int lastdot = sname.find_last_of ('.');
if (lastdot!=Glib::ustring::npos && lastdot<=sname.size()-4 && (!sname.casefold().compare (lastdot, 4, ".icm") || !sname.casefold().compare (lastdot, 4, ".icc"))) { if (lastdot!=Glib::ustring::npos && lastdot<=(int)sname.size()-4 && (!sname.casefold().compare (lastdot, 4, ".icm") || !sname.casefold().compare (lastdot, 4, ".icc"))) {
// printf ("processing file %s...\n", fname.c_str()); // printf ("processing file %s...\n", fname.c_str());
Glib::ustring name = sname.substr(0,lastdot); Glib::ustring name = sname.substr(0,lastdot);
ProfileContent pc (fname); ProfileContent pc (fname);

View File

@ -95,7 +95,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) {
extractInfo (); extractInfo ();
} }
} }
else if (dotpos<fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".jpg")) { else if (dotpos<(int)fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".jpg")) {
FILE* f = g_fopen (fname.c_str (), "rb"); FILE* f = g_fopen (fname.c_str (), "rb");
if (f) { if (f) {
root = rtexif::ExifManager::parseJPEG (f); root = rtexif::ExifManager::parseJPEG (f);
@ -106,7 +106,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) {
fclose (ff); fclose (ff);
} }
} }
else if ((dotpos<fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".tif")) || (dotpos<fname.size()-4 && !fname.casefold().compare (dotpos, 5, ".tiff"))) { else if ((dotpos<(int)fname.size()-3 && !fname.casefold().compare (dotpos, 4, ".tif")) || (dotpos<fname.size()-4 && !fname.casefold().compare (dotpos, 5, ".tiff"))) {
FILE* f = g_fopen (fname.c_str (), "rb"); FILE* f = g_fopen (fname.c_str (), "rb");
if (f) { if (f) {
root = rtexif::ExifManager::parseTIFF (f); root = rtexif::ExifManager::parseTIFF (f);

View File

@ -475,6 +475,9 @@ void ImProcFunctions::colorCurve (LabImage* lold, LabImage* lnew) {
void ImProcFunctions::lumadenoise (LabImage* lab, int** b2) { void ImProcFunctions::lumadenoise (LabImage* lab, int** b2) {
if (params->lumaDenoise.enabled && lab->W>=8 && lab->H>=8) if (params->lumaDenoise.enabled && lab->W>=8 && lab->H>=8)
#ifdef _OPENMP
#pragma omp parallel
#endif
bilateral<unsigned short, unsigned int> (lab->L, lab->L, (unsigned short**)b2, lab->W, lab->H, params->lumaDenoise.radius / scale, params->lumaDenoise.edgetolerance, multiThread); bilateral<unsigned short, unsigned int> (lab->L, lab->L, (unsigned short**)b2, lab->W, lab->H, params->lumaDenoise.radius / scale, params->lumaDenoise.edgetolerance, multiThread);
} }
@ -482,10 +485,10 @@ void ImProcFunctions::colordenoise (LabImage* lab, int** b2) {
if (params->colorDenoise.enabled && lab->W>=8 && lab->H>=8) { if (params->colorDenoise.enabled && lab->W>=8 && lab->H>=8) {
#ifdef _OPENMP #ifdef _OPENMP
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(lab->W,lab->H)*omp_get_max_threads()); #pragma omp parallel
#else
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(lab->W,lab->H));
#endif #endif
{
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(lab->W,lab->H));
gaussHorizontal<short> (lab->a, lab->a, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread); gaussHorizontal<short> (lab->a, lab->a, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread);
gaussHorizontal<short> (lab->b, lab->b, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread); gaussHorizontal<short> (lab->b, lab->b, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread);
gaussVertical<short> (lab->a, lab->a, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread); gaussVertical<short> (lab->a, lab->a, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread);
@ -493,6 +496,7 @@ void ImProcFunctions::colordenoise (LabImage* lab, int** b2) {
delete buffer; delete buffer;
} }
}
} }
void ImProcFunctions::getAutoExp (unsigned int* histogram, int histcompr, double expcomp, double clip, double& br, int& bl) { void ImProcFunctions::getAutoExp (unsigned int* histogram, int histcompr, double expcomp, double clip, double& br, int& bl) {

View File

@ -37,7 +37,9 @@ namespace rtengine {
void ImProcFunctions::dcdamping (float** aI, unsigned short** aO, float damping, int W, int H) { void ImProcFunctions::dcdamping (float** aI, unsigned short** aO, float damping, int W, int H) {
#pragma omp parallel for if (multiThread) #ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) { for (int j=0; j<W; j++) {
float I = aI[i][j]; float I = aI[i][j];
@ -69,10 +71,10 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, unsigned short** b2) {
float** tmp = (float**)b2; float** tmp = (float**)b2;
#ifdef _OPENMP #ifdef _OPENMP
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H)*omp_get_max_threads()); #pragma omp parallel
#else
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
#endif #endif
{
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
float damping = params->sharpening.deconvdamping / 5.0; float damping = params->sharpening.deconvdamping / 5.0;
bool needdamp = params->sharpening.deconvdamping > 0; bool needdamp = params->sharpening.deconvdamping > 0;
for (int k=0; k<params->sharpening.deconviter; k++) { for (int k=0; k<params->sharpening.deconviter; k++) {
@ -82,7 +84,9 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, unsigned short** b2) {
gaussVertical<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread); gaussVertical<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread);
if (!needdamp) { if (!needdamp) {
#pragma omp parallel for if (multiThread) #ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) for (int j=0; j<W; j++)
if (tmp[i][j]>0) if (tmp[i][j]>0)
@ -94,17 +98,25 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, unsigned short** b2) {
gaussHorizontal<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread); gaussHorizontal<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread);
gaussVertical<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread); gaussVertical<float> (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread);
#pragma omp parallel for if (multiThread) #ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) for (int j=0; j<W; j++)
tmpI[i][j] = tmpI[i][j] * tmp[i][j]; tmpI[i][j] = tmpI[i][j] * tmp[i][j];
} } // end for
delete buffer;
} // end parallel
#pragma omp parallel for if (multiThread) #ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) for (int j=0; j<W; j++)
lab->L[i][j] = lab->L[i][j]*(100-params->sharpening.deconvamount) / 100 + (int)CLIP(tmpI[i][j])*params->sharpening.deconvamount / 100; lab->L[i][j] = lab->L[i][j]*(100-params->sharpening.deconvamount) / 100 + (int)CLIP(tmpI[i][j])*params->sharpening.deconvamount / 100;
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
delete [] tmpI[i]; delete [] tmpI[i];
delete [] tmpI; delete [] tmpI;
@ -121,12 +133,13 @@ void ImProcFunctions::sharpening (LabImage* lab, unsigned short** b2) {
return; return;
int W = lab->W, H = lab->H; int W = lab->W, H = lab->H;
unsigned short** b3;
#ifdef _OPENMP #ifdef _OPENMP
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H)*omp_get_max_threads()); #pragma omp parallel
#else
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
#endif #endif
{
unsigned short** b3;
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
if (params->sharpening.edgesonly==false) { if (params->sharpening.edgesonly==false) {
gaussHorizontal<unsigned short> (lab->L, b2, buffer, W, H, params->sharpening.radius / scale, multiThread); gaussHorizontal<unsigned short> (lab->L, b2, buffer, W, H, params->sharpening.radius / scale, multiThread);
@ -148,7 +161,7 @@ void ImProcFunctions::sharpening (LabImage* lab, unsigned short** b2) {
base = b3; base = b3;
if (params->sharpening.halocontrol==false) { if (params->sharpening.halocontrol==false) {
#pragma omp parallel for if (multiThread) #pragma omp for
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) { for (int j=0; j<W; j++) {
int diff = base[i][j] - b2[i][j]; int diff = base[i][j] - b2[i][j];
@ -166,6 +179,7 @@ void ImProcFunctions::sharpening (LabImage* lab, unsigned short** b2) {
delete [] b3[i]; delete [] b3[i];
delete [] b3; delete [] b3;
} }
}
} }
void ImProcFunctions::sharpenHaloCtrl (LabImage* lab, unsigned short** blurmap, unsigned short** base, int W, int H) { void ImProcFunctions::sharpenHaloCtrl (LabImage* lab, unsigned short** blurmap, unsigned short** base, int W, int H) {

View File

@ -51,20 +51,21 @@ void SHMap::update (Image16* img, unsigned short** buffer, double radius, double
int val = lumi[0]*img->r[i][j] + lumi[1]*img->g[i][j] + lumi[2]*img->b[i][j]; int val = lumi[0]*img->r[i][j] + lumi[1]*img->g[i][j] + lumi[2]*img->b[i][j];
map[i][j] = CLIP(val); map[i][j] = CLIP(val);
} }
if (!hq) {
#ifdef _OPENMP #ifdef _OPENMP
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H)*omp_get_max_threads()); #pragma omp parallel
#else
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
#endif #endif
{
if (!hq) {
AlignedBuffer<double>* buffer = new AlignedBuffer<double> (MAX(W,H));
gaussHorizontal<unsigned short> (map, map, buffer, W, H, radius, multiThread); gaussHorizontal<unsigned short> (map, map, buffer, W, H, radius, multiThread);
gaussVertical<unsigned short> (map, map, buffer, W, H, radius, multiThread); gaussVertical<unsigned short> (map, map, buffer, W, H, radius, multiThread);
delete buffer; delete buffer;
} }
else { else {
#ifdef _OPENMP #if 0
// the new OpenMP method does not need thread number specific code.
// #ifdef _OPENMP
#pragma omp parallel if (multiThread) #pragma omp parallel if (multiThread)
{ {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
@ -80,6 +81,9 @@ void SHMap::update (Image16* img, unsigned short** buffer, double radius, double
bilateral<unsigned short> (map, buffer, W, H, 8000, radius, 0, H); bilateral<unsigned short> (map, buffer, W, H, 8000, radius, 0, H);
#endif #endif
// anti-alias filtering the result // anti-alias filtering the result
#ifdef _OPENMP
#pragma omp for
#endif
for (int i=0; i<H; i++) for (int i=0; i<H; i++)
for (int j=0; j<W; j++) for (int j=0; j<W; j++)
if (i>0 && j>0 && i<H-1 && j<W-1) if (i>0 && j>0 && i<H-1 && j<W-1)
@ -87,7 +91,7 @@ void SHMap::update (Image16* img, unsigned short** buffer, double radius, double
else else
map[i][j] = buffer[i][j]; map[i][j] = buffer[i][j];
} }
} // end parallel enclosure
// update average, minimum, maximum // update average, minimum, maximum
double _avg = 0; double _avg = 0;
int n = 1; int n = 1;