Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
aa8e08e
better document huayno integrators and some test fixes
ipelupessy Jul 10, 2021
b83f47e
accelerate huayno for test particles (zero mass particles) (wip)
ipelupessy Jul 14, 2021
c921aa4
some fixes
ipelupessy Jul 14, 2021
a5641f2
fix error code
ipelupessy Jul 14, 2021
f45b257
fixup of kepler evolve logic for various cases, allow termination of CC
ipelupessy Jul 14, 2021
01bef2d
various fixes, setting zerosys and consistency checks fix
ipelupessy Jul 20, 2021
2a0c814
huayno: replace some integer by pointers, making the role of the vari…
ipelupessy Jul 20, 2021
89f1958
fix huayno split_cc to maintain separation of mass and massless part
ipelupessy Jul 22, 2021
19c4c4a
fixes for bs, some comments and diag reporting fixes, also do kepler in
ipelupessy Jul 23, 2021
78a9039
factor out last and lastzero pointers (not needed)
ipelupessy Jul 27, 2021
f1cd8d0
update test
ipelupessy Jul 27, 2021
c8b2080
retire old split_cc
ipelupessy Jul 27, 2021
60cb3fa
fix LAST macro
ipelupessy Jul 27, 2021
ca03c1b
actually skip all zero/zero mass timestep checks
ipelupessy Jul 27, 2021
1013db5
update test
ipelupessy Jul 27, 2021
2a542cd
retire IS_ZEROSYS
ipelupessy Jul 27, 2021
e28175b
make seperate cc linked list, simplifies particle sys
ipelupessy Jul 27, 2021
b40fa2c
add error controlled integrator (needs improved condition), do not
ipelupessy Jul 29, 2021
39e76a1
add error control files
ipelupessy Jul 29, 2021
10ae335
fix prototype
ipelupessy Jul 29, 2021
12096a7
fix comment
ipelupessy Jul 29, 2021
0156d17
Merge branch 'main' into huayno_fixes
ipelupessy Jul 30, 2021
49b1a26
Merge branch 'main' into huayno_fixes
ipelupessy Jul 30, 2021
c9e8ef7
small fixes in logging and small bug in kick, convert some direct part
ipelupessy Aug 2, 2021
4602d1a
retire kepler test evolver
ipelupessy Aug 2, 2021
a0f540c
minor cleanup
ipelupessy Aug 2, 2021
534ab8b
fix huayno cl build, some cl fixes and make sure zero mass interactions
ipelupessy Aug 3, 2021
77db77a
make double the default for huayno opencl
ipelupessy Aug 3, 2021
cce4c9b
refactor huayno opencl support to not need stdcl lib
ipelupessy Aug 5, 2021
a836cf3
minor cleanup of Makefile
ipelupessy Aug 5, 2021
83434ac
minor change for system energies
ipelupessy Aug 5, 2021
ebc9069
remove code comment and fix evolve_cl for small systems
ipelupessy Aug 6, 2021
60b06bd
add CC_SHARED10 (connected components with shared10 termination)
ipelupessy Aug 7, 2021
98e9d61
make recenter logic clearer
ipelupessy Aug 7, 2021
08e2724
minor fix and reset compsum in kepler
ipelupessy Aug 7, 2021
b77caea
minor error check
ipelupessy Aug 9, 2021
de8c93d
Merge branch 'main' into huayno_fixes
ipelupessy Aug 9, 2021
b2927d1
change test shasums (changed because of reset compensated summation in
ipelupessy Aug 10, 2021
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
41 changes: 12 additions & 29 deletions src/amuse/community/huayno/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ CXXFLAGS +=
LIBS += -lm
INCLUDE =


CODE_GENERATOR ?= $(AMUSE_DIR)/build.py

# set OpenCL and STDCL libraries
OPENCL = /home/inti/libraries/cuda
STDCL = /home/inti/libraries/coprthr

#---------------------------------------------

OBJS = interface.o
Expand All @@ -40,17 +33,14 @@ OPENMP_BUILDDIR = build_mp
AM_LIBS = -L$(AMUSE_DIR)/lib/amuse_mpi -lamuse_mpi
AM_CFLAGS = -I$(AMUSE_DIR)/lib/amuse_mpi

CL_LIBS?=-L$(OPENCL)/lib/x86_64 -lOpenCL -lpthread -ldl -L$(STDCL)/lib -lstdcl
CL_FLAGS?=-I$(OPENCL)/include -I$(STDCL)/include

all: huayno_worker

clean:
rm -f *.o *.bck *.pyc *.clh worker_code.cc worker_code.h
rm -Rf $(BUILDDIR)
rm -Rf $(OPENCL_BUILDDIR)
rm -Rf $(OPENMP_BUILDDIR)
rm -f huayno_worker huayno_worker_cl huayno_worker_mp huayno_worker_sockets
rm -f huayno_worker huayno_worker_cl huayno_worker_mp
-make -C $(SRCDIR) clean

distclean: clean
Expand All @@ -60,8 +50,7 @@ $(BUILDDIR)/Makefile: $(SRCDIR)/Makefile
cp $(SRCDIR)/Makefile $(BUILDDIR)/Makefile

$(BUILDDIR)/libhuayno.a: $(BUILDDIR)/Makefile $(LIBFILES) src/Makefile
make -C $(BUILDDIR) all VPATH=../src

make -C $(BUILDDIR) all VPATH=../src CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)"

