Skip to content

Commit

Permalink
ensure highly factorizable MPB sizes (NanoComp#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Jun 12, 2020
1 parent 76d029d commit 7887b10
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/mpb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ static double dot_product(const mpb_real a[3], const mpb_real b[3]) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}

// return the next number factorizable into powers of 2,3,5,7
// for efficient FFTs, similar to optimize-grid-size! in MPB:
static int nextpow2357(int n) {
while (1) {
int m = n;
while (m % 3 == 0) m /= 3;
while (m % 5 == 0) m /= 5;
while (m % 7 == 0) m /= 7;
if ((m & (m - 1)) == 0) // if m is a power of 2
return n;
n += 1;
}
}

/****************************************************************/
/* call MPB to get the band_numth eigenmode at freq frequency. */
/* */
Expand Down Expand Up @@ -332,6 +346,7 @@ void *fields::get_eigenmode(double frequency, direction d, const volume where, c
for (int i = 0; i < 3; ++i) {
n[i] = int(resolution * s[i] + 0.5);
if (n[i] == 0) n[i] = 1;
n[i] = nextpow2357(n[i]);
if (s[i] != 0)
R[i][i] = s[i];
else {
Expand Down

0 comments on commit 7887b10

Please sign in to comment.