Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler directives to work with MacOS/Windows #21

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changes
## Version 23.10.1.3
## The following cumulative fixes are in version 23.10.1.3
## Version 23.10.1.4
## The following cumulative fixes are in version 23.10.1.4
- Modify nlopt to avoid issues with LLVM-clang incompatibilities
- Disable OpenMP temporarily to get approved for CRAN
## Version 23.10.1.2.4
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ToxicR
Type: Package
Title: Analyzing Toxicology Dose-Response Data
Version: 24.1.1.4
Version: 23.10.1.4
Date: 2024-11-12
Authors@R:
c(
Expand Down Expand Up @@ -75,7 +75,8 @@ URL: https://github.com/NIEHS/ToxicR
LazyData: true
Imports: Rcpp (>= 1.0.0), ggplot2 (>= 3.3.2), shiny (>= 1.5.0), coda
(>= 0.19-4), scales (>= 1.1.1), forcats, ggridges (>= 0.5.3),
doBy (>= 4.6.11), multcomp (>= 1.4), dplyr (>= 1.0.7), remotes
doBy (>= 4.6.11), multcomp (>= 1.4), dplyr (>= 1.0.7), remotes,
mvtnorm
LinkingTo: Rcpp, RcppEigen, RcppGSL
RoxygenNote: 7.3.2
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,7 @@ fi


if test x"${have_cmake}" == x"no"; then
. src/cmake_install.sh
. src/scripts/cmake_install.sh
if test -z "${CMAKE_BIN}"; then
## also error to end configure here
as_fn_error $? "Could not find 'cmake'." "$LINENO" 5
Expand Down
43 changes: 17 additions & 26 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Configure Script for ToxicR
# Modified 4/27/2022
# Configure Script for ToxicR
# Modified 4/27/2022

AC_INIT([ToxicR], 1.0.1) dnl Package version

Expand All @@ -11,15 +9,21 @@ CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
AC_LANG(C++)
AC_PROG_CPP

#determine the OS
AC_MSG_CHECKING([Is OPENMP avaialble? ])
# Determine the OS
AC_MSG_CHECKING([Is OPENMP available?])
OS_FLAG="$(uname)"
if test x"${OS_FLAG}" == x"Darwin";then
if test x"${OS_FLAG}" == x"Darwin"; then
AC_MSG_RESULT([no])
OPENMP="-DNO_OMP"
OSFLAG="-D__APPLE__"
elif test x"${OS_FLAG}" == x"Linux"; then
AC_MSG_RESULT([yes])
OPENMP="\$(SHLIB_OPENMP_CXXFLAGS)"
OSFLAG=""
else
AC_MSG_RESULT([yes])
OPENMP="\$(SHLIB_OPENMP_CXXFLAGS) "
OPENMP="\$(SHLIB_OPENMP_CXXFLAGS)"
OSFLAG="-D__WIN32"
fi

AC_PATH_PROG([GSL_CONFIG], [gsl-config])
Expand All @@ -35,14 +39,14 @@ else
sudo apt install gsl
To install GSL in Fedora Type:
sudo yum -y install gsl
To iinstall GSL on macOS using homebrew type:
To install GSL on macOS using homebrew type:
brew install gsl
])
fi

## Can we use pkg-config?
AC_PATH_PROG(have_pkg_config, pkg-config, no)
AC_MSG_CHECKING([Is pkg-config avaialble? ])
AC_MSG_CHECKING([Is pkg-config available?])
if test x"${have_pkg_config}" != x"no"; then
AC_MSG_RESULT([yes])
AC_MSG_CHECKING([if pkg-config knows NLopt])
Expand All @@ -58,24 +62,12 @@ if test x"${have_pkg_config}" != x"no"; then
AC_SUBST([NLOPT_LIBS], "${nlopt_libs}")
else
AC_MSG_RESULT([no])
#if it is macOS just try link and use nlopt generically
need_to_build="yes"
need_to_build="yes"
fi
else
AC_MSG_RESULT([no])
#if it is macOS just try link and use nlopt generically
if test x"${OS_FLAG}" == x"Darwin";then
AC_MSG_RESULT([>= 2.6.0])
nlopt_include=""
nlopt_libs="-lnlopt"
AC_SUBST([NLOPT_INCLUDE], "${nlopt_include}")
AC_SUBST([NLOPT_LIBS], "${nlopt_libs}")
else
need_to_build="yes"
fi

need_to_build="yes"
fi

else
AC_MSG_RESULT([no])
need_to_build="yes"
Expand All @@ -85,14 +77,12 @@ fi
if test x"${need_to_build}" != x"no"; then
AC_PATH_PROG(have_cmake, cmake, no)

