Skip to content

Commit

Permalink
experimental code to run amuse without mpi_comm_spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenve committed Feb 26, 2016
1 parent 7b2f422 commit c9b23e0
Show file tree
Hide file tree
Showing 14 changed files with 1,223 additions and 59 deletions.
1 change: 1 addition & 0 deletions aclocal.m4
Expand Up @@ -27,3 +27,4 @@ m4_include([m4/gsl.m4])
m4_include([m4/python_dev.m4])
m4_include([m4/fortran.m4])
m4_include([m4/netcdf.m4])
m4_include([m4/pic_flags.m4])
116 changes: 116 additions & 0 deletions configure
Expand Up @@ -700,6 +700,7 @@ GSL_CONFIG
GSL_LIBS
GSL_CFLAGS
GSL_FLAGS
PIC_FLAGS
NETCDFF_PREFIX
NETCDFF_LIBS
NETCDFF_FLAGS
Expand Down Expand Up @@ -845,6 +846,7 @@ with_gmp
with_mpfr
with_hdf5
with_netcdf
enable_pic
with_gsl_prefix
with_gsl_exec_prefix
enable_gsltest
Expand Down Expand Up @@ -884,6 +886,7 @@ GMP_LIBS
MPFR_CFLAGS
MPFR_LIBS
CXXCPP
PIC_FLAGS
GSL_CFLAGS
GSL_LIBS'

Expand Down Expand Up @@ -1502,6 +1505,8 @@ Optional Features:
--enable-cuda Enable CUDA for codes
--enable-sapporo2 Use the provided sapporo library version 2, instead
of sapporo_light
--disable-pic compile PIC objects [default=enabled for shared
builds on supported platforms]
--disable-gsltest Do not try to compile and run a test GSL program
Optional Packages:
Expand Down Expand Up @@ -1556,6 +1561,7 @@ Some influential environment variables:
MPFR_CFLAGS C compiler flags for MPFR, overriding pkg-config
MPFR_LIBS linker flags for MPFR, overriding pkg-config
CXXCPP C++ preprocessor
PIC_FLAGS compiler flags for PIC code
GSL_CFLAGS C compiler flags for GSL, overriding pkg-config
GSL_LIBS linker flags for GSL, overriding pkg-config
Expand Down Expand Up @@ -8541,6 +8547,116 @@ fi



# Check whether --enable-pic was given.
if test "${enable_pic+set}" = set; then :
enableval=$enable_pic; enable_pic="$enableval"
test "x$enable_pic" = x && enable_pic=auto
else
enable_pic=auto
fi

# disable PIC by default for static builds
if test "$enable_pic" = auto && test "$enable_static" = yes; then
enable_pic=no
fi
# if PIC hasn't been explicitly disabled, try to figure out the flags
if test "$enable_pic" != no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to produce PIC" >&5
$as_echo_n "checking for $CC option to produce PIC... " >&6; }
# allow the user's flags to override
if test "x$PIC_FLAGS" = x; then
# see if we're using GCC
if test "x$GCC" = xyes; then
case "$host_os" in
aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*)
# PIC is the default for these OSes.
;;
mingw*|os2*|pw32*)
# This hack is so that the source file can tell whether
# it is being built for inclusion in a dll (and should
# export symbols for example).
PIC_FLAGS="-DDLL_EXPORT"
;;
darwin*|rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
PIC_FLAGS="-fno-common"
;;
hpux*)
# PIC is the default for IA64 HP-UX and 64-bit HP-UX,
# but not for PA HP-UX.
case $host_cpu in
hppa*64*|ia64*)
;;
*)
PIC_FLAGS="-fPIC"
;;
esac
;;
*)
# Everyone else on GCC uses -fPIC
PIC_FLAGS="-fPIC"
;;
esac
else # !GCC
case "$host_os" in
hpux9*|hpux10*|hpux11*)
# PIC is the default for IA64 HP-UX and 64-bit HP-UX,
# but not for PA HP-UX.
case "$host_cpu" in
hppa*64*|ia64*)
# +Z the default
;;
*)
PIC_FLAGS="+Z"
;;
esac
;;
linux*|k*bsd*-gnu)
case `basename "$CC"` in
icc*|ecc*|ifort*)
PIC_FLAGS="-KPIC"
;;
pgcc*|pgf77*|pgf90*|pgf95*)
# Portland Group compilers (*not* the Pentium gcc
# compiler, which looks to be a dead project)
PIC_FLAGS="-fpic"
;;
ccc*)
# All Alpha code is PIC.
;;
xl*)
# IBM XL C 8.0/Fortran 10.1 on PPC
PIC_FLAGS="-qpic"
;;
*)
case `$CC -V 2>&1 | sed 5q` in
*Sun\ C*|*Sun\ F*)
# Sun C 5.9 or Sun Fortran
PIC_FLAGS="-KPIC"
;;
esac
esac
;;
solaris*)
PIC_FLAGS="-KPIC"
;;
sunos4*)
PIC_FLAGS="-PIC"
;;
esac
fi # GCC
fi # PIC_FLAGS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PIC_FLAGS" >&5
$as_echo "$PIC_FLAGS" >&6; }
fi


