Skip to content

Commit f3149e6

Browse files
authored
Merge pull request #1218 from HannoSpreeuw/Fix_1208
Fix 1208
2 parents 20bb7f5 + f7fb543 commit f3149e6

9 files changed

Lines changed: 45 additions & 3 deletions

File tree

lib/sapporo_light/sapporo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,8 @@ int sapporo::get_ngb_list(int cluster_id,
270270
sort(nbl, nbl + min(nblen, maxlength));
271271
return overflow;
272272
}
273+
274+
int sapporo::get_nj_max() const
275+
{
276+
return nj_max;
277+
}

lib/sapporo_light/sapporo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ extern "C"
103103
{
104104
int get_device_count();
105105
cudaError_t host_evaluate_gravity(sapporo_multi_struct);
106+
int g6_get_nj_max_();
106107
}
107108

108109
class sapporo {
@@ -169,7 +170,7 @@ class sapporo {
169170

170171
predict = false;
171172
nj_modified = 0;
172-
173+
173174
device.address_j = NULL;
174175

175176
device.t_j = NULL;
@@ -182,13 +183,15 @@ class sapporo {
182183
device.acc_i = NULL;
183184
device.vel_i = NULL;
184185
device.jrk_i = NULL;
186+
185187

186188
};
187189
~sapporo() {};
188190

189191
int open(int cluster_id);
190192
int close(int cluster_id);
191193
int get_n_pipes();
194+
int get_nj_max() const;
192195
int set_ti(int cluster_id, double ti);
193196

194197
int set_j_particle(int cluster_id,

lib/sapporo_light/sapporoG6lib.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ extern "C" {
4949
return grav.calc_lasthalf2(*cluster_id, *nj, *ni,
5050
index, xi, vi, *eps2, h2, acc, jerk, pot, inn);
5151
}
52+
int g6_get_nj_max_() {
53+
return grav.get_nj_max();
54+
}
5255

5356
int g6_initialize_jp_buffer_(int* cluster_id, int* buf_size) {return 0;}
5457
int g6_flush_jp_buffer_(int* cluster_id) {return 0;}
@@ -80,4 +83,3 @@ extern "C" {
8083

8184

8285
}
83-

lib/sapporo_light/send_fetch_data.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ void sapporo::send_j_particles_to_device(int ignore) {
6565
dev_struct &dev = device;
6666

6767
int nj = address_j.size();
68+
69+
if (nj > nj_max) {
70+
fprintf(stdout, "ERROR: nj = %d exceeds GPU capacity nj_max = %d\n", nj, nj_max);
71+
abort;
72+
}
6873

6974
CUDA_SAFE_CALL(cudaMemcpy( dev.address_j, &address_j[0], nj * sizeof(int), cudaMemcpyHostToDevice));
7075
CUDA_SAFE_CALL(cudaMemcpy( &dev.t_j [nj_max], &t_j[0], nj * sizeof(DS2), cudaMemcpyHostToDevice));

src/amuse_ph4/interface.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,9 @@ int get_id_of_updated_particle(int index, int * index_of_particle, int * status)
936936
*status = jd->UpdatedParticles[index].status;
937937
return 0;
938938
}
939+
940+
int get_nj_max(int * value)
941+
{
942+
*value = jd->get_nj_max();
943+
return 0;
944+
}

src/amuse_ph4/interface.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ def recompute_timesteps():
464464
function.result_type = 'int32'
465465
return function
466466

467+
@legacy_function
468+
def get_nj_max():
469+
function = LegacyFunctionSpecification()
470+
function.addParameter('nj_max', dtype='int32',
471+
direction=function.OUT)
472+
function.result_type = 'int32'
473+
return function
467474

468475
class ph4(GravitationalDynamics,GravityFieldCode):
469476

src/amuse_ph4/src/jdata.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#ifdef GPU
3636
#include "grape.h"
37+
#include "sapporo.h"
3738
#endif
3839

3940
// AMUSE STOPPING CONDITIONS SUPPORT
@@ -1153,3 +1154,12 @@ real jdata::get_tnext()
11531154
int ndum;
11541155
return sched->get_list(NULL, ndum);
11551156
}
1157+
1158+
int jdata::get_nj_max()
1159+
{
1160+
#ifdef GPU
1161+
return g6_get_nj_max_();
1162+
#else
1163+
return std::numeric_limits<int>::max();
1164+
#endif
1165+
}

src/amuse_ph4/src/jdata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class jdata {
212212
void spec_output(const char *s = NULL);
213213
void to_com();
214214
real get_tnext();
215+
int get_nj_max();
215216

216217
// In gpu.cc:
217218

src/tests/compile_tests/async_implementation/test_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
from pathlib import Path
1010
import time
11+
import sys
1112

1213

1314
class ForTesting(InCodeComponentImplementation):
@@ -120,7 +121,9 @@ def test7(self):
120121
self.assertEqual(x[0].result(), x[1])
121122
instance1.stop()
122123
instance2.stop()
123-
self.assertTrue(t2-t1 < 2.)
124+
# Do not run this test on MacOS runners, since they seem very slow.
125+
if sys.platform != "darwin":
126+
self.assertTrue(t2-t1 < 2.)
124127

125128
def test8(self):
126129
from threading import Thread

0 commit comments

Comments
 (0)