$(OPENMP_BUILDDIR)/Makefile: $(SRCDIR)/Makefile
-mkdir $(OPENMP_BUILDDIR)
Expand All @@ -76,8 +65,7 @@ $(OPENCL_BUILDDIR)/Makefile: $(SRCDIR)/Makefile

$(OPENCL_BUILDDIR)/libhuayno_cl.a: $(OPENCL_BUILDDIR)/Makefile $(LIBFILES) src/Makefile
make -C $(OPENCL_BUILDDIR) libhuayno_cl.a VPATH=../src CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LIBS="$(LIBS)" INCLUDE="$(INCLUDE)"



worker_code.cc: interface.py
$(CODE_GENERATOR) --type=c interface.py HuaynoInterface -o $@

Expand All @@ -92,32 +80,27 @@ huayno_worker_mp: CXXFLAGS += $(OPENMP_CFLAGS)
huayno_worker_mp: __init__.py worker_code.cc worker_code.h $(OPENMP_BUILDDIR)/libhuayno.a $(OPENMP_BUILDDIR)/interface.o
$(MPICXX) $(SC_FLAGS) $(CXXFLAGS) $(INCLUDE) $(LDFLAGS) worker_code.cc $(OPENMP_BUILDDIR)/interface.o $(OPENMP_BUILDDIR)/libhuayno.a -o $@ $(LIBS) $(SC_CLIBS)

huayno_worker_mp.so: CFLAGS += $(OPENMP_CFLAGS)
huayno_worker_mp.so: CXXFLAGS += $(OPENMP_CFLAGS)
#~ huayno_worker_mp.so: CFLAGS += $(OPENMP_CFLAGS)
#~ huayno_worker_mp.so: CXXFLAGS += $(OPENMP_CFLAGS)

huayno_worker_cl: CFLAGS += -fopenmp -DEVOLVE_OPENCL
huayno_worker_cl: CXXFLAGS += -fopenmp -DEVOLVE_OPENCL
huayno_worker_cl: LIBS += $(CL_LIBS) -lstdcl
huayno_worker_cl: INCLUDE += $(CL_FLAGS)
huayno_worker_cl: CFLAGS += -DEVOLVE_OPENCL
huayno_worker_cl: CXXFLAGS += -DEVOLVE_OPENCL
huayno_worker_cl: LIBS += $(CL_LIBS)
huayno_worker_cl: INCLUDE += $(CL_FLAGS) -I.
huayno_worker_cl: __init__.py worker_code.cc worker_code.h $(OPENCL_BUILDDIR)/libhuayno_cl.a $(OPENCL_BUILDDIR)/interface.o
$(MPICXX) $(CXXFLAGS) $(INCLUDE) $(LDFLAGS) worker_code.cc $(OPENCL_BUILDDIR)/interface.o $(OPENCL_BUILDDIR)/libhuayno_cl.a -o $@ $(LIBS) $(SC_CLIBS)


.cc.o: $<
$(MPICXX) -I$(SRCDIR) $(SC_FLAGS) $(CXXFLAGS) $(INCLUDE) -c -o $@ $<