CFLAGS="$CFLAGS $PIC_FLAGS"
CXXFLAGS="$CXXFLAGS $PIC_FLAGS"
FCFLAGS="$FCFLAGS $PIC_FLAGS"



# Check whether --with-gsl-prefix was given.
if test "${with_gsl_prefix+set}" = set; then :
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -203,6 +203,11 @@ AX_HDF5()

AX_NETCDF()

DETECT_PIC_FLAGS()
CFLAGS="$CFLAGS $PIC_FLAGS"
CXXFLAGS="$CXXFLAGS $PIC_FLAGS"
FCFLAGS="$FCFLAGS $PIC_FLAGS"

AX_PATH_GSL(1.0, [FOUND_GSL=yes], [
FOUND_GSL=no
AC_MSG_WARN([gsl not found, please specify --with-gsl])
Expand Down
24 changes: 18 additions & 6 deletions lib/stopcond/stopcond.c
Expand Up @@ -440,14 +440,25 @@ int get_stopping_condition_maximum_internal_energy_parameter_(double *value) {

#include <mpi.h>
static int sc_mpi_rank;
static MPI_Comm world = MPI_COMM_WORLD;
static int is_world_set = 0;

int mpi_set_communicator(void * comm) {
world = *(MPI_Comm *)comm;
is_world_set = 1;
}

int mpi_setup_stopping_conditions() {
if(!is_world_set) {
world = MPI_COMM_WORLD;
is_world_set = 1;
}
int error;
error = MPI_Comm_rank(MPI_COMM_WORLD, &sc_mpi_rank);
error = MPI_Comm_rank(world, &sc_mpi_rank);
if(error) {
return -1;
}
error = MPI_Comm_size(MPI_COMM_WORLD, &sc_mpi_size);
error = MPI_Comm_size(world, &sc_mpi_size);
if(error) {
return -1;
}
Expand Down Expand Up @@ -483,11 +494,11 @@ int mpi_collect_stopping_conditions() {
memset(displs, 0, sizeof(displs));
long set = 0;

MPI_Allreduce(&set_conditions, &set, 1, MPI_INTEGER, MPI_BOR, MPI_COMM_WORLD);
MPI_Allreduce(&set_conditions, &set, 1, MPI_INTEGER, MPI_BOR, world);

set_conditions = set;

MPI_Gather(&number_of_stopping_conditions_set, 1, MPI_INTEGER, counts, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(&number_of_stopping_conditions_set, 1, MPI_INTEGER, counts, 1, MPI_INT, 0, world);

if(sc_mpi_rank == 0) {
local_number_of_stopping_conditions_set = 0;
Expand Down Expand Up @@ -522,7 +533,7 @@ int mpi_collect_stopping_conditions() {
displs,
MPI_INTEGER,
0,
MPI_COMM_WORLD
world
);

if(sc_mpi_rank == 0) {
Expand All @@ -543,7 +554,7 @@ int mpi_collect_stopping_conditions() {
displs,
MPI_INTEGER,
0,
MPI_COMM_WORLD
world
);

if(sc_mpi_rank == 0) {
Expand All @@ -561,6 +572,7 @@ int mpi_collect_stopping_conditions() {

#else

int mpi_set_communicator(void * comm) {return 0;}
int mpi_setup_stopping_conditions() {sc_mpi_size = 1; return 0;}
int mpi_collect_stopping_conditions() {return 0;}
int mpi_distribute_stopping_conditions() {return 0;}
Expand Down
1 change: 1 addition & 0 deletions lib/stopcond/stopcond.h
Expand Up @@ -85,6 +85,7 @@ int set_stopping_condition_particle_index(int index, int index_in_the_condition,
int mpi_setup_stopping_conditions();
int mpi_distribute_stopping_conditions();
int mpi_collect_stopping_conditions();
int mpi_set_communicator(void * comm);

#ifdef __cplusplus
}
Expand Down
105 changes: 105 additions & 0 deletions m4/pic_flags.m4
@@ -0,0 +1,105 @@
AC_DEFUN([DETECT_PIC_FLAGS],
[AC_REQUIRE([AC_PROG_CC])dnl
AC_ARG_VAR([PIC_FLAGS], [compiler flags for PIC code])
AC_ARG_ENABLE([pic],
[AS_HELP_STRING([--disable-pic],
[compile PIC objects @<:@default=enabled for shared builds
on supported platforms@:>@])],
[enable_pic="$enableval"
test "x$enable_pic" = x && enable_pic=auto],
[enable_pic=auto])
# disable PIC by default for static builds
if test "$enable_pic" = auto && test "$enable_static" = yes; then
enable_pic=no
fi
# if PIC hasn't been explicitly disabled, try to figure out the flags
if test "$enable_pic" != no; then
AC_MSG_CHECKING([for $CC option to produce PIC])
# allow the user's flags to override
if test "x$PIC_FLAGS" = x; then
# see if we're using GCC
if test "x$GCC" = xyes; then
case "$host_os" in
aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*)
# PIC is the default for these OSes.
;;
mingw*|os2*|pw32*)
# This hack is so that the source file can tell whether
# it is being built for inclusion in a dll (and should
# export symbols for example).
PIC_FLAGS="-DDLL_EXPORT"
;;
darwin*|rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
PIC_FLAGS="-fno-common"
;;
hpux*)
# PIC is the default for IA64 HP-UX and 64-bit HP-UX,
# but not for PA HP-UX.
case $host_cpu in
hppa*64*|ia64*)
;;
*)
PIC_FLAGS="-fPIC"
;;
esac
;;
*)
# Everyone else on GCC uses -fPIC
PIC_FLAGS="-fPIC"
;;
esac
else # !GCC
case "$host_os" in
hpux9*|hpux10*|hpux11*)
# PIC is the default for IA64 HP-UX and 64-bit HP-UX,
# but not for PA HP-UX.
case "$host_cpu" in
hppa*64*|ia64*)
# +Z the default
;;
*)
PIC_FLAGS="+Z"
;;
esac
;;
linux*|k*bsd*-gnu)
case `basename "$CC"` in
icc*|ecc*|ifort*)
PIC_FLAGS="-KPIC"
;;
pgcc*|pgf77*|pgf90*|pgf95*)
# Portland Group compilers (*not* the Pentium gcc
# compiler, which looks to be a dead project)
PIC_FLAGS="-fpic"
;;
ccc*)
# All Alpha code is PIC.
;;
xl*)
# IBM XL C 8.0/Fortran 10.1 on PPC
PIC_FLAGS="-qpic"
;;
*)
case `$CC -V 2>&1 | sed 5q` in
*Sun\ C*|*Sun\ F*)
# Sun C 5.9 or Sun Fortran
PIC_FLAGS="-KPIC"
;;
esac
esac
;;
solaris*)
PIC_FLAGS="-KPIC"
;;
sunos4*)
PIC_FLAGS="-PIC"
;;
esac
fi # GCC
fi # PIC_FLAGS
AC_MSG_RESULT([$PIC_FLAGS])
fi
AC_SUBST([PIC_FLAGS])
])# DETECT_PIC_FLAGS
21 changes: 17 additions & 4 deletions src/amuse/community/bhtree/Makefile
Expand Up @@ -29,15 +29,28 @@ CUDA_LIBDIRS ?= -L$(CUDA_TK)/lib -L$(CUDA_TK)/lib64
CUDA_LIBS ?= $(CUDA_LIBDIRS) -lcudart
GPULIBS = $(CUDA_LIBS) $(SAPPORO_LIBS) -lpthread

