diff --git a/c/include/prima/prima_internal.h b/c/include/prima/prima_internal.h new file mode 100644 index 0000000000..c577ada223 --- /dev/null +++ b/c/include/prima/prima_internal.h @@ -0,0 +1,38 @@ +#ifndef PRIMA_INTERNAL_H +#define PRIMA_INTERNAL_H + +#include "prima/prima.h" + +unsigned int get_random_seed(void); + +// Function to check whether the problem matches the algorithm +prima_rc_t prima_check_problem(const prima_problem_t problem, const prima_algorithm_t algorithm); + +// Function to initialize the result +prima_rc_t prima_init_result(prima_result_t *const result, const prima_problem_t problem); + +// Functions implemented in Fortran (*_c.f90) +int cobyla_c(const int m_nlcon, const prima_objcon_t calcfc, const void *data, const int n, double x[], double *const f, double *const cstrv, double nlconstr[], + const int m_ineq, const double Aineq[], const double bineq[], + const int m_eq, const double Aeq[], const double beq[], + const double xl[], const double xu[], + const double f0, const double nlconstr0[], + int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const double ctol, + const prima_callback_t callback, int *const info); + +int bobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, const double xl[], const double xu[], + int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info); + +int newuoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, + int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info); + +int uobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, + int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const prima_callback_t callback, int *const info); + +int lincoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, + double *const cstrv, const int m_ineq, const double Aineq[], const double bineq[], + const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[], + int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const double ctol, + const prima_callback_t callback, int *const info); + +#endif diff --git a/c/prima.c b/c/prima.c index bfa45e02d7..188abe91e5 100644 --- a/c/prima.c +++ b/c/prima.c @@ -1,7 +1,7 @@ // Dedicated to the late Professor M. J. D. Powell FRS (1936--2015). -#include "prima/prima.h" +#include "prima/prima_internal.h" #include #include #include @@ -203,32 +203,6 @@ const char *prima_get_rc_string(const prima_rc_t rc) } } - -// Functions implemented in Fortran (*_c.f90) -int cobyla_c(const int m_nlcon, const prima_objcon_t calcfc, const void *data, const int n, double x[], double *const f, double *const cstrv, double nlconstr[], - const int m_ineq, const double Aineq[], const double bineq[], - const int m_eq, const double Aeq[], const double beq[], - const double xl[], const double xu[], - const double f0, const double nlconstr0[], - int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const double ctol, - const prima_callback_t callback, int *const info); - -int bobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, const double xl[], const double xu[], - int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info); - -int newuoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, - int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info); - -int uobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, - int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const prima_callback_t callback, int *const info); - -int lincoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, - double *const cstrv, const int m_ineq, const double Aineq[], const double bineq[], - const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[], - int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const double ctol, - const prima_callback_t callback, int *const info); - - // The function that does the minimization using a PRIMA solver prima_rc_t prima_minimize(const prima_algorithm_t algorithm, const prima_problem_t problem, const prima_options_t options, prima_result_t *const result) { diff --git a/c/tests/stress.c b/c/tests/stress.c index d66d685046..ccd7f44a3a 100644 --- a/c/tests/stress.c +++ b/c/tests/stress.c @@ -7,7 +7,14 @@ #include // Make PRIMA available -#include "prima/prima.h" +#include "prima/prima_internal.h" + +// Thread-safe version of localtime +#ifdef _WIN32 +#define localtime_safe(a, b) localtime_s(a, b) +#else +#define localtime_safe(a, b) localtime_r(b, a) +#endif #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define N_MAX 2000 @@ -65,8 +72,9 @@ unsigned int get_random_seed(void) { // Set the random seed to year/week char buf[10] = {0}; time_t t = time(NULL); - struct tm *tmp = localtime(&t); - int rc = strftime(buf, 10, "%y%W", tmp); + struct tm timeinfo; + localtime_safe(&timeinfo, &t); + int rc = strftime(buf, 10, "%y%W", &timeinfo); if (!rc) return 42; else @@ -87,7 +95,7 @@ int main(int argc, char * argv[]) printf("Debug = %d\n", debug); unsigned int seed = get_random_seed(); - printf("Random seed = %d\n", seed); + printf("Random seed = %u\n", seed); srand(seed); // Set up the options