$(BUILDDIR)/%.o: %.c
$(MPICC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<
$(CC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<

$(OPENMP_BUILDDIR)/%.o: %.c
$(MPICC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<
$(CC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<


$(OPENCL_BUILDDIR)/%.o: %.c
$(MPICC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<
$(CC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<

.c.o: $<
$(MPICC) -I$(SRCDIR) $(SC_FLAGS) $(CFLAGS) $(INCLUDE) -c -o $@ $<

%.clh: %.cl
awk 'BEGIN{print "const char srcstr[]=" } {if(substr($$0,length($0))=="\\"){$$0=$$0"\\"};print "\""$$0"\\n\""} END{print ";"}' $< > $@
64 changes: 45 additions & 19 deletions src/amuse/community/huayno/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ int initialize_code()
nmax=NMAX;
err=LOOKUPSYMBOL(init_,)(&lookup, nmax*sizeof(struct particle)/sizeof(int));
if(err != 0) return err;
mainsys.n=0;
mainsys=zerosys;
mainsys.part=(struct particle*) malloc(nmax*sizeof(struct particle));
if(mainsys.part == NULL) return -1;
mainsys.last=NULL;
dt_param=.03;
dt_param=.03;
accel_zero_mass=1;
eps2=0.;
inttype=8;
opencl_device_type=0;
t_now=0.;
dtime=0.;
init_code();
// AMUSE STOPPING CONDITIONS SUPPORT
set_support_for_condition(COLLISION_DETECTION);
set_support_for_condition(OUT_OF_BOX_DETECTION);
Expand All @@ -56,8 +56,8 @@ int cleanup_code()
free(mainsys.part);
mainsys.part=NULL;
}
mainsys.last=NULL;
dt_param=.03;
accel_zero_mass=1;
t_now=0.;
dtime=0.;
eps2=0.;
Expand All @@ -67,6 +67,11 @@ int cleanup_code()
return 0;
}

void refresh_lookup()
{
for(int p=0;p<mainsys.n;p++) LOOKUPSYMBOL(,_update)(&lookup, mainsys.part[p].id,p);
}

int new_particle(int *id, double mass,
double x, double y, double z,
double vx, double vy, double vz,
Expand Down Expand Up @@ -99,7 +104,6 @@ int new_particle(int *id, double mass,
mainsys.part[p].postime=0;
mainsys.n++;
pcounter++;
mainsys.last=&mainsys.part[p];
return 0;
}

Expand All @@ -111,12 +115,7 @@ int delete_particle(int id)
if(err!=0) return err;
LOOKUPSYMBOL(,_delete)(&lookup,id);
mainsys.n--;
if(mainsys.n==0)
{
mainsys.last=NULL;
return 0;
}
mainsys.last--;
if(mainsys.n==0) return 0;
mainsys.part[p]=mainsys.part[mainsys.n];
LOOKUPSYMBOL(,_update)(&lookup,mainsys.part[p].id,p);
return 0;
Expand Down Expand Up @@ -277,13 +276,13 @@ int get_index_of_next_particle(int id, int *nout)

int get_kinetic_energy(double *kinetic_energy)
{
*kinetic_energy=system_kinetic_energy(mainsys);
*kinetic_energy=(double) system_kinetic_energy(mainsys);
return 0;
}

int get_potential_energy(double *potential_energy)
{
*potential_energy=system_potential_energy(mainsys);
*potential_energy=(double) system_potential_energy(mainsys);
return 0;
}

Expand All @@ -299,6 +298,19 @@ int set_inttype_parameter(int i)
return 0;
}

int get_opencl_device_type(int *i)
{
*i=opencl_device_type;
return 0;
}

int set_opencl_device_type(int i)
{
opencl_device_type=i;
return 0;
}


int set_timestep_parameter(double t)
{
dt_param=t;
Expand Down Expand Up @@ -335,6 +347,18 @@ int get_verbosity_parameter(int *t)
return 0;
}

int set_accel_zero_mass_parameter(int t)
{
accel_zero_mass=t;
return 0;
}

int get_accel_zero_mass_parameter(int *t)
{
*t=accel_zero_mass;
return 0;
}


int evolve_model(double t_end)
{
Expand Down Expand Up @@ -396,7 +420,7 @@ int evolve_model(double t_end)
t_now+=dt;
}
}
for(int p=0;p<mainsys.n;p++) LOOKUPSYMBOL(,_update)(&lookup, mainsys.part[p].id,p);
refresh_lookup();

if (set_conditions & enabled_conditions) {
int err,type, number_of_particles, id;
Expand Down Expand Up @@ -433,6 +457,7 @@ int get_begin_time(double * output) {
int commit_particles()
{
init_evolve(mainsys,inttype);
refresh_lookup();
return 0;
}

Expand Down Expand Up @@ -467,6 +492,7 @@ int synchronize_model()
int recommit_particles()
{
init_evolve(mainsys,inttype);
refresh_lookup();
return 0;
}

Expand Down Expand Up @@ -528,10 +554,12 @@ int get_center_of_mass_velocity(double *vx,double *vy,double *vz)
int recommit_parameters()
{
init_evolve(mainsys,inttype);
refresh_lookup();
return 0;
}
int commit_parameters()
{
init_code();
t_now = begin_time;
return 0;
}
Expand Down Expand Up @@ -564,10 +592,9 @@ int get_indices_of_colliding_particles(int *p1,int*p2)
int get_gravity_at_point(double * eps, double * x, double * y, double * z,
double * ax, double * ay, double * az, int n)
{
struct sys tmpsys;
struct sys tmpsys=zerosys;
tmpsys.n=n;
tmpsys.part=(struct particle*) malloc(n*sizeof(struct particle));
tmpsys.last=&tmpsys.part[n];
for(int p=0;p<n;p++)
{
tmpsys.part[p].pos[0]=x[p];
Expand Down Expand Up @@ -598,10 +625,9 @@ int get_potential_at_point(double * eps,
double * x, double * y, double * z,
double * phi, int n)
{
struct sys tmpsys;
struct sys tmpsys=zerosys;
tmpsys.n=n;
tmpsys.part=(struct particle*) malloc(n*sizeof(struct particle));
tmpsys.last=&tmpsys.part[n];
for(int p=0;p<n;p++)
{
tmpsys.part[p].pos[0]=x[p];
Expand Down
46 changes: 45 additions & 1 deletion src/amuse/community/huayno/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,35 @@ def set_eps2_parameter():
function.result_type = 'i'
return function

@legacy_function
def get_accel_zero_mass_parameter():
function = LegacyFunctionSpecification()
function.addParameter('accelerate_zero_mass', dtype='b', direction=function.OUT)
function.result_type = 'i'
return function

@legacy_function
def set_accel_zero_mass_parameter():
function = LegacyFunctionSpecification()
function.addParameter('accelerate_zero_mass', dtype='b', direction=function.IN)
function.result_type = 'i'
return function

@legacy_function
def get_opencl_device_type():
function = LegacyFunctionSpecification()
function.addParameter('opencl_device_type', dtype='i', direction=function.OUT)
function.result_type = 'i'
return function

@legacy_function
def set_opencl_device_type():
function = LegacyFunctionSpecification()
function.addParameter('opencl_device_type', dtype='i', direction=function.IN)
function.result_type = 'i'
return function


def set_eps2(self, e):
return self.set_eps2_parameter(e)

Expand Down Expand Up @@ -197,7 +226,7 @@ def _list(cls):
CC_BS = 24, CCC_BS = 25, BS_CC_KEPLER = 26, CC_BSA = 27, CCC_BSA = 28, SHARED2_COLLISIONS = 29,
SHARED4_COLLISIONS = 30, SHARED6_COLLISIONS = 31, SHARED8_COLLISIONS = 32,
SHARED10_COLLISIONS = 33, CONSTANT2 = 34, CONSTANT4 = 35, CONSTANT6 = 36,
CONSTANT8 = 37, CONSTANT10 = 38, )
CONSTANT8 = 37, CONSTANT10 = 38, ERROR_CONTROL=39, CC_SHARED10=40, CCC_SHARED10=41)

for key, val in all_inttypes.items():
setattr(inttypes, key, val)
Expand Down Expand Up @@ -260,6 +289,14 @@ def define_parameters(self, handler):
default_value = 0
)

handler.add_boolean_parameter(
"get_accel_zero_mass_parameter",
"set_accel_zero_mass_parameter",
"accelerate_zero_mass",
"accelerate zero mass particle interactions (should always be true, except for testing)",
default_value = True
)

inttypes=sorted([(getattr(self.inttypes,t),t )
for i,t in enumerate(sorted(self.inttypes._list()))])

Expand Down Expand Up @@ -289,6 +326,13 @@ def define_parameters(self, handler):
default_value = 0.0 | nbody_system.time
)

handler.add_method_parameter(
"get_opencl_device_type",
"set_opencl_device_type",
"opencl_device_type",
"set preferred OpenCL device type (0=default, 1=cpu, 2=gpu)",
default_value = 0
)

def define_methods(self, handler):
GravitationalDynamics.define_methods(self, handler)
Expand Down
Loading