nlmixrdevelopment / RxODE

RxODE is an R package that facilitates easy simulations in R
https://nlmixrdevelopment.github.io/RxODE/
GNU General Public License v3.0
54 stars 14 forks source link

pruneBranch Installation Fails on Windows #278

Closed billdenney closed 4 years ago

billdenney commented 4 years ago

Related to #170.

I'm trying to install the current version of the pruneBranch with:

remotes::install_github(repo="nlmixrdevelopment/RxODE", ref="pruneBranch")

Near the beginning of installation, I get the following error. I don't immediately know how to debug in more detail.

* installing *source* package 'RxODE' ...
** using staged installation

gcc.exe: error: 2>&1: Invalid argument
G__~1.EXE: error: 2>&1: Invalid argument
--------[[begin src/Makevars.win]]--------

A bit farther down, I get:

--------[[end src/Makevars.win]]--------
** libs

*** arch - i386
"C:/rtools40/mingw32/bin/"gcc  -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG  -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/dparser/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/PreciseSums/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/RcppEigen/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/sitmo/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/StanHeaders/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/BH/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/checkmate/include'     -D_isRxODE_   -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c lincmt.c -o lincmt.o

cc1.exe: out of memory allocating 65536 bytes
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/i386/Makeconf:222: lincmt.o] Error 1
ERROR: compilation failed for package 'RxODE'
* removing 'C:/Users/Bill Denney/Documents/R/win-library/4.0/RxODE'
* restoring previous 'C:/Users/Bill Denney/Documents/R/win-library/4.0/RxODE'
Error: Failed to install 'RxODE' from GitHub:
  (converted from warning) installation of package ‘C:/Users/BILLDE~1/AppData/Local/Temp/RtmpOSNx46/file24347bce137a/RxODE_0.9.2-0.tar.gz’ had non-zero exit status

I still have plenty of memory available.

