Hey everyone (well, Daniel mostly I guess),So I'm finally getting up to speed with the new CmdStan structure and have hit two snags so far.
First, it seems like the dependencies are broken with the new CmdStan setup. In particular, if you change a source file in stan (proper) the unit tests in CmdStan don't rebuild.
Second, stan and CmdStan build their object files in different places. This means that when running unit tests in both it's necessary to, e.g., build the parser twice. Not a major issue, but annoying all the same.
Anyway, just wanted to point these issues out. I'd take a crack at fixing them, but my make-foo is weak. Glad to see the refactoring is happening!
--Cheers,Marcus
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Fri, Apr 11, 2014 at 2:06 PM, Marcus Brubaker <marcus.a...@gmail.com> wrote:
Hey everyone (well, Daniel mostly I guess),So I'm finally getting up to speed with the new CmdStan structure and have hit two snags so far.
First, it seems like the dependencies are broken with the new CmdStan setup. In particular, if you change a source file in stan (proper) the unit tests in CmdStan don't rebuild.Yeah -- I noticed that recently. Sorry I haven't gotten it fixed yet, but I'll try to get it up and working soon. I think it also happens in Stan proper. Damn make! But really, it's my fault. I must have done something and not checked hard enough.
Second, stan and CmdStan build their object files in different places. This means that when running unit tests in both it's necessary to, e.g., build the parser twice. Not a major issue, but annoying all the same.Good point. I figured if you were using CmdStan, you'll only build the parser from there. If you're working in Stan, you'll build the parser there. I don't think there's much to do about this one unless we find some way to copy over the one built in Stan.
Anyway, just wanted to point these issues out. I'd take a crack at fixing them, but my make-foo is weak. Glad to see the refactoring is happening!If you find anything else, please let me know. Like I said, I only stumbled on the broken make recently (this week) and if I had known earlier, I would have spent some time earlier fixing it. There isn't a testing framework for make itself, is there?
I haven't tested on Linux and I think we need to explicitly link to pthreads there. That looks to be the issue. If you don't beat me to it, I will fix it tomorrow or Monday.
Cheers,
Marcus
CMake Error at src/test/CMakeLists.txt:13 (add_subdirectory):
The source directory
/opt/stan/src/test/test-models
does not contain a CMakeLists.txt file.
-- Configuring incomplete, errors occurred!
See also "/opt/stan/build/CMakeFiles/CMakeOutput.log".
See also "/opt/stan/build/CMakeFiles/CMakeError.log".
Linking CXX executable unit_agrad_dot_product_test
1 error generated.
make[2]: *** [src/test/CMakeFiles/unit_common_command_init_test.dir/unit/common/command_init_test.cpp.o] Error 1
make[1]: *** [src/test/CMakeFiles/unit_common_command_init_test.dir/all] Error 2
[ 14%] Built target unit_agrad_dot_product_test
make: *** [all] Error 2
After a git pull, I gotCMake Error at src/test/CMakeLists.txt:13 (add_subdirectory):
The source directory
/opt/stan/src/test/test-models
does not contain a CMakeLists.txt file.
-- Configuring incomplete, errors occurred!
See also "/opt/stan/build/CMakeFiles/CMakeOutput.log".
See also "/opt/stan/build/CMakeFiles/CMakeError.log".
but once I commented out that line, it ran until
Linking CXX executable unit_agrad_dot_product_test
1 error generated.
make[2]: *** [src/test/CMakeFiles/unit_common_command_init_test.dir/unit/common/command_init_test.cpp.o] Error 1
make[1]: *** [src/test/CMakeFiles/unit_common_command_init_test.dir/all] Error 2
[ 14%] Built target unit_agrad_dot_product_test
make: *** [all] Error 2
This is a lot more progress than I would have expected in 2 days.
One question: We have a functioning cluster at Columbia with thousands of cores so the optimal way to use it is to call make individually on every single micro target, rather than something like make test-all. That is possible with static makefiles, although it is a bit tedious to write a shell script to do it. Do you have an idea about how we could do something like that with cmake?
Ben
On Sunday, April 13, 2014 4:15:41 PM UTC-4, Marcus Brubaker wrote:Ok, I think I've fixed the pthreads issue. I've also started a little on building Stan models, but haven't had too much time to work on it today so the tests which rely on compiled models still don't build yet. I've also added some of the custom compile flags and split things out a bit better.Cheers,Marcus
--
Also, I can get a CMake-based build system about 90% of the way there, but I will need help from people for that remaining 10%. Specifically, there are a few things I won't be able to test myself:- Building on Windows- Building on Linux for Windows using mingw and unit testing with Wine- Jenkins integration
x86_64-w64-mingw32-gcc: error: unrecognized command line option
‘-rdynamic’
I've pushed a quick change which should fix this. From the base stan source directory run:mkdir build-mingw32 ; cd build-mingw32 ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw32-linux.cmake ..On my linux box it now fails with an error about "string table overflow" when compiling the parser but I'll look into that later when I have a bit more time.
Ah, ok, I've now fixed this. It is less than elegant but I haven't had time to think about how to do it better. In short, in src/stan/gm/CMakeLists.txt I have code which was turning optimization off to speed up compilation since we generally don't care about how fast the parser is. (I'm doing the same thing for all the units tests as well.) I've made it conditional on using mingw such that if we're not using mingw, we always turn optimization off (to speed up compilation) or if mingw is in use, we always turn it on to work around that bug.We could get rid of all of this and just adjust the compiler options (CMAKE_CXX_FLAGS*) by hand for the entire project or use different build types (e.g., debug vs release) if that is preferred. It's certainly more elegant. Thoughts?
make CC=x86_64-w64-mingw32-g++ AR=x86_64-w64-mingw32-ar O_STANC=3 src/test/unitgoodrich@CYBERPOWERPC:/opt/stan$ mkdir build-mingw32 ; cd build-mingw32 ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw32-linux.cmake ..
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Performing Test HAVE_PIPE_FLAG
-- Performing Test HAVE_PIPE_FLAG - Success
-- Performing Test HAVE_SYNTAXONLY_FLAG
-- Performing Test HAVE_SYNTAXONLY_FLAG - Failed
-- Found Wine executable at: /usr/bin/wine
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/stan/build-mingw32
goodrich@CYBERPOWERPC:/opt/stan/build-mingw32$ make -j1
Scanning dependencies of target stan
[ 0%] Building CXX object CMakeFiles/stan.dir/src/stan/agrad/rev/var_stack.cpp.obj
Linking CXX static library libstan.a
[ 0%] Built target stan
Scanning dependencies of target print
[ 0%] Building CXX object CMakeFiles/print.dir/src/stan/command/print.cpp.obj
Linking CXX executable print.exe
[ 0%] Built target print
Scanning dependencies of target stanc
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/ast_def.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/expression_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/whitespace_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/program_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/statement_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/var_decls_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/term_grammar_inst.cpp.obj
[ 0%] Building CXX object src/stan/gm/CMakeFiles/stanc.dir/grammars/statement_2_grammar_inst.cpp.obj
Linking CXX static library libstanc.a
[ 0%] Built target stanc
Scanning dependencies of target stanc-bin
[ 0%] Building CXX object CMakeFiles/stanc-bin.dir/src/stan/command/stanc.cpp.obj
Linking CXX executable stanc.exe
[ 0%] Built target stanc-bin
Scanning dependencies of target gtest
[ 0%] Building CXX object lib/gtest_1.7.0/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
[ 0%] Building CXX object lib/gtest_1.7.0/CMakeFiles/gtest.dir/src/gtest_main.cc.obj
Linking CXX static library libgtest.a
[ 0%] Built target gtest
Scanning dependencies of target Test_SyntaxOnly_Models
[ 0%] Generating function_signatures_student_t_4.cpp
wine: '/home/goodrich/.wine' is a 64-bit installation, it cannot be used with a 32-bit wineserver.goodrich@CYBERPOWERPC:/opt/stan/build-mingw32$ file stanc.exe
stanc.exe: PE32+ executable (console) x86-64, for MS Windows
The problem seems to be that it is making a 32bit executable with a 64bit compiler on a 64bit OS
goodrich@CYBERPOWERPC:/opt/stan/build-mingw32$ file stanc.exe
stanc.exe: PE32+ executable (console) x86-64, for MS Windows
I also tried to make a 32bit wine prefix, but Stan didn't seem to work with that either. I did not see anything in the Toolchain file about the bitness. Maybe it also needs to specify the archiver?
This looks like maybe it is grabbing the wrong wine executable or something? Do you have multiple versions of wine installed?
-ffat-lto-objects can you try that on Jenkins once the current pull requests finish? I don't think it will improve much with mingw based on g++-4.6 but I think it won't break the build, and if so, we should enable these options in the Makefile.
@Marcus, can you incorporate that into the CMake branch or tell me how to do it?
Ben
> I got a mingw based on g++-4.9 and it is much better (i.e. clang++-like) in its memory requirements iff CFLAGS += -flto=jobserver -ffat-lto-objects
Nice. I have no idea how you find all those flags. The doc for
these compilers seems thousands of pages long!
Can we just release a set of StanTools along the lines of RTools?
There's not that much in RTools that we need --- just the basic
unix stuff for make and the C++ compilers, I think.
Actually, Ben, should those LTO flags be passed to the linker as well or just at object compile time?
-ffat-lto-objects, so my guess is that mingw based on g++-4.6 would do the same. I think we can omit -ffat-lto-objects.Ok, the latest push should include the flags in the linker as well. I've also checked for -ffat-lto-objects separately so it will use it if the compiler recognizes it, but not otherwise.Is it worth turning on LTO even for non-mingw compilers? It would be easy to do that but I'm not really familiar with what it does and what the tradeoffs are.Also, is -lwinpthread always the right thing to link against? On my machine (Fedora 20) it fails because it can't find the library (it's there, but probably somewhere strange) and seems to work just fine without it.