diff --git a/SparseGrids/tsgGridLocalPolynomial.cpp b/SparseGrids/tsgGridLocalPolynomial.cpp index 62f75afe6..e01e0d3f0 100644 --- a/SparseGrids/tsgGridLocalPolynomial.cpp +++ b/SparseGrids/tsgGridLocalPolynomial.cpp @@ -1391,6 +1391,7 @@ MultiIndexSet GridLocalPolynomial::getRefinementCanidates(double tolerance, Type int num_points = points.getNumIndexes(); + #ifdef _OPENMP #pragma omp parallel { Data2D lrefined(num_dimensions, 0); @@ -1426,6 +1427,31 @@ MultiIndexSet GridLocalPolynomial::getRefinementCanidates(double tolerance, Type refined.append(lrefined); } } + #else + if (level_limits.empty()){ + for(int i=0; i lrefined(num_dimensions, 0); + + if (level_limits.empty()){ + #pragma omp for + for(int i=0; i 0) ? MultiIndexSet(refined) : MultiIndexSet(); diff --git a/SparseGrids/tsgIndexManipulator.cpp b/SparseGrids/tsgIndexManipulator.cpp index 064839db8..269dc7176 100644 --- a/SparseGrids/tsgIndexManipulator.cpp +++ b/SparseGrids/tsgIndexManipulator.cpp @@ -48,7 +48,7 @@ namespace MultiIndexManipulations{ * The process is repeated until the new set is empty. * \endinternal */ -template +template void repeatAddIndexes(std::function &index)> inside, std::vector &level_sets){ size_t num_dimensions = level_sets.back().getNumDimensions(); bool adding = true; @@ -60,14 +60,14 @@ void repeatAddIndexes(std::function &index)> inside, std::vector point(num_dimensions); std::copy_n(level_sets.back().getIndex(i), num_dimensions, point.data()); for(auto &p : point){ - p += (use_parents) ? -1 : 1; // parents have lower index, children have higher indexes - if ( (!use_parents || (p >= 0)) && inside(point) ){ + p += (use_parents_direction) ? -1 : 1; // parents have lower index, children have higher indexes + if ( (not use_parents_direction or p >= 0) and inside(point) ){ #pragma omp critical { level.appendStrip(point); } } - p -= (use_parents) ? -1 : 1; // restore p + p -= (use_parents_direction) ? -1 : 1; // restore p } } @@ -122,7 +122,8 @@ void completeSetToLower(MultiIndexSet &set){ if (completion.getNumStrips() > 0){ std::vector level_sets = { MultiIndexSet(completion) }; - repeatAddIndexes([&](std::vector const &p) -> bool{ return set.missing(p); }, level_sets); + constexpr bool use_parents = true; + repeatAddIndexes([&](std::vector const &p) -> bool{ return set.missing(p); }, level_sets); set += unionSets(level_sets); } @@ -138,7 +139,8 @@ void completeSetToLower(MultiIndexSet &set){ inline MultiIndexSet generateGeneralMultiIndexSet(size_t num_dimensions, std::function &index)> criteria){ std::vector level_sets = { MultiIndexSet(num_dimensions, std::vector(num_dimensions, 0)) }; - repeatAddIndexes(criteria, level_sets); + constexpr bool use_parents = false; + repeatAddIndexes(criteria, level_sets); MultiIndexSet set = unionSets(level_sets); @@ -320,12 +322,53 @@ Data2D computeDAGup(MultiIndexSet const &mset){ MultiIndexSet selectFlaggedChildren(const MultiIndexSet &mset, const std::vector &flagged, const std::vector &level_limits){ size_t num_dimensions = mset.getNumDimensions(); + int n = mset.getNumIndexes(); - Data2D children_unsorted(mset.getNumDimensions(), 0); + Data2D children_unsorted(num_dimensions, 0); + #ifdef _OPENMP + #pragma omp parallel + { + Data2D lrefined(num_dimensions, 0); + std::vector kid(num_dimensions); + + if (level_limits.empty()){ + #pragma omp for + for(int i=0; i kid(num_dimensions); - int n = mset.getNumIndexes(); if (level_limits.empty()){ for(int i=0; i