Commit bcf9935e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Make the configure script check whether the FFTW library that was found is a threaded build or not.

parent b3767183
...@@ -589,6 +589,7 @@ AH_VERBATIM([__STDC_FORMAT_MACROS], ...@@ -589,6 +589,7 @@ AH_VERBATIM([__STDC_FORMAT_MACROS],
# Check for FFTW. We test for this in the standard directories by default, # Check for FFTW. We test for this in the standard directories by default,
# and only disable if using --with-fftw=no or --without-fftw. When a value # and only disable if using --with-fftw=no or --without-fftw. When a value
# is given FFTW must be found. # is given FFTW must be found.
# If FFTW is found, we check whether this is the threaded version.
have_fftw="no" have_fftw="no"
AC_ARG_WITH([fftw], AC_ARG_WITH([fftw],
[AS_HELP_STRING([--with-fftw=PATH], [AS_HELP_STRING([--with-fftw=PATH],
...@@ -598,29 +599,60 @@ AC_ARG_WITH([fftw], ...@@ -598,29 +599,60 @@ AC_ARG_WITH([fftw],
[with_fftw="test"] [with_fftw="test"]
) )
if test "x$with_fftw" != "xno"; then if test "x$with_fftw" != "xno"; then
# Was FFTW's location specifically given?
if test "x$with_fftw" != "xyes" -a "x$with_fftw" != "xtest" -a "x$with_fftw" != "x"; then if test "x$with_fftw" != "xyes" -a "x$with_fftw" != "xtest" -a "x$with_fftw" != "x"; then
FFTW_LIBS="-L$with_fftw/lib -lfftw3_threads -lfftw3" FFTW_LIBS="-L$with_fftw/lib -lfftw3"
FFTW_INCS="-I$with_fftw/include" FFTW_INCS="-I$with_fftw/include"
else else
FFTW_LIBS="-lfftw3_threads -lfftw3" FFTW_LIBS="-lfftw3"
FFTW_INCS="" FFTW_INCS=""
fi fi
# FFTW is not specified, so just check if we have it. # FFTW is not specified, so just check if we have it.
if test "x$with_fftw" = "xtest"; then if test "x$with_fftw" = "xtest"; then
AC_CHECK_LIB([fftw3],[fftw_malloc],[have_fftw="yes"],[have_fftw="no"],$FFTW_LIBS) AC_CHECK_LIB([fftw3],[fftw_malloc],[have_fftw="yes"],[have_fftw="no"],$FFTW_LIBS)
if test "x$have_fftw" != "xno"; then if test "x$have_fftw" != "xno"; then
AC_DEFINE([HAVE_FFTW],1,[The FFTW library appears to be present.]) AC_DEFINE([HAVE_FFTW],1,[The FFTW library appears to be present.])
fi fi
# FFTW was specified, check that it was a valid location.
else else
AC_CHECK_LIB([fftw3],[fftw_malloc], AC_CHECK_LIB([fftw3],[fftw_malloc],
AC_DEFINE([HAVE_FFTW],1,[The FFTW library appears to be present.]), AC_DEFINE([HAVE_FFTW],1,[The FFTW library appears to be present.]),
AC_MSG_ERROR(something is wrong with the FFTW library!), $FFTW_LIBS) AC_MSG_ERROR(something is wrong with the FFTW library!), $FFTW_LIBS)
have_fftw="yes" have_fftw="yes"
fi fi
# FFTW was requested not to be used.
if test "$have_fftw" = "no"; then if test "$have_fftw" = "no"; then
FFTW_LIBS="" FFTW_LIBS=""
FFTW_INCS="" FFTW_INCS=""
fi fi
# Now, check whether we have the threaded version of FFTW
if test "x$have_fftw" = "xyes"; then
# Was FFTW's location specifically given?
if test "x$with_fftw" != "xyes" -a "x$with_fftw" != "xtest" -a "x$with_fftw" != "x"; then
FFTW_THREADED_LIBS="-L$with_fftw/lib -lfftw3_threads -lfftw3"
FFTW_THREADED_INCS="-I$with_fftw/include"
else
FFTW_THREADED_LIBS="-lfftw3_threads -lfftw3"
FFTW_THREADED_INCS=""
fi
# Verify that the library is threaded
AC_CHECK_LIB([fftw3],[fftw_init_threads],[have_threaded_fftw="yes"],
[have_threaded_fftw="no"], $FFTW_THREADED_LIBS)
# If found, update things
if test "x$have_threaded_fftw" = "xyes"; then
AC_DEFINE([HAVE_THREADED_FFTW],1,[The threaded FFTW library appears to be present.])
FFTW_LIBS=$FFTW_THREADED_LIBS
FFTW_INCS=$FFTW_THREADED_INCS
have_fftw="yes - threaded"
fi
fi
fi fi
AC_SUBST([FFTW_LIBS]) AC_SUBST([FFTW_LIBS])
AC_SUBST([FFTW_INCS]) AC_SUBST([FFTW_INCS])
......
...@@ -624,11 +624,13 @@ void pm_mesh_init(struct pm_mesh* mesh, const struct gravity_props* props, ...@@ -624,11 +624,13 @@ void pm_mesh_init(struct pm_mesh* mesh, const struct gravity_props* props,
if (2. * mesh->r_cut_max > box_size) if (2. * mesh->r_cut_max > box_size)
error("Mesh too small or r_cut_max too big for this box size"); error("Mesh too small or r_cut_max too big for this box size");
#ifdef HAVE_THREADED_FFTW
/* Initialise the thread-parallel FFTW version */ /* Initialise the thread-parallel FFTW version */
if (N >= 64) { if (N >= 64) {
fftw_init_threads(); fftw_init_threads();
fftw_plan_with_nthreads(nr_threads); fftw_plan_with_nthreads(nr_threads);
} }
#endif
/* Allocate the memory for the combined density and potential array */ /* Allocate the memory for the combined density and potential array */
mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N); mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
...@@ -668,7 +670,9 @@ void pm_mesh_init_no_mesh(struct pm_mesh* mesh, double dim[3]) { ...@@ -668,7 +670,9 @@ void pm_mesh_init_no_mesh(struct pm_mesh* mesh, double dim[3]) {
*/ */
void pm_mesh_clean(struct pm_mesh* mesh) { void pm_mesh_clean(struct pm_mesh* mesh) {
#ifdef HAVE_THREADED_FFTW
fftw_cleanup_threads(); fftw_cleanup_threads();
#endif
if (mesh->potential) free(mesh->potential); if (mesh->potential) free(mesh->potential);
mesh->potential = 0; mesh->potential = 0;
...@@ -702,11 +706,13 @@ void pm_mesh_struct_restore(struct pm_mesh* mesh, FILE* stream) { ...@@ -702,11 +706,13 @@ void pm_mesh_struct_restore(struct pm_mesh* mesh, FILE* stream) {
#ifdef HAVE_FFTW #ifdef HAVE_FFTW
const int N = mesh->N; const int N = mesh->N;
#ifdef HAVE_THREADED_FFTW
/* Initialise the thread-parallel FFTW version */ /* Initialise the thread-parallel FFTW version */
if (N >= 64) { if (N >= 64) {
fftw_init_threads(); fftw_init_threads();
fftw_plan_with_nthreads(mesh->nr_threads); fftw_plan_with_nthreads(mesh->nr_threads);
} }
#endif
/* Allocate the memory for the combined density and potential array */ /* Allocate the memory for the combined density and potential array */
mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N); mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment