Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
460169d
Perform these calculations only with mass
HannoSpreeuw May 6, 2026
53b929b
This essentially reverts commit 460169d
HannoSpreeuw May 7, 2026
98eca4f
Lower limit on the mass not hard coded.
HannoSpreeuw May 7, 2026
75f1c44
Test particles will never reach the GPU
HannoSpreeuw May 7, 2026
951bb36
"SAPPORO_TEST_PARTICLE_MASS" is set
HannoSpreeuw May 7, 2026
5b1611c
Declaration of "nj_massive"
HannoSpreeuw May 7, 2026
4dafb00
Sorting of particles along mass
HannoSpreeuw May 7, 2026
8d664c2
Set "nj_massive" for "gpu"
HannoSpreeuw May 7, 2026
c1712d4
Runs with test particles seemed to take forever
HannoSpreeuw May 7, 2026
107d43a
No speedup from conditional
HannoSpreeuw May 15, 2026
ae1c36e
Simpler way to weed out massless particles
HannoSpreeuw May 15, 2026
4f15dd9
With the new method, "nj_massive" is redundant
HannoSpreeuw May 15, 2026
7b6c07f
Line most likely redundant
HannoSpreeuw May 15, 2026
1a35326
"nj_massive" has become redundant.
HannoSpreeuw May 15, 2026
f46e8d5
This whitespace was redundant.
HannoSpreeuw May 18, 2026
c85271f
This check should be made at the caller
HannoSpreeuw May 18, 2026
ac1ecdf
Check "nj > 0" at the caller
HannoSpreeuw May 19, 2026
1d0386d
Only add a j-particle when it has mass
HannoSpreeuw May 19, 2026
7568d01
Merge branch 'main' into 1207_fix
HannoSpreeuw May 19, 2026
3a2a913
This print statement is redundant
HannoSpreeuw May 19, 2026
3f3f787
This conditional has become redundant
HannoSpreeuw May 19, 2026
b726e4f
We should not add a particle when massless
HannoSpreeuw May 19, 2026
1f708c9
This increases achieved occupancy
HannoSpreeuw May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/sapporo_light/sapporo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ int sapporo::set_j_particle(int cluster_id,
exit(-1);
}

// Skip test particles (massless particles) as they don't contribute to gravity
if (mass <= SAPPORO_TEST_PARTICLE_MASS) return 0;

DS Dmass = (DS){mass, INT_AS_FLOAT(id)};
map<int,int>::iterator iterator = mapping_from_address_j_to_index_in_update_array.find(address);
map<int,int>::iterator end = mapping_from_address_j_to_index_in_update_array.end();
Expand Down Expand Up @@ -134,6 +137,7 @@ void sapporo::calc_firsthalf(int cluster_id,
}

if (address_j.size() > 0) {
// Since we skip adding test particles, all particles in address_j are massive
send_j_particles_to_device(device_id);
}

Expand All @@ -147,7 +151,9 @@ void sapporo::calc_firsthalf(int cluster_id,
acc_j.clear();
jrk_j.clear();
}
evaluate_gravity(ni, nj);
if (nj > 0) {
evaluate_gravity(ni, nj);
}

}

Expand Down
9 changes: 9 additions & 0 deletions lib/sapporo_light/sapporo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#include <map>

#include <math.h>

#ifndef SAPPORO_TEST_PARTICLE_MASS
# if defined(_TINY_)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TINY ever not defined? If so, why?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_TINY_ may not be defined if PH4 is not the running AMUSE code in which case the _TINY_ definition in stdinc.h may be skipped:

#define _TINY_	   (pow(2.0, -52))	  // double limit on powers of 2

# define SAPPORO_TEST_PARTICLE_MASS ((float)(_TINY_))
# else
# define SAPPORO_TEST_PARTICLE_MASS 1e-30f
# endif
#endif

using namespace std;

#include <cuda_runtime.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/sapporo_light/sapporo_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define MAXCUDADEVICES 4
#define NBODIES_MAX 524288
#define NBLOCKS 16 /* number of block which can be run simultaneously */
#define NBLOCKS 256 /* number of block which can be run simultaneously */

#ifdef NGB
#define NTHREADS 256 /* max number of threads which can run per block */
Expand Down
1 change: 1 addition & 0 deletions lib/sapporo_light/send_fetch_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int sapporo::fetch_ngb_list_from_device(int ignore) {


double sapporo::evaluate_gravity(int ni, int nj) {

#ifdef NGB
bool ngb = true;
#else
Expand Down
47 changes: 22 additions & 25 deletions src/amuse_ph4/src/idata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,30 @@ void idata::get_partial_acc_and_jerk()
ldnn[i] = _INFINITY_;
for (int k = 0; k < 3; k++) lacc[i][k] = ljerk[i][k] = 0;
for (int j = j_start; j < j_end; j++) {
// Skip particles with zero mass.
if (jdat->mass[j] > _TINY_){
r2 = xv = 0;
for (int k = 0; k < 3; k++) {
dx[k] = jdat->pred_pos[j][k] - ipos[i][k];
dv[k] = jdat->pred_vel[j][k] - ivel[i][k];
r2 += dx[k]*dx[k];
xv += dx[k]*dv[k];
}
r2i = 1/(r2+eps2+_TINY_);
ri = sqrt(r2i);
mri = jdat->mass[j]*ri;
mr3i = mri*r2i;
a3 = -3*xv*r2i;
// PRC(jdat->mpi_rank); PRC(ri); PRL(mri);
if (r2 > _TINY_) {
lpot[i] -= mri;
if (r2 < ldnn[i]) {
ldnn[i] = r2;
lnn[i] = j;
}
}
for (int k = 0; k < 3; k++) {
lacc[i][k] += mr3i*dx[k];
ljerk[i][k] += mr3i*(dv[k]+a3*dx[k]);
r2 = xv = 0;
for (int k = 0; k < 3; k++) {
dx[k] = jdat->pred_pos[j][k] - ipos[i][k];
dv[k] = jdat->pred_vel[j][k] - ivel[i][k];
r2 += dx[k]*dx[k];
xv += dx[k]*dv[k];
}
r2i = 1/(r2+eps2+_TINY_);
ri = sqrt(r2i);
mri = jdat->mass[j]*ri;
mr3i = mri*r2i;
a3 = -3*xv*r2i;
// PRC(jdat->mpi_rank); PRC(ri); PRL(mri);
if (r2 > _TINY_) {
lpot[i] -= mri;
if (r2 < ldnn[i]) {
ldnn[i] = r2;
lnn[i] = j;
}
}
for (int k = 0; k < 3; k++) {
lacc[i][k] += mr3i*dx[k];
ljerk[i][k] += mr3i*(dv[k]+a3*dx[k]);
}
}
ldnn[i] = sqrt(ldnn[i]);
}
Expand Down
5 changes: 5 additions & 0 deletions src/amuse_ph4/src/jdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ int jdata::add_particle(real pmass, real pradius,
real dt) // default = -1
{
const char *in_function = "jdata::add_particle";

if (pmass <= _TINY_) {
return -1;
}

if (DEBUG > 2 && mpi_rank == 0) PRL(in_function);

if (nj >= njbuf) {
Expand Down
Loading