diff --git a/include/misc/optim_options.hpp b/include/misc/optim_options.hpp index 50b4bf8..7f1fe62 100644 --- a/include/misc/optim_options.hpp +++ b/include/misc/optim_options.hpp @@ -41,12 +41,6 @@ // -#ifdef _MSC_VER - #error OptimLib: MSVC is not supported -#endif - -// - #if defined(_OPENMP) && !defined(OPTIM_DONT_USE_OPENMP) #undef OPTIM_USE_OPENMP #define OPTIM_USE_OPENMP @@ -76,15 +70,20 @@ #endif // floating point number type - +#ifndef FLOAT_TYPE_KEY + #define FLOAT_TYPE_KEY 0 +#endif +#ifndef DOUBLE_TYPE_KEY + #define DOUBLE_TYPE_KEY 1 +#endif #ifndef OPTIM_FPN_TYPE - #define OPTIM_FPN_TYPE double + #define OPTIM_FPN_TYPE DOUBLE_TYPE_KEY #endif -#if OPTIM_FPN_TYPE == float +#if OPTIM_FPN_TYPE == FLOAT_TYPE_KEY #undef OPTIM_FPN_SMALL_NUMBER #define OPTIM_FPN_SMALL_NUMBER fp_t(1e-05) -#elif OPTIM_FPN_TYPE == double +#elif OPTIM_FPN_TYPE == DOUBLE_TYPE_KEY #undef OPTIM_FPN_SMALL_NUMBER #define OPTIM_FPN_SMALL_NUMBER fp_t(1e-08) #else @@ -96,12 +95,22 @@ namespace optim { using uint_t = unsigned int; - using fp_t = OPTIM_FPN_TYPE; +#if OPTIM_FPN_TYPE == FLOAT_TYPE_KEY + using fp_t = float; +#else + using fp_t = double; +#endif using rand_engine_t = std::mt19937_64; static const double eps_dbl = std::numeric_limits::epsilon(); static const double inf = std::numeric_limits::infinity(); + +#ifdef _MSC_VER + using ompint_t = int64_t; +#else + using ompint_t = size_t; +#endif } // diff --git a/src/unconstrained/de.cpp b/src/unconstrained/de.cpp index 083e6b4..db57541 100644 --- a/src/unconstrained/de.cpp +++ b/src/unconstrained/de.cpp @@ -117,7 +117,7 @@ optim::internal::de_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -164,7 +164,7 @@ optim::internal::de_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -258,7 +258,7 @@ optim::internal::de_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { X_next.row(i) = inv_transform(X_next.row(i), bounds_type, lower_bounds, upper_bounds); } } diff --git a/src/unconstrained/de_prmm.cpp b/src/unconstrained/de_prmm.cpp index 70e3457..2c040ec 100644 --- a/src/unconstrained/de_prmm.cpp +++ b/src/unconstrained/de_prmm.cpp @@ -134,7 +134,7 @@ optim::internal::de_prmm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -195,7 +195,7 @@ optim::internal::de_prmm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) #endif - for (size_t j = 0; j < n_pop_temp; ++j) { + for (ompint_t j = 0; j < n_pop_temp; ++j) { if (objfn_vals(j) < objfn_vals(j + n_pop_temp)) { X_reset.row(j) = X_next.row(j); objfn_vals_reset(j) = objfn_vals(j); @@ -223,7 +223,7 @@ optim::internal::de_prmm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_pars) #endif - for (size_t i = 0; i < n_pop - n_pop_best; ++i) { + for (ompint_t i = 0; i < n_pop - n_pop_best; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -306,7 +306,7 @@ optim::internal::de_prmm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_pars) #endif - for (size_t i = n_pop - n_pop_best; i < n_pop; ++i) { + for (ompint_t i = n_pop - n_pop_best; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -417,7 +417,7 @@ optim::internal::de_prmm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { X_next.row(i) = inv_transform(X_next.row(i), bounds_type, lower_bounds, upper_bounds); } } diff --git a/src/unconstrained/nm.cpp b/src/unconstrained/nm.cpp index 00a22c6..46fffe6 100644 --- a/src/unconstrained/nm.cpp +++ b/src/unconstrained/nm.cpp @@ -251,7 +251,7 @@ optim::internal::nm_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) #endif - for (size_t i = 1; i < n_vals + 1; i++) { + for (ompint_t i = 1; i < n_vals + 1; i++) { simplex_fn_vals(i) = box_objfn( BMO_MATOPS_TRANSPOSE(simplex_points.row(i)), nullptr, opt_data); } } diff --git a/src/unconstrained/pso.cpp b/src/unconstrained/pso.cpp index 5361f03..57121c6 100644 --- a/src/unconstrained/pso.cpp +++ b/src/unconstrained/pso.cpp @@ -133,7 +133,7 @@ optim::internal::pso_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -202,7 +202,7 @@ optim::internal::pso_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec_1,rand_vec_2) #endif - for (size_t i=0; i < n_pop; ++i) { + for (ompint_t i=0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -270,7 +270,7 @@ optim::internal::pso_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { P.row(i) = inv_transform(P.row(i), bounds_type, lower_bounds, upper_bounds); } } diff --git a/src/unconstrained/pso_dv.cpp b/src/unconstrained/pso_dv.cpp index 9b44239..7ef0b79 100644 --- a/src/unconstrained/pso_dv.cpp +++ b/src/unconstrained/pso_dv.cpp @@ -125,7 +125,7 @@ optim::internal::pso_dv_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP @@ -178,7 +178,7 @@ optim::internal::pso_dv_impl( #ifdef OPTIM_USE_OPENMP #pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_CR) #endif - for (size_t i = 0; i < n_pop; ++i) { + for (ompint_t i = 0; i < n_pop; ++i) { size_t thread_num = 0; #ifdef OPTIM_USE_OPENMP