30 namespace swarm {
namespace gpu {
namespace bppt {
58 const static int nbod = T::n;
59 const static int pair_count = (nbod*(nbod-1))/2;
60 const static int CHUNK_SIZE = SHMEM_CHUNK_SIZE;
66 ensemble::SystemRef& sys;
92 GENERIC void calc_pair(
int ij)
const{
93 int i = first<nbod>( ij );
94 int j = second<nbod>( ij );
98 double dx[3] = { sys[j][0].pos()- sys[i][0].pos(),sys[j][1].pos()- sys[i][1].pos(), sys[j][2].pos()- sys[i][2].pos() };
100 double dv[3] = { sys[j][0].vel()- sys[i][0].vel(),sys[j][1].vel()- sys[i][1].vel(), sys[j][2].vel()- sys[i][2].vel() };
103 double r2 = dx[0]*dx[0]+dx[1]*dx[1]+dx[2]*dx[2];
106 double acc_mag = rsqrt(r2) / r2;
109 for(
int c = 0;
c < 3;
c ++)
111 shared[ij][
c].acc() = dx[
c]* acc_mag;
112 shared[ij][
c].jerk() = (dv[
c] - dx[
c] * jerk_mag ) * acc_mag;
131 double acc_from_planets = 0.0;
133 double acc_from_sun = 0.0;
135 double jerk_from_planets = 0.0;
137 double jerk_from_sun = 0.0;
141 for(
int d = 0; d < pair_count; d++){
142 int x = first<nbod>(d), y= second<nbod>(d);
146 acc_from_sun += shared[d][
c].acc() * sys[y].mass();
147 jerk_from_sun += shared[d][
c].jerk() * sys[y].mass();
149 acc_from_planets += shared[d][
c].acc() * sys[y].mass();
150 jerk_from_planets += shared[d][
c].jerk() * sys[y].mass();
154 acc_from_sun -= shared[d][
c].acc() * sys[
x].mass();
155 jerk_from_sun -= shared[d][
c].jerk() * sys[
x].mass();
157 acc_from_planets -= shared[d][
c].acc() * sys[
x].mass();
158 jerk_from_planets -= shared[d][
c].jerk() * sys[
x].mass();
163 acc = acc_from_sun + acc_from_planets;
164 jerk = jerk_from_sun + jerk_from_planets;
186 GPUAPI
void operator() (
int ij,
int b,
int c,
double& pos,
double& vel,
double& acc,
double& jerk)
const{
188 if(b < nbod && c < 3)
189 sys[b][
c].pos() = pos , sys[b][
c].vel() = vel;
194 if(b < nbod && c < 3){
201 return (nbod*3>(nbod-1)*nbod/2) ? nbod*3 : (nbod-1)*nbod/2;
206 return sizeof(shared_data)/CHUNK_SIZE;