|
@ -14,59 +14,79 @@ |
|
|
|
|
|
|
|
|
namespace wvlt { |
|
|
namespace wvlt { |
|
|
namespace par { |
|
|
namespace par { |
|
|
// Convenience container of some often-used values
|
|
|
// The structs proc_info and plan_1D contain some often
|
|
|
// n = inputisze, p = nproc(), s = pid()
|
|
|
// used values in the parallel algorithm, they also
|
|
|
// b = blocksize, prev/next = previous and next processor index
|
|
|
// precompute some constants.
|
|
|
struct distribution { |
|
|
|
|
|
unsigned int n, p, s, b, prev, next; |
|
|
// p = nproc(), s = pid()
|
|
|
|
|
|
// prev/next = previous and next processor index
|
|
|
distribution(unsigned int n_, unsigned int p_, unsigned int s_) |
|
|
struct proc_info { |
|
|
: n(n_), p(p_), s(s_), b(n/p), prev((s-1+p)%p), next((s+1)%p) |
|
|
unsigned int p, s, prev, next; |
|
|
|
|
|
|
|
|
|
|
|
proc_info(unsigned int p_, unsigned int s_) |
|
|
|
|
|
: p(p_), s(s_), prev((s-1+p)%p), next((s+1)%p) |
|
|
|
|
|
{} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// n = inputisze, b = blocksize, m = step_size
|
|
|
|
|
|
// Cm = communication size
|
|
|
|
|
|
// TODO: describe other vars
|
|
|
|
|
|
struct plan_1D { |
|
|
|
|
|
unsigned int n, b, m, Cm, small_steps, big_steps, remainder; |
|
|
|
|
|
|
|
|
|
|
|
plan_1D(unsigned int n_, unsigned int b_, unsigned int m_) |
|
|
|
|
|
: n(n_), b(b_), m(m_), Cm(pow_two(m+1) - 2), small_steps(two_log(b) - 1), big_steps(small_steps/m), remainder(small_steps - m*big_steps) |
|
|
{} |
|
|
{} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
inline unsigned int communication_size(unsigned int m){ |
|
|
inline plan_1D get_remainder(plan_1D plan){ |
|
|
return pow_two(m+1) - 2; |
|
|
plan.m = plan.remainder; |
|
|
|
|
|
plan.Cm = pow_two(plan.m+1) - 2; |
|
|
|
|
|
plan.remainder = 0; |
|
|
|
|
|
return plan; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline void step(distribution const & d, double* x, double* other, unsigned int size, unsigned int stride, unsigned int m){ |
|
|
inline void comm_step(proc_info const & pi, plan_1D const & plan, double* x, double* other, unsigned int size, unsigned int stride){ |
|
|
unsigned int t = d.prev; |
|
|
for(unsigned int i = 0; i < plan.Cm; ++i){ |
|
|
unsigned int Cm = communication_size(m); |
|
|
bsp::put(pi.prev, &x[stride*i], other, i, 1); |
|
|
for(unsigned int i = 0; i < Cm; ++i){ |
|
|
|
|
|
bsp::put(t, &x[stride*i], other, i, 1); |
|
|
|
|
|
} |
|
|
} |
|
|
bsp::sync(); |
|
|
} |
|
|
|
|
|
|
|
|
unsigned int end = pow_two(m); |
|
|
inline void comp_step(proc_info const & d, plan_1D const & plan, double* x, double* other, unsigned int size, unsigned int stride){ |
|
|
|
|
|
unsigned int end = pow_two(plan.m); |
|
|
for(unsigned int i = 1; i < end; i <<= 1){ |
|
|
for(unsigned int i = 1; i < end; i <<= 1){ |
|
|
wavelet_mul(x, other[0], other[i], size, stride*i); |
|
|
wavelet_mul(x, other[0], other[i], size, stride*i); |
|
|
if(i < end/2) wavelet_mul_base(other, 2*end - 2*i, i); |
|
|
if(i < end/2) wavelet_mul_base(other, 2*end - 2*i, i); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline void base(distribution const & d, double* x, double* other, unsigned int size, unsigned int m){ |
|
|
inline void step(proc_info const & d, plan_1D const & plan, double* x, double* other, unsigned int size, unsigned int stride){ |
|
|
unsigned int t = two_log(d.b); |
|
|
comm_step(d, plan, x, other, size, stride); |
|
|
unsigned int steps = (t-1)/m; |
|
|
bsp::sync(); |
|
|
|
|
|
comp_step(d, plan, x, other, size, stride); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void base(proc_info const & d, plan_1D const & plan, double* x, double* other, unsigned int size){ |
|
|
|
|
|
// do steps of size m
|
|
|
unsigned int stride = 1; |
|
|
unsigned int stride = 1; |
|
|
for(unsigned int i = steps; i; i--){ |
|
|
for(unsigned int i = plan.big_steps; i; i--){ |
|
|
step(d, x, other, size, stride, m); |
|
|
step(d, plan, x, other, size, stride); |
|
|
stride <<= m; |
|
|
stride <<= plan.m; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned int remaining = (t-1) - m*steps; |
|
|
// in the case m didn't divide the total number of small steps, do the remaining part
|
|
|
if(remaining) |
|
|
if(plan.remainder) |
|
|
step(d, x, other, size, stride, remaining); |
|
|
step(d, get_remainder(plan), x, other, size, stride); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// block distributed parallel wavelet, result is also in block distribution (in-place in x)
|
|
|
// block distributed parallel wavelet, result is also in block distribution (in-place in x)
|
|
|
inline void wavelet(distribution const & d, double* x, double* next, double* proczero, unsigned int m){ |
|
|
inline void wavelet(proc_info const & d, plan_1D const & plan, double* x, double* next, double* proczero){ |
|
|
// First do the local part
|
|
|
// First do the local part
|
|
|
base(d, x, next, d.b, m); |
|
|
base(d, plan, x, next, plan.b); |
|
|
|
|
|
|
|
|
// Then do a fan in (i.e. 2 elements to proc zero)
|
|
|
// Then do a fan in (i.e. 2 elements to proc zero)
|
|
|
for(unsigned int i = 0; i < 2; ++i){ |
|
|
for(unsigned int i = 0; i < 2; ++i){ |
|
|
bsp::put(0, &x[i * d.b/2], proczero, d.s * 2 + i); |
|
|
bsp::put(0, &x[i * plan.b/2], proczero, d.s * 2 + i); |
|
|
} |
|
|
} |
|
|
bsp::sync(); |
|
|
bsp::sync(); |
|
|
|
|
|
|
|
@ -76,7 +96,7 @@ namespace wvlt { |
|
|
// and to send it back to everyone
|
|
|
// and to send it back to everyone
|
|
|
for(unsigned int t = 0; t < d.p; ++t){ |
|
|
for(unsigned int t = 0; t < d.p; ++t){ |
|
|
for(unsigned int i = 0; i < 2; ++i){ |
|
|
for(unsigned int i = 0; i < 2; ++i){ |
|
|
bsp::put(t, &proczero[t*2 + i], x, i * d.b/2); |
|
|
bsp::put(t, &proczero[t*2 + i], x, i * plan.b/2); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|