Looking at the instructions for setting up stan, I that setting compiler flags are no longer required ("Finally, on Windows it should not currently be necessary to specify any compiler flags at all, so if you are having problems, you can remove your Makevars.win file entirely." from the end of the section at https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#checking-the-c-toolchain).

I'm working on this now and will update if I find a solution. If you have any hints, I'd appreciate them.

billdenney commented 4 years ago

Watching memory usage during compilation, I see that it holds steady around 450 MB, and then I can briefly see a spike up to ~1.5 GB immediately before it errors out. (The system has 16 GB on it, and with the rate of increase, it could have possibly consumed all available RAM before the error.)

mattfidler commented 4 years ago

Hi @billdenney,

Could you post the value of your ~/.R/Makevars.win

I believe your system is trying to optimize a program with thousands of variables. In linux it rolls-back, in windows I guess it consumes all your memory then fails.

I believe you used to be able to compile this on windows, so I am unsure what happened differently.

billdenney commented 4 years ago

I've tried 3 different ~/.R/Makevars.win variants:

Variant 1 (which worked previously):

CXX14=$(BINPREF)g++ $(M_ARCH)
CXX14STD=-std=c++1y
CXX14FLAGS=-O2 -Wall

Variant 2 (suggested by the current Stan page on setup):

CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2

Variant 3 was all commented out (also as suggested by Stan).

I have also tried reinstalling Rtools in case there was an update or issue there.

billdenney commented 4 years ago

Compiling on Linux, the same cc1 process for lincmt.c is taking about 3.5GB at the moment, so I think you're correct about trying to optimize across many variables. That seems odd to me for what I would have assumed is relatively simple code. Is there a way that could be simplified?

As a guess, on Windows, it was the 32-bit compilation that failed. Perhaps the issue is that 32-bit cc1 on Windows cannot access >2 or 3 GB? (Those limits are sometimes the case for 32-bit operations on Windows.)

billdenney commented 4 years ago

It does seem related to 32-bit memory limits. I just ran:

Sys.setenv(BINPREF="c:/rtools40/mingw64/bin/")
remotes::install_github(repo="nlmixrdevelopment/RxODE", ref="pruneBranch")

And, as far as I can tell, BINPREF says to use this binary to compile rather than the automatically-detected copy. With that, compilation made it past lincmt.o.

Using BINPREF doesn't seem like the correct solution long-term. I'm not sure that I'm even getting a real 32-bit binary. Failure to compile due to exceeding 32-bit memory limits seems like something that won't make it to CRAN.

mattfidler commented 4 years ago

This is likely true; You are not getting a real 32 bit binary either. You are also right it will likely not pass on CRAN.

I have a possible work-around but it takes a bit of setup.

mattfidler commented 4 years ago

You will have to install the c version of n1qn1 for nlmixr

devtools::install_github("nlmixrdevelopment/n1qn1c")
billdenney commented 4 years ago

All of the compilation finished successfully on my windows machine, but then at the end, I got the following error (not a surprise):

** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for 'RxODE' in library.dynam(lib, package, package.lib):
 DLL 'RxODE' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted

I would guess that if we could use the 64-bit cc1 with the -m32 option, it would likely work correctly-- but I don't have a clue how to make that work on CRAN.

mattfidler commented 4 years ago

I havn't submitted because it breaks the CRAN nlmixr...

mattfidler commented 4 years ago

Try:

CXX14=$(BINPREF)g++ $(M_ARCH)
CXX14STD=-std=c++1y
CXX14FLAGS=-O0 -Wall
mattfidler commented 4 years ago

The variable tracking is part of the optimization. I'm unsure if -O0 is allowed in CRAN directly or not.

billdenney commented 4 years ago

When I tried the Makevars.win file suggested above, I still see -O2 on the command line, and I get the same error.

--------[[end src/Makevars.win]]--------
** libs

*** arch - i386
"C:/rtools40/mingw32/bin/"gcc  -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG  -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/dparser/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/PreciseSums/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/RcppEigen/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/sitmo/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/StanHeaders/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/BH/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/checkmate/include'     -D_isRxODE_   -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c lincmt.c -o lincmt.o
billdenney commented 4 years ago

FYI, I just asked on r-package-devel.

mattfidler commented 4 years ago

I'm unsure if it works, but I think I turned on -O0 for lincmt.c and lincmtB.cpp

This is what is probably eating the memory.

mattfidler commented 4 years ago

Just compiled on my windows machine for i386 with this change.

billdenney commented 4 years ago

It worked!

Looking at the compilation, it appears to have been applied more broadly, or maybe it was always using -O0 and I'm just noticing the fact. it got past the first compilation error (and so I think it will work for me, too).

Note the -O0 for rxInv.cpp here.

"C:/rtools40/mingw32/bin/"g++  -std=c++1y -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG  -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/dparser/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/PreciseSums/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/RcppEigen/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/sitmo/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/StanHeaders/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/BH/include' -I'C:/Users/Bill Denney/Documents/R/win-library/4.0/checkmate/include'     -fopenmp -D_isRxODE_ -DBOOST_DISABLE_ASSERTS -I"`"C:/PROGRA~1/R/R-40~1.2/bin/i386/Rscript" -e 'cat(file.path(find.package("BH"),"include"))'`" -I"`"C:/PROGRA~1/R/R-40~1.2/bin/i386/Rscript" -e 'cat(file.path(find.package("RcppEigen"),"include"))'`" -I"`"C:/PROGRA~1/R/R-40~1.2/bin/i386/Rscript" -e 'cat(file.path(find.package("StanHeaders"),"include"))'`" -I"`"C:/PROGRA~1/R/R-40~1.2/bin/i386/Rscript" -e 'cat(file.path(find.package("Rcpp"),"include"))'`" -I"`"C:/PROGRA~1/R/R-40~1.2/bin/i386/Rscript" -e 'cat(file.path(find.package("RcppArmadillo"),"include"))'`"   -O0 -Wall -c rxInv.cpp -o rxInv.o
billdenney commented 4 years ago

I think that this one is good now. Thanks for the help (on a holiday, no less)!

mattfidler commented 4 years ago

That comes from the makefile:

CXX14=$(BINPREF)g++ $(M_ARCH)
CXX14STD=-std=c++1y
CXX14FLAGS=-O0 -Wall

You can delete this and see if it works without, if you have time