Closed billdenney closed 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.)
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.
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.
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.)
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.
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.
You will have to install the c version of n1qn1 for nlmixr
devtools::install_github("nlmixrdevelopment/n1qn1c")
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.
I havn't submitted because it breaks the CRAN nlmixr...
Try:
CXX14=$(BINPREF)g++ $(M_ARCH)
CXX14STD=-std=c++1y
CXX14FLAGS=-O0 -Wall
The variable tracking is part of the optimization. I'm unsure if -O0
is allowed in CRAN directly or not.
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
FYI, I just asked on r-package-devel.
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.
Just compiled on my windows machine for i386
with this change.
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
I think that this one is good now. Thanks for the help (on a holiday, no less)!
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
Related to #170.
I'm trying to install the current version of the
pruneBranch
with:Near the beginning of installation, I get the following error. I don't immediately know how to debug in more detail.
A bit farther down, I get:
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.