Skip to content

Commit 0696502

Browse files
authored
Merge pull request #35 from seamplex/feature/gsl-optional
Feenox can be compied without GSL (but features are reduced A LOT)
2 parents 30fea73 + 371668d commit 0696502

56 files changed

Lines changed: 2227 additions & 825 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.h.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#undef HAVE_ASPRINTF
22
#undef HAVE_CLOCK_GETTIME
33
#undef HAVE_GETRUSAGE
4+
#undef HAVE_GSL
45
#undef HAVE_PETSC
56
#undef HAVE_SLEPC
67
#undef HAVE_SUNDIALS

configure.ac

Lines changed: 101 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,15 @@ AM_CONDITIONAL([INCLUDE_SLEPC], [test "x${have_slepc}" = "xyes"])
313313

314314

315315
######################
316-
# see if we have --enable-download-gsl
316+
# check for GSL (optional)
317+
AC_ARG_WITH([gsl],
318+
[AS_HELP_STRING([--with-gsl],
319+
[use GSL for advanced math features @<:@default=check@:>@])],
320+
[],
321+
[with_gsl=check]
322+
)
323+
324+
have_gsl="no"
317325
gslver=2.8
318326
gsldist=gsl-${gslver}
319327
gslmirror=http://ftpmirror.gnu.org/gsl/${gsldist}.tar.gz
@@ -323,59 +331,92 @@ AC_ARG_ENABLE([download-gsl],
323331
[download_gsl=yes],
324332
[download_gsl=no])
325333

