Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/TV2DWopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ int DR2L1W_TV(size_t M, size_t N, double*unary, double*W1, double*W2, double*s,
@param ws array of Workspaces to use for the computation
*/
void DR_columnsPass(size_t M, size_t N, double* input, double* output, double* W, Workspace **ws) {
#ifdef _OPENMP
#pragma omp parallel shared(M,N,input,output,W,ws) default(none)
#endif
{
// Get thread number
int id = omp_get_thread_num();
Expand All @@ -159,8 +161,10 @@ void DR_columnsPass(size_t M, size_t N, double* input, double* output, double* W
wsi->warm = 0;

// Run 1-d solvers in parallel on each column of the input
#ifdef _OPENMP
#pragma omp for
for (int j=0; j < N; j++) {
#endif
for (size_t j=0; j < N; j++) {
resetWorkspace(wsi);
// Array for weights
double* wline = getDoubleWorkspace(wsi);
Expand Down Expand Up @@ -188,17 +192,21 @@ void DR_columnsPass(size_t M, size_t N, double* input, double* output, double* W
@param ws array of Workspaces to use for the computation
*/
void DR_rowsPass(size_t M, size_t N, double* input, double* output, double* ref, double* W, Workspace **ws) {
#ifdef _OPENMP
#pragma omp parallel shared(M,N,input,ref,output,W,ws) default(none)
#endif
{
int i,j;
size_t i, j;
// Get thread number
int id = omp_get_thread_num();
// Get corresponding workspace
Workspace *wsi = ws[id];
wsi->warm = 0;

// Run 1-d solvers in parallel on each row of the input
#ifdef _OPENMP
#pragma omp for
#endif
for (j=0; j < M; j++) {
resetWorkspace(wsi);
// Array for weights
Expand Down
32 changes: 30 additions & 2 deletions src/TV2Dopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
#endif

/* Initialization */
#ifdef _OPENMP
#pragma omp parallel for shared(x,y,p,q,n) private(i) default(none)
#endif
for(i=0;i<n;i++){
x[i] = y[i];
p[i] = 0;
Expand Down Expand Up @@ -160,7 +162,9 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
#endif

/* Copy actual solution */
#ifdef _OPENMP
#pragma omp parallel for shared(x,xLast,n) private(i) default(none)
#endif
for(i=0;i<n;i++)
xLast[i] = x[i];

Expand All @@ -170,15 +174,19 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
#endif
d = int(dims[0]-1);
/* Run 1-dimensional prox operator over each 1-dimensional slice along the specified dimension (parallelized) */
#ifdef _OPENMP
#pragma omp parallel shared(ws,nSlices,ns,d,incs,x,p,lambdas,z,norms) private(j,k,idx1,idx2) default(none)
#endif
{
/* Get thread number */
int id = omp_get_thread_num();
Workspace *wsi = ws[id];
wsi->warm = 0;
int top=nSlices[d];

#ifdef _OPENMP
#pragma omp for
#endif
for(j=0;j<top;j++){
/* Find slice starting point */
idx1 = (j / incs[d])*incs[d]*ns[d] + (j % incs[d]);
Expand All @@ -198,7 +206,9 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
}

/* Update p */
#ifdef _OPENMP
#pragma omp parallel for shared(p,x,z,n) private(i) default(none)
#endif
for(i=0;i<n;i++)
p[i] += x[i] - z[i];

Expand All @@ -207,15 +217,19 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
d = int(dims[1]-1);

/* Run 1-dimensional prox operator over each 1-dimensional slice along the specified dimension (parallelized) */
#ifdef _OPENMP
#pragma omp parallel shared(ws,nSlices,ns,d,incs,x,q,lambdas,z,norms) private(j,k,idx1,idx2) default(none)
#endif
{
/* Get thread number */
int id = omp_get_thread_num();
Workspace *wsi = ws[id];
wsi->warm = 0;
int top=nSlices[d];

#ifdef _OPENMP
#pragma omp for
#endif
for(j=0;j<top;j++){
/* Find slice starting point */
idx1 = (j / incs[d])*incs[d]*ns[d] + (j % incs[d]);
Expand All @@ -235,20 +249,26 @@ int PD2_TV(double *y,double *lambdas,double *norms,double *dims,double *x,double
}

/* Update q */
#ifdef _OPENMP
#pragma omp parallel for shared(q,z,x,n) private(i) default(none)
#endif
for(i=0;i<n;i++)
q[i] += z[i] - x[i];
}
else{
#ifdef _OPENMP
#pragma omp parallel for shared(z,x,n) private(i) default(none)
#endif
for(i=0;i<n;i++)
x[i] = z[i];
memcpy(x,z,nBytes);
}

/* Compute stopping criterion: mean change */
stop = 0;
#ifdef _OPENMP
#pragma omp parallel for shared(x,xLast,n) private(k) reduction(+:stop) default(none)
#endif
for(k=0;k<n;k++)
stop += fabs(x[k]-xLast[k]);
stop /= n;
Expand Down Expand Up @@ -429,7 +449,9 @@ int DR2_TV(size_t M, size_t N, double*unary, double W1, double W2,
@param ws array of Workspaces to use for the computation
*/
void DR_columnsPass(size_t M, size_t N, double* input, double* output, double W, double norm, Workspace **ws) {
#ifdef _OPENMP
#pragma omp parallel shared(M,N,input,output,W,norm,ws) default(none)
#endif
{
// Get thread number
int id = omp_get_thread_num();
Expand All @@ -438,8 +460,10 @@ void DR_columnsPass(size_t M, size_t N, double* input, double* output, double W,
wsi->warm = 0;

// Run 1-d solvers in parallel on each column of the input
#ifdef _OPENMP
#pragma omp for
for (int j=0; j < N; j++) {
#endif
for (size_t j=0; j < N; j++) {
resetWorkspace(wsi);
// Prepare inputs
memcpy(wsi->in, input+(M*j), sizeof(double)*M);
Expand Down Expand Up @@ -467,17 +491,21 @@ void DR_columnsPass(size_t M, size_t N, double* input, double* output, double W,
@param ws array of Workspaces to use for the computation
*/
void DR_rowsPass(size_t M, size_t N, double* input, double* output, double* ref, double W, double norm, Workspace **ws) {
#ifdef _OPENMP
#pragma omp parallel shared(M,N,input,ref,output,W,norm,ws) default(none)
#endif
{
int i,j;
size_t i, j;
// Get thread number
int id = omp_get_thread_num();
// Get corresponding workspace
Workspace *wsi = ws[id];
wsi->warm = 0;

// Run 1-d solvers in parallel on each row of the input
#ifdef _OPENMP
#pragma omp for
#endif
for (j=0; j < M; j++) {
resetWorkspace(wsi);
// Prepare inputs, considering displacement from reference signal
Expand Down
12 changes: 10 additions & 2 deletions src/TVL1opt_tautstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ inline Segment* newknot(Buffer* majorant, Buffer* minorant, Point* origin, Point
The new prox-TV segment is added to the prox array
*/
#define addproxsegment(prox, segment, j) \
for ( j = 0 ; j < segment->incx ; j++ ) \
for ( j = 0 ; j < (size_t) segment->incx ; j++ ) \
(prox)[j] = segment->slope;

/*
Expand Down Expand Up @@ -292,16 +292,20 @@ int classicTautString_TV1_offset(double *signal, int n, double lam, double *prox
Segment *saux;
size_t i, iaux;
double *pwriter = prox;
for ( i = 1 ; i < n-1 ; i++ ) {
for ( i = 1 ; i < (size_t)(n-1) ; i++ ) {
// Update majorant
segment.incx = 1;
segment.slope = segment.incy = signal[i];
#ifdef _MSC_VER
#pragma warning(suppress: 4244)
#endif
concavemajorantadd(majorant, dirsegment, saux, iaux);
// Update minorant
segment.incx = 1;
segment.slope = segment.incy = signal[i];
#ifdef _MSC_VER
#pragma warning(suppress: 4244)
#endif
convexminorantadd(minorant, dirsegment, saux, iaux);
// Update last explored point
lastexplored.x++;
Expand All @@ -319,12 +323,16 @@ int classicTautString_TV1_offset(double *signal, int n, double lam, double *prox
// Update majorant with last segment
segment.incx = 1;
segment.slope = segment.incy = signal[n-1] + lam;
#ifdef _MSC_VER
#pragma warning(suppress: 4244)
#endif
concavemajorantadd(majorant, dirsegment, saux, iaux);
// Update minorant with last segment
segment.incx = 1;
segment.slope = segment.incy = signal[n-1] - lam;
#ifdef _MSC_VER
#pragma warning(suppress: 4244)
#endif
convexminorantadd(minorant, dirsegment, saux, iaux);

// At this point, because the endpoint of the tube is the same
Expand Down
8 changes: 6 additions & 2 deletions src/TVL2opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- n: length of array y (and x).
*/
int more_TV2(double *y,double lambda,double *x,double *info,int n){
if(n < 2) { info[INFO_RC] = RC_ERROR; return 0; }
int nn=n-1,i;
double stop,tmp,lam,pNorm,qNorm,pNormSq,dist;
double *Dy,*alpha,*beta,*minus,*p,*aux;
Expand Down Expand Up @@ -194,6 +195,7 @@ int more_TV2(double *y,double lambda,double *x,double *info,int n){
- ws: workspace of allocated memory to use. If NULL, any needed memory is locally managed.
*/
int morePG_TV2(double *y,double lambda,double *x,double *info,int n,Workspace *ws){
if(n < 2) { if(info) info[INFO_RC] = RC_ERROR; return 0; }
int nn=n-1,i,iters;
double stop,tmp,lam,pNorm,qNorm,pNormSq,dist;
double *Dy=NULL,*alpha=NULL,*beta=NULL,*minus=NULL,*p,*aux;
Expand All @@ -219,7 +221,8 @@ int morePG_TV2(double *y,double lambda,double *x,double *info,int n,Workspace *w

#define NORM(x,n,i,tmp) \
tmp = 0; \
for(i=0;i<n;i++) tmp += x[i]*x[i]; tmp = sqrt(tmp);
for(i=0;i<n;i++) tmp += x[i]*x[i]; \
tmp = sqrt(tmp);

#define FREE \
if(!ws) { \
Expand Down Expand Up @@ -472,7 +475,8 @@ int PG_TV2(double *y,double lambda,double *x,double *info,int n){

#define NORM(x,n,i,tmp) \
tmp = 0; \
for(i=0;i<n;i++) tmp += x[i]*x[i]; tmp = sqrt(tmp);
for(i=0;i<n;i++) tmp += x[i]*x[i]; \
tmp = sqrt(tmp);

#define FREE \
if(p) free(p); \
Expand Down
Loading