if test x"${have_cmake}" == x"no"; then
. src/scripts/cmake_config.sh
if test x"${have_cmake}" == x"no"; then
. src/scripts/cmake_install.sh
if test -z "${CMAKE_BIN}"; then
## also error to end configure here
AC_MSG_ERROR([Could not find 'cmake'.])
fi
else
. src/scripts/cmake_install.sh
fi
## 'uname -m' on M1 give x86_64 which is ... not helping
machine=`"${R_HOME}/bin/Rscript" -e 'cat(Sys.info()[["machine"]])'`
Expand All @@ -107,6 +97,7 @@ SUBDIR_SOURCES="$(cd src/ && ls {code_base,polyK}/*.cpp | tr '\n' ' ')"
SRC_SOURCES="$( cd src/ && ls *.cpp | tr '\n' ' ')"

AC_SUBST(OPENMP)
AC_SUBST(OSFLAG)
AC_SUBST(SRC_SOURCES)
AC_SUBST(SUBDIR_SOURCES)
AC_SUBST([NLOPT_CPPFLAGS],["${nlopt_include}"])
Expand Down
4 changes: 2 additions & 2 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG_CXXFLAGS=-I./code_base -I./include @OSFLAG@ @OPENMP@ @NLOPT_CPPFLAGS@ @GSL_CPPFLAGS@ -DR_COMPILATION -DNO_OMP -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) @NLOPT_LIBS@ @GSL_LIBS@ @OPENMP@ -lgfortran
PKG_CXXFLAGS=-I./code_base -I./include @OPENMP@ @NLOPT_CPPFLAGS@ @GSL_CPPFLAGS@ -DR_COMPILATION -DNO_OMP -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) @NLOPT_LIBS@ @GSL_LIBS@ @OPENMP@

# Debug / clear eigen warnings from compilation
#PKG_CXXFLAGS+=-Wno-ignored-attributes -DToxicR_DEBUG
Expand Down
4 changes: 2 additions & 2 deletions src/Makevars.ucrt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG_CXXFLAGS=-I./code_base -I./include @OSFLAG@ $(SHLIB_OPENMP_CXXFLAGS) -I$(R_TOOLS_SOFT)/include/nlopt -I$(R_TOOLS_SOFT)/include/gsl -DR_COMPILATION -ftree-vectorize -Os -DNO_OMP -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) -lgsl -lgslcblas -lnlopt -lgfortran
PKG_CXXFLAGS=-I./code_base -I./include $(SHLIB_OPENMP_CXXFLAGS) -I$(R_TOOLS_SOFT)/include/nlopt -I$(R_TOOLS_SOFT)/include/gsl -DR_COMPILATION -ftree-vectorize -Os -DNO_OMP -DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) -lgsl -lgslcblas -lnlopt
# Debug / clear eigen warnings from compilation
#PKG_CXXFLAGS+=-Wno-ignored-attributes -DToxicR_DEBUG

Expand Down
8 changes: 6 additions & 2 deletions src/include/cBMDstatmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,13 @@ optimizationResult cfindMAX_W_EQUALITY(cBMDModel<LL, PR> *M,
try {
result = opt.optimize(x, minf);
good_opt = true;
#if defined(_WIN32) || defined(__APPLE__)
} catch (nlopt::roundoff_limited &exc) {
good_opt = false;
#else
} catch (nlopt::roundoff_limited2 &exc) {
good_opt = false;
// cout << "Error Round off" << endl;
#endif
} catch (nlopt::forced_stop &exc) {
good_opt = false;
// cout << "Error Forced stop" << endl;
Expand Down Expand Up @@ -609,7 +613,7 @@ optimizationResult cfindMAX_W_BOUND(cBMDModel<LL, PR> *M, Eigen::MatrixXd start,
// flush(file);
good_opt = true;
// opt_iter++;
#ifdef _WIN32 || defined(__APPLE__)
#if defined(_WIN32) || defined(__APPLE__)
} catch (nlopt::roundoff_limited &exc) {
good_opt = false;
DEBUG_LOG(file, "opt_iter= " << opt_iter << ", error: roundoff_limited");
Expand Down
2 changes: 1 addition & 1 deletion src/include/statmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ optimizationResult findMAP(statModel<LL, PR> *M, Eigen::MatrixXd startV,

} // catch

#ifdef _WIN32 || defined(__APPLE__)
#if defined(_WIN32) || defined(__APPLE__)
catch (nlopt::roundoff_limited &exce) {
DEBUG_LOG(file, "opt_iter= " << opt_iter << ", error: roundoff_limited");
// Rcpp::Rcout << "Roundoff_limited nlopt: " << exce.what() <<
Expand Down
Loading