From ab148c8c9af40fcdd08c670f67b7ad5598b553d0 Mon Sep 17 00:00:00 2001 From: janrinze Date: Sat, 23 Oct 2010 19:46:41 +0200 Subject: [PATCH] OpenMP cleanup part 1. removes dependency on thread number id. --- rtengine/bilateral2.h | 8 +++++--- rtengine/gauss.h | 35 +++++++++++++---------------------- rtengine/iccstore.cc | 2 +- rtengine/imagedata.cc | 4 ++-- rtengine/improcfun.cc | 10 +++++++--- rtengine/ipsharpen.cc | 40 +++++++++++++++++++++++++++------------- rtengine/shmap.cc | 18 +++++++++++------- 7 files changed, 66 insertions(+), 51 deletions(-) diff --git a/rtengine/bilateral2.h b/rtengine/bilateral2.h index 0a7cb7bb8..242595db4 100644 --- a/rtengine/bilateral2.h +++ b/rtengine/bilateral2.h @@ -334,9 +334,11 @@ template void bilateral25 (T** src, T** dst, T** buffer, int W // main bilateral filter template void bilateral (T** src, T** dst, T** buffer, int W, int H, double sigma, double sens, bool multiThread) { - - if (sigma<0.45) - #pragma omp parallel for if (multiThread) +//parallel if (multiThread) + if (sigma<0.45) +#ifdef _OPENMP +#pragma omp for +#endif for (int i=0; i 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 void gaussHorizontal3 (T** src, T** dst, T* buffer, int W, int template 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) - for (int i=0; i void gaussHorizontal (T** src, T** dst, AlignedBuffer* for (int i=0; i<3; i++) for (int j=0; j<3; j++) M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3); - - #pragma omp parallel for if (multiThread) + // if (multiThread) + #pragma omp for for (int i=0; idata + omp_get_thread_num() * W; -#else double* temp2 = buffer->data; -#endif 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[2] = B * src[i][2] + b1*temp2[1] + b2*temp2[0] + b3*src[i][0]; @@ -192,14 +186,11 @@ template void gaussVertical (T** src, T** dst, AlignedBuffer* b for (int i=0; i<3; i++) for (int j=0; j<3; j++) M[i][j] /= (1.0+b1-b2+b3)*(1.0+b2+(b1-b3)*b3); - - #pragma omp parallel for if (multiThread) - for (int i=0; idata + omp_get_thread_num() * H; -#else - double* temp2 = buffer->data; +#pragma omp for #endif + for (int i=0; idata; 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[2] = B * src[2][i] + b1*temp2[1] + b2*temp2[0] + b3*src[0][i]; diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 8e9ba21ef..748a3046d 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -164,7 +164,7 @@ std::vector ICCStore::parseDir (Glib::ustring pdir) { // ignore directories if (!Glib::file_test (fname, Glib::FILE_TEST_IS_DIR)) { 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()); Glib::ustring name = sname.substr(0,lastdot); ProfileContent pc (fname); diff --git a/rtengine/imagedata.cc b/rtengine/imagedata.cc index e2523a3c9..2146a4d79 100644 --- a/rtengine/imagedata.cc +++ b/rtengine/imagedata.cc @@ -95,7 +95,7 @@ ImageData::ImageData (Glib::ustring fname, RawMetaDataLocation* ri) { extractInfo (); } } - else if (dotposlumaDenoise.enabled && lab->W>=8 && lab->H>=8) +#ifdef _OPENMP +#pragma omp parallel +#endif bilateral (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) { #ifdef _OPENMP - AlignedBuffer* buffer = new AlignedBuffer (MAX(lab->W,lab->H)*omp_get_max_threads()); -#else - AlignedBuffer* buffer = new AlignedBuffer (MAX(lab->W,lab->H)); +#pragma omp parallel #endif + { + AlignedBuffer* buffer = new AlignedBuffer (MAX(lab->W,lab->H)); gaussHorizontal (lab->a, lab->a, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread); gaussHorizontal (lab->b, lab->b, buffer, lab->W, lab->H, params->colorDenoise.amount / 10.0 / scale, multiThread); gaussVertical (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; } + } } void ImProcFunctions::getAutoExp (unsigned int* histogram, int histcompr, double expcomp, double clip, double& br, int& bl) { diff --git a/rtengine/ipsharpen.cc b/rtengine/ipsharpen.cc index 98345d98f..7fb3bbc81 100644 --- a/rtengine/ipsharpen.cc +++ b/rtengine/ipsharpen.cc @@ -37,7 +37,9 @@ namespace rtengine { 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* buffer = new AlignedBuffer (MAX(W,H)*omp_get_max_threads()); -#else - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); +#pragma omp parallel #endif + { + AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); float damping = params->sharpening.deconvdamping / 5.0; bool needdamp = params->sharpening.deconvdamping > 0; for (int k=0; ksharpening.deconviter; k++) { @@ -82,7 +84,9 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, unsigned short** b2) { gaussVertical (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread); if (!needdamp) { - #pragma omp parallel for if (multiThread) +#ifdef _OPENMP +#pragma omp for +#endif for (int i=0; i0) @@ -94,17 +98,25 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, unsigned short** b2) { gaussHorizontal (tmp, tmp, buffer, W, H, params->sharpening.deconvradius / scale, multiThread); gaussVertical (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; iL[i][j] = lab->L[i][j]*(100-params->sharpening.deconvamount) / 100 + (int)CLIP(tmpI[i][j])*params->sharpening.deconvamount / 100; + + for (int i=0; iW, H = lab->H; - unsigned short** b3; #ifdef _OPENMP - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)*omp_get_max_threads()); -#else - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); +#pragma omp parallel #endif + { + unsigned short** b3; + + AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); if (params->sharpening.edgesonly==false) { gaussHorizontal (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; if (params->sharpening.halocontrol==false) { - #pragma omp parallel for if (multiThread) + #pragma omp for for (int i=0; ir[i][j] + lumi[1]*img->g[i][j] + lumi[2]*img->b[i][j]; map[i][j] = CLIP(val); } - - if (!hq) { #ifdef _OPENMP - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)*omp_get_max_threads()); -#else - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); +#pragma omp parallel #endif + { + if (!hq) { + AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); gaussHorizontal (map, map, buffer, W, H, radius, multiThread); gaussVertical (map, map, buffer, W, H, radius, multiThread); delete buffer; } else { -#ifdef _OPENMP +#if 0 +// the new OpenMP method does not need thread number specific code. +// #ifdef _OPENMP #pragma omp parallel if (multiThread) { int tid = omp_get_thread_num(); @@ -80,6 +81,9 @@ void SHMap::update (Image16* img, unsigned short** buffer, double radius, double bilateral (map, buffer, W, H, 8000, radius, 0, H); #endif // anti-alias filtering the result +#ifdef _OPENMP +#pragma omp for +#endif for (int i=0; i0 && j>0 && i