Skip to content

Commit

Permalink
grid: Fix build issues related to unroll pragma
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Mar 3, 2021
1 parent 4b0df70 commit 21a7ae4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/grid/common/grid_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#define GRID_STRINGIFY(SYMBOL) #SYMBOL

#if defined(__GNUC__)
// GCC introduced the unroll pragma with version 8 using a custom syntax.
#if defined(__GNUC__) && __GNUC__ >= 8
#define GRID_PRAGMA_UNROLL(N) _Pragma(GRID_STRINGIFY(GCC unroll N))
#else
#elif defined(__GNUC__) && __GNUC__ < 8
#define GRID_PRAGMA_UNROLL(N)
#else // Most other compilers support a common syntax.
#define GRID_PRAGMA_UNROLL(N) _Pragma(GRID_STRINGIFY(unroll(N)))
#endif

Expand Down
9 changes: 5 additions & 4 deletions src/grid/ref/grid_ref_collint.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "../common/grid_library.h"
#include "../common/grid_sphere_cache.h"

#define GRID_MAX_LP_OPTIMIZED 9

#if (GRID_DO_COLLOCATE)
#define GRID_CONST_WHEN_COLLOCATE const
#define GRID_CONST_WHEN_INTEGRATE
Expand Down Expand Up @@ -224,10 +226,9 @@ static inline void ortho_cxy_to_grid(const int lp, const int kg1, const int kg2,
memset(cx, 0, cx_size * sizeof(double));

// Generate separate branches for low values of lp gives up to 30% speedup.
const int MAX_LP_OPTIMIZED = 9;
if (lp <= MAX_LP_OPTIMIZED) {
GRID_PRAGMA_UNROLL(MAX_LP_OPTIMIZED + 1)
for (int ilp = 0; ilp <= MAX_LP_OPTIMIZED; ilp++) {
if (lp <= GRID_MAX_LP_OPTIMIZED) {
GRID_PRAGMA_UNROLL(GRID_MAX_LP_OPTIMIZED + 1)
for (int ilp = 0; ilp <= GRID_MAX_LP_OPTIMIZED; ilp++) {
if (lp == ilp) {
ortho_cxy_to_grid_low(ilp, j1, j2, kg1, kg2, jg1, jg2, cmax, pol, map,
npts_local, sphere_bounds_iter, cx, cxy, grid);
Expand Down

0 comments on commit 21a7ae4

Please sign in to comment.