326-
# if gsl directory does not exist, see if we have to uncompress and/or download
327-
AS_IF([test ! -e ${gsldist}],[
328-
AS_IF([test ! -e ${gsldist}.tar.gz],[
329-
AS_IF([test "x$download_gsl" = "xyes"],[
330-
AS_IF([test "x$(which wget)" != "x"],[
331-
AC_MSG_NOTICE([downloading ${gslmirror}])
332-
wget -c ${gslmirror}
334+
AS_IF([test "x${with_gsl}" != "xno"], [
335+
# if gsl directory does not exist, see if we have to uncompress and/or download
336+
AS_IF([test ! -e ${gsldist}],[
337+
AS_IF([test ! -e ${gsldist}.tar.gz],[
338+
AS_IF([test "x$download_gsl" = "xyes"],[
339+
AS_IF([test "x$(which wget)" != "x"],[
340+
AC_MSG_NOTICE([downloading ${gslmirror}])
341+
wget -c ${gslmirror}
342+
],[
343+
AS_IF([test "x${with_gsl}" != "xcheck"], [
344+
AC_MSG_ERROR([file ${gsldist}.tar.gz not found and wget not installed])
345+
])
346+
])
347+
AS_IF([test ! -e ${gsldist}.tar.gz],[
348+
AS_IF([test "x${with_gsl}" != "xcheck"], [
349+
AC_MSG_ERROR([file ${gsldist}.tar.gz could not be downloaded])
350+
])
351+
])
352+
])
353+
])
354+
355+
AS_IF([test -e ${gsldist}.tar.gz],[
356+
AC_MSG_NOTICE([uncompressing ${gsldist}.tar.gz])
357+
tar xzf ${gsldist}.tar.gz
358+
])
359+
])
360+
361+
# if gsl directory exists, see if we have to compile it
362+
AS_IF([test -e ${gsldist}],[
363+
AS_IF([test -e ${gsldist}/.libs/libgsl.a],[
364+
AC_MSG_NOTICE([using already-compiled GSL library ${gsldist}/.libs/libgsl.a])
333365
],[
334-
AC_MSG_ERROR([file ${gsldist}.tar.gz not found and wget not installed])
366+
AC_MSG_NOTICE([configuring ${gsldist}])
367+
cd ${gsldist}
368+
./configure --prefix=${prefix} --host=${host}
369+
AC_MSG_NOTICE([compiling ${gsldist}])
370+
make
371+
cd ..
335372
])
336-
AS_IF([test ! -e ${gsldist}.tar.gz],[
337-
AC_MSG_ERROR([file ${gsldist}.tar.gz could not be downloaded, copy it manually and re-try.])
373+
374+
AC_SUBST([DOWNLOADED_GSL_LIBS], ["../${gsldist}/.libs/libgsl.a ../${gsldist}/cblas/.libs/libgslcblas.a"])
375+
AC_SUBST([DOWNLOADED_GSL_INCLUDES], ["-I ../${gsldist} -I ../../${gsldist}"])
376+
gsl_version="${gslver} (downloaded and statically linked)"
377+
have_gsl="yes"
378+
],[
379+
# traditional test for GSL
380+
# check for GSL & CBLAS
381+
AC_CHECK_HEADER([gsl/gsl_vector.h], [], [
382+
AS_IF([test "x${with_gsl}" != "xcheck"], [
383+
AC_MSG_FAILURE([--with-gsl was given but GSL headers libgsl-dev not found])
384+
])
385+
])
386+
387+
# TODO: the original idea is that
388+
# if we found PETSc, we use whatever BLAS it has, otherwise we use GSL's CBLAS
389+
# but this does not work in Fedora since even though the library flexiblas
390+
# that is used by PETSc does contain cblas_dgemm, it is not found by the linker
391+
#AS_IF([test "x${have_petsc}" != "xyes"],
392+
AC_CHECK_LIB([gslcblas],[cblas_dgemm], [], [
393+
AS_IF([test "x${with_gsl}" != "xcheck"], [
394+
AC_MSG_FAILURE([--with-gsl was given but GSL CBLAS libgsl-dev not found])
395+
])
396+
])
397+
#)
398+
AC_CHECK_LIB([gsl],[gsl_blas_dgemm], [], [
399+
AS_IF([test "x${with_gsl}" != "xcheck"], [
400+
AC_MSG_FAILURE([--with-gsl was given but GSL library libgsl-dev not found])
401+
])
338402
])
403+
404+
# check if we have everything
405+
AS_IF([test "x${ac_cv_lib_gsl_gsl_blas_dgemm}" = "xyes" -a \
406+
"x${ac_cv_header_gsl_gsl_vector_h}" = "xyes"],
407+
[
408+
gsl_version="from system"
409+
have_gsl="yes"
410+
]
411+
)
339412
])
340-
])
341-
342-
AS_IF([test -e ${gsldist}.tar.gz],[
343-
AC_MSG_NOTICE([uncompressing ${gsldist}.tar.gz])
344-
tar xzf ${gsldist}.tar.gz
345-
])
346-
])
347413
348-
# if gsl directory exists, see if we have to compile it
349-
AS_IF([test -e ${gsldist}],[
350-
AS_IF([test -e ${gsldist}/.libs/libgsl.a],[
351-
AC_MSG_NOTICE([using already-compiled GSL library ${gsldist}/.libs/libgsl.a])
352-
],[
353-
AC_MSG_NOTICE([configuring ${gsldist}])
354-
cd ${gsldist}
355-
./configure --prefix=${prefix} --host=${host}
356-
AC_MSG_NOTICE([compiling ${gsldist}])
357-
make
358-
cd ..
359-
])
360-
361-
AC_SUBST([DOWNLOADED_GSL_LIBS], ["../${gsldist}/.libs/libgsl.a ../${gsldist}/cblas/.libs/libgslcblas.a"])
362-
AC_SUBST([DOWNLOADED_GSL_INCLUDES], ["-I ../${gsldist} -I ../../${gsldist}"])
363-
gsl_version="${gslver} (downloaded and statically linked)"
364-
],[
365-
# traditional test for GSL
366-
# check for GSL & CBLAS (required)
367-
AC_CHECK_HEADER([gsl/gsl_vector.h], [], AC_MSG_ERROR([GNU Scientific library headers libgsl-dev not found.
368-
Either install them with your package manager or configure with --enable-download-gsl]))
369-
370-
# TODO: the original idea is that
371-
# if we found PETSc, we use whatever BLAS it has, otherwise we use GSL's CBLAS
372-
# but this does not work in Fedora since even though the library flexiblas
373-
# that is used by PETSc does contain cblas_dgemm, it is not found by the linker
374-
#AS_IF([test "x${have_petsc}" != "xyes"],
375-
AC_CHECK_LIB([gslcblas],[cblas_dgemm], [], AC_MSG_ERROR([GNU Scientific library CBLAS libgsl-dev not found]))
376-
#)
377-
AC_CHECK_LIB([gsl],[gsl_blas_dgemm], [], AC_MSG_ERROR([GNU Scientific library libgsl-dev not found]))
378-
gsl_version="from system"
414+
# Define HAVE_GSL if we found it
415+
AS_IF([test "x${have_gsl}" = "xyes"],
416+
[
417+
AC_DEFINE([HAVE_GSL], [1], [GSL is available])
418+
]
419+
)
379420
])
380421
381422
@@ -424,22 +465,32 @@ AS_IF([test "x${enable_fee2ccx}" = "xyes"] , [
424465

425466

426467
AS_BOX([Summary of dependencies])
427-
AS_ECHO( [" GNU Scientific Library ${gsl_version}"])
468+
AS_ECHO_N( [" GNU Scientific Library ${have_gsl}"])
469+
AS_IF([test "x${have_gsl}" = "xyes"],
470+
AS_ECHO([" ${gsl_version}"]),
471+
AS_ECHO
472+
)
473+
428474
# AS_ECHO( [" Readline ${have_readline}"])
475+
429476
AS_ECHO( [" SUNDIALS ${have_sundials}"])
477+
430478
AS_ECHO_N([" PETSc ${have_petsc}"])
431479
AS_IF([test "x${have_petsc}" = "xyes"],
432480
AS_ECHO([" ${PETSC_DIR} ${PETSC_ARCH}"]),
433481
AS_ECHO
434482
)
483+
435484
AS_ECHO_N([" SLEPc ${have_slepc}"])
436485
AS_IF([test "x${have_slepc}" = "xyes"],
437486
AS_ECHO([" ${SLEPC_DIR}"]),
438487
AS_ECHO
439488
)
489+
440490
AS_ECHO( [" Compile fee2ccx ${enable_fee2ccx}"])
441491
AS_ECHO( [" Compiler ${compiler_show}"])
442492
AS_ECHO( [" Compiler flags ${CFLAGS}"])
493+
AS_ECHO( [" Compiler version ${compiler_version}"])
443494
# AS_ECHO( [" Linker flags ${LDFLAGS}"])
444495

445496
AC_OUTPUT

src/feenox.h

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,17 @@
4141
#endif
4242

4343
// for inlining as much as possible GSL
44+
#ifdef HAVE_GSL
4445
#define HAVE_INLINE
4546
#define GSL_RANGE_CHECK_OFF
47+
#endif
4648

4749
#ifndef sunrealtype
4850
#define sunrealtype realtype
4951
#endif
5052

51-
// we need all the includes here so they all follow the inline directive above
52-
#include <gsl/gsl_blas.h>
53-
#include <gsl/gsl_errno.h>
54-
#include <gsl/gsl_deriv.h>
55-
#include <gsl/gsl_heapsort.h>
56-
#include <gsl/gsl_integration.h>
57-
#include <gsl/gsl_interp.h>
58-
#include <gsl/gsl_linalg.h>
59-
#include <gsl/gsl_math.h>
60-
#include <gsl/gsl_matrix.h>
61-
#include <gsl/gsl_min.h>
62-
#include <gsl/gsl_multifit_nlinear.h>
63-
#include <gsl/gsl_multimin.h>
64-
#include <gsl/gsl_multiroots.h>
65-
#include <gsl/gsl_qrng.h>
66-
#include <gsl/gsl_randist.h>
67-
#include <gsl/gsl_rng.h>
68-
#include <gsl/gsl_roots.h>
69-
#include <gsl/gsl_spline.h>
70-
#include <gsl/gsl_sf.h>
71-
#include <gsl/gsl_statistics.h>
72-
#include <gsl/gsl_sort_double.h>
73-
#include <gsl/gsl_sort_vector_double.h>
74-
#include <gsl/gsl_vector.h>
75-
#include <gsl/gsl_version.h>
53+
// Include linear algebra layer (GSL or compatibility implementation)
54+
#include "math/linalg.h"
7655

7756
#ifdef HAVE_SUNDIALS
7857
#include <ida/ida.h>
@@ -162,7 +141,11 @@ extern "C++" {
162141
// reasonable defaults
163142
#define DEFAULT_DT 1.0/16.0
164143
#define DEFAULT_DAE_RTOL 1e-6
144+
#ifdef HAVE_GSL
165145
#define DEFAULT_RANDOM_METHOD gsl_rng_mt19937
146+
#else
147+
#define DEFAULT_RANDOM_METHOD NULL
148+
#endif
166149

167150
#define DEFAULT_PRINT_FORMAT "%g"
168151
#define DEFAULT_PRINT_SEPARATOR "\t"
@@ -187,7 +170,11 @@ extern "C++" {
187170
#define DEFAULT_FIT_GTOL 1e-8
188171
#define DEFAULT_FIT_FTOL 0.0
189172

173+
#ifdef HAVE_GSL
190174
#define DEFAULT_SOLVE_METHOD gsl_multiroot_fsolver_dnewton
175+
#else
176+
#define DEFAULT_SOLVE_METHOD NULL
177+
#endif
191178
#define DEFAULT_SOLVE_EPSREL 0 // zero means do not look for deltas in derivatives
192179
#define DEFAULT_SOLVE_EPSABS 1e-6
193180
#define DEFAULT_SOLVE_MAX_ITER 128
@@ -231,7 +218,9 @@ extern "C++" {
231218
#define ELEMENT_TYPE_PRISM15 18
232219
#define NUMBER_ELEMENT_TYPE 19
233220

221+
#ifndef M_SQRT5
234222
#define M_SQRT5 2.23606797749978969640917366873127623544061835961152572427089
223+
#endif
235224

236225
#define FEENOX_SOLUTION_NOT_GRADIENT 0
237226
#define FEENOX_SOLUTION_GRADIENT 1
@@ -1430,8 +1419,8 @@ struct mesh_write_t {
14301419

14311420
int (*write_header)(mesh_t *mesh, FILE *file);
14321421
int (*write_mesh)(mesh_t *mesh, FILE *file, int no_physical_names);
1433-
int (*write_data)(mesh_write_t *this, mesh_write_dist_t *dist);
1434-
int (*write_footer)(mesh_write_t *this);
1422+
int (*write_data)(mesh_write_t *mesh, mesh_write_dist_t *dist);
1423+
int (*write_footer)(mesh_write_t *mesh);
14351424

14361425
// these two are to know if we have to change the type in VTK
14371426
int point_init;
@@ -1538,7 +1527,11 @@ struct solve_t {
15381527
int max_iter;
15391528
int verbose;
15401529

1530+
#ifdef HAVE_GSL
15411531
const gsl_multiroot_fsolver_type *type;
1532+
#else
1533+
const void *type;
1534+
#endif
15421535

15431536
solve_t *next;
15441537
};
@@ -2130,7 +2123,7 @@ extern int feenox_read_arguments(char *string, int n_arguments, char ***arg, siz
21302123

21312124

21322125
// file.c
2133-
char *feenox_evaluate_string(const char *restrict format, int n_args, expr_t *arg);
2126+
char *feenox_evaluate_string(const char *restrict fmt, int n_args, expr_t *arg);
21342127
extern int feenox_instruction_file(void *arg);
21352128
FILE *feenox_fopen(const char *filepath, const char *mode);
21362129
extern int feenox_instruction_file_open(void *arg);
@@ -2303,7 +2296,7 @@ extern double feenox_gsl_function(double x, void *params);
23032296
// mesh.c
23042297
extern int feenox_instruction_mesh_read(void *arg);
23052298
extern int feenox_mesh_create_nodes_argument(mesh_t *);
2306-
extern int feenox_mesh_create_index2tag(mesh_t *this);
2299+
extern int feenox_mesh_create_index2tag(mesh_t *mesh);
23072300
extern int feenox_mesh_free(mesh_t *);
23082301

23092302
extern int feenox_mesh_read_vtk(mesh_t *);
@@ -2427,13 +2420,13 @@ extern int feenox_mesh_write_header_vtk(mesh_t *mesh, FILE *file);
24272420
extern int feenox_mesh_write_vtk_cells(mesh_t *mesh, FILE * file, int with_size);
24282421
extern int feenox_mesh_write_vtk_types(mesh_t *mesh, FILE * file);
24292422
extern int feenox_mesh_write_mesh_vtk(mesh_t *mesh, FILE *file, int dummy);
2430-
extern int feenox_mesh_write_data_vtk(mesh_write_t *this, mesh_write_dist_t *dist);
2423+
extern int feenox_mesh_write_data_vtk(mesh_write_t *mesh, mesh_write_dist_t *dist);
24312424

24322425
// vtu.c
24332426
extern int feenox_mesh_write_header_vtu(mesh_t *mesh, FILE *file);
24342427
extern int feenox_mesh_write_mesh_vtu(mesh_t *, FILE *file, int dummy);
2435-
extern int feenox_mesh_write_data_vtu(mesh_write_t *this, mesh_write_dist_t *dist);
2436-
extern int feenox_mesh_write_footer_vtu(mesh_write_t *this);
2428+
extern int feenox_mesh_write_data_vtu(mesh_write_t *mesh, mesh_write_dist_t *dist);
2429+
extern int feenox_mesh_write_footer_vtu(mesh_write_t *mesh);
24372430

24382431
// neighbors.c
24392432
extern element_t *feenox_mesh_find_element_volumetric_neighbor(element_t *e) __attribute__((noinline));

0 commit comments

Comments
 (0)