export CXXFLAGS

all: compile bhtree_worker

python_worker.o: python_worker.c
$(CXX) $(CXXFLAGS) $(PYTHONDEV_CFLAGS) $(SC_FLAGS) $(LDFLAGS) -c -o $@ $<

bhtree_worker_python: python_worker.o
$(MPICXX) $(CXXFLAGS) $(PYTHONDEV_LDFLAGS) $(SC_FLAGS) $(LDFLAGS) python_worker.o $(OBJS) $(CODELIB) -o $@ $(SC_CLIBS)

bhtree_worker_cython: bhtree_worker_cython.so
$(CODE_GENERATOR) --type=cython -m script -x amuse.community.bhtree.interface BHTreeInterface -o $@

bhtree_worker_cython.so: bhtree_worker_cython.o worker_code.h $(CODELIB) $(OBJS)
$(MPICXX) -shared $(CXXFLAGS) $(PYTHONDEV_LDFLAGS) $(SC_FLAGS) $(LDFLAGS) bhtree_worker_cython.o $(OBJS) $(CODELIB) -o $@ $(SC_CLIBS)

bhtree_worker_cython.o: bhtree_worker_cython.c worker_code.h
$(CXX) $(CXXFLAGS) $(SC_FLAGS) $(PYTHONDEV_CFLAGS) -c -o $@ $<

bhtree_worker_cython.pyx: interface.py
$(CODE_GENERATOR) --type=cython -m mpi interface.py BHTreeInterface -o $@

bhtree_worker_cython.c: bhtree_worker_cython.pyx
$(CYTHON) $< -o $@

compile: $(BHTC)

$(BUILDDIR)/Makefile: $(BHTCDIR)/Makefile
Expand All @@ -50,7 +63,7 @@ $(GPU_BUILDDIR)/Makefile: $(BHTCDIR)/Makefile
cp $(BHTCDIR)/Makefile $(GPU_BUILDDIR)/Makefile

$(BHTC): $(BUILDDIR)/Makefile src/*.c src/*.h src/*.C
make -C $(BUILDDIR) all VPATH=../src
make -C $(BUILDDIR) all VPATH=../src
$(CODELIB): $(BUILDDIR)/Makefile src/*.c src/*.h src/*.C
make -C $(BUILDDIR) all VPATH=../src

Expand Down

0 comments on commit c9b23e0

Please sign in to comment.