From c83e63cf008fcb97951def1f74956fbef3de0fa4 Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus Date: Fri, 4 Dec 2015 16:56:47 +0100 Subject: [PATCH] Add option OMP_PARALLEL_FORMAT_BARE to enable bare OMP FOR blocks in OpenMP It's not a good idea to generate #pragma omp parallel for if the code will sit inside a block of user code already annotated with #pragma omp parallel. Setting this flag will drop the 'parallel' in pretty-printing clast_for Signed-off-by: Utz-Uwe Haus --- include/cloog/clast.h | 5 +++++ source/pprint.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/cloog/clast.h b/include/cloog/clast.h index 3348aa8..3d13bb7 100644 --- a/include/cloog/clast.h +++ b/include/cloog/clast.h @@ -35,6 +35,11 @@ struct clast_term { #define CLAST_PARALLEL_OMP 1 #define CLAST_PARALLEL_MPI 2 #define CLAST_PARALLEL_VEC 4 + /* generate only the minimal annotation of OMP FOR, + not a complete OMP PARALLEL FOR. Useful if output is nested in another + OMP PARALLEL block + */ +#define CLAST_PARALLEL_FORMAT_BARE 8 enum clast_red_type { clast_red_sum, clast_red_min, clast_red_max }; struct clast_reduction { diff --git a/source/pprint.c b/source/pprint.c index d2faeed..7380f16 100644 --- a/source/pprint.c +++ b/source/pprint.c @@ -459,7 +459,8 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, fprintf(dst, ";\n"); } if(options->use_c99) - fprintf(dst, "_Pragma(\"omp parallel for%s%s%s%s%s%s\")\n", + fprintf(dst, "_Pragma(\"omp %s for%s%s%s%s%s%s\")\n", + (f->parallel&CLAST_PARALLEL_FORMAT_BARE)? "":"parallel", (f->private_vars)? " private(":"", (f->private_vars)? f->private_vars: "", (f->private_vars)? ")":"", @@ -467,7 +468,8 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, (f->reduction_vars)? f->reduction_vars: "", (f->reduction_vars)? ")": ""); else - fprintf(dst, "#pragma omp parallel for%s%s%s%s%s%s\n", + fprintf(dst, "#pragma omp %s for%s%s%s%s%s%s\n", + (f->parallel&CLAST_PARALLEL_FORMAT_BARE)? "":"parallel", (f->private_vars)? " private(":"", (f->private_vars)? f->private_vars: "", (f->private_vars)? ")":"", @@ -515,7 +517,8 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, fprintf(dst, "polyrt_loop_dist(_lb_dist, _ub_dist, nprocs, my_rank, &lbp, &ubp);\n"); if (f->parallel & CLAST_PARALLEL_OMP) { if(options->use_c99) - fprintf(dst, "_Pragma(\"omp parallel for%s%s%s%s%s%s\")\n", + fprintf(dst, "_Pragma(\"omp %s for%s%s%s%s%s%s\")\n", + (f->parallel&CLAST_PARALLEL_FORMAT_BARE)? "":"parallel", (f->private_vars)? " private(":"", (f->private_vars)? f->private_vars: "", (f->private_vars)? ")":"", @@ -523,14 +526,15 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, (f->reduction_vars)? f->reduction_vars: "", (f->reduction_vars)? ")": ""); else - fprintf(dst, "#pragma omp parallel for%s%s%s%s%s%s\n", + fprintf(dst, "#pragma omp %s for%s%s%s%s%s%s\n", + (f->parallel&CLAST_PARALLEL_FORMAT_BARE)? "":"parallel", (f->private_vars)? " private(":"", (f->private_vars)? f->private_vars: "", (f->private_vars)? ")":"", (f->reduction_vars)? " reduction(": "", (f->reduction_vars)? f->reduction_vars: "", (f->reduction_vars)? ")": ""); - } + } fprintf(dst, "%*s", indent, ""); } -- 2.11.4.GIT