Skip to content

Commit

Permalink
Make GSL support for random number generation optionnal
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sevin committed Jan 18, 2024
1 parent 64b229c commit c401b40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/CommandLineInterface/CLIcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ static errno_t runCLI_initialize()
PRINT_ERROR("seteuid error");
}

#ifdef USE_GSL
// Initialize random-number generator
//
const gsl_rng_type *rndgenType;
Expand All @@ -358,6 +359,7 @@ static errno_t runCLI_initialize()
rndgenType = gsl_rng_rand; // not as good but ~10x faster fast
data.rndgen = gsl_rng_alloc(rndgenType);
gsl_rng_set(data.rndgen, time(NULL));
#endif

// warm up
//for(i=0; i<10; i++)
Expand Down Expand Up @@ -1057,8 +1059,11 @@ static void runCLI_free()

#endif
// free(data.cmd);

#ifdef USE_GSL
DEBUG_TRACEPOINT("free data.rndgen");
gsl_rng_free(data.rndgen);
#endif
}

int user_function()
Expand Down
7 changes: 7 additions & 0 deletions src/CommandLineInterface/CLIcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ typedef int errno_t;

#include <errno.h>
#include <fftw3.h>
#ifdef USE_GSL
#include <gsl/gsl_rng.h> // for random numbers
#else
typedef struct
{
int dummy;
} gsl_rng;
#endif
#include <sched.h>
#include <semaphore.h>
#include <signal.h>
Expand Down
6 changes: 5 additions & 1 deletion src/CommandLineInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ option(python_module "Compile Python Wrappers" OFF)
project(CLIcore C)

find_package(PkgConfig REQUIRED)
find_package(GSL QUIET REQUIRED)
pkg_check_modules(FFTW REQUIRED fftw3)
pkg_check_modules(FFTWF REQUIRED fftw3f)
pkg_check_modules(NCURSES REQUIRED ncurses)
find_package(OpenMP)
find_package(GSL)

pkg_check_modules(HWLOC hwloc)

Expand Down Expand Up @@ -123,6 +123,10 @@ if(${CFITSIO_FOUND})
target_include_directories(CLIcore PUBLIC ${CFITSIO_INCLUDE_DIRS})
endif()

if(${GSL_FOUND})
target_compile_definitions(CLIcore PUBLIC USE_GSL=1)
endif()

target_include_directories(CLIcore
PUBLIC ${GSL_INCLUDE_DIRS}
${FFTW_INCLUDE_DIRS}
Expand Down

0 comments on commit c401b40

Please sign in to comment.