I think we should claim we tested the Intel compiler
and it worked, not that we're planning on supporting it
going forward. At least until we get the compilation
more under control in the context of R and across
Win/Linux/Mac for g++ and clang++. I just don't want to
have to field questions about it.
Thanks for the truncated report.
The pointless comparison of unsigned int with
zero is from a templated class instantiated with
"unsigned int", but I suppose the comparison could
be statically removed the way we do with propto calcs
in the case of unsigned int.
I'll check out the matrix and LKJ density tests.
- Bob
I hear the Intel compiler produces faster code
than g++ or clang++, so it'd be nice to see the speed.
I think we should claim we tested the Intel compiler
and it worked, not that we're planning on supporting it
going forward. At least until we get the compilation
more under control in the context of R and across
Win/Linux/Mac for g++ and clang++. I just don't want to
have to field questions about it.
It's because I have to hit reply-to in order to
see the formatting in the messages from Ben and
from Marcus. As you can see below, I only get
spaces in their emails, and Thunderbird conveneniently
deletes line-initial spaces when showing messages.
- Bob
On 3/29/12 12:19 PM, Ben Goodrich wrote:
> On Thursday, March 29, 2012 10:37:20 AM UTC-4, Bob Carpenter wrote:
>
> I hear the Intel compiler produces faster code
> than g++ or clang++, so it'd be nice to see the speed.
>
>
> It's complicated (and I didn't test run-time speed). It definitely can be said that it compiles slowly; it took over an
> hour to run through test-all with one core. The benchmarks I have seen often don't make it 100% clear if they are
> talking about using the Intel Math Kernel Library (MKL) standalone or MKL with the Intel C++ compiler. So, I never have
> been able to get a clear picture of how much of the gain to attribute to the compiler itself. FWIW, the next version of
> Eigen will supposedly support using the MKL backend for some operations.
>
> I think we should claim we tested the Intel compiler
> and it worked, not that we're planning on supporting it
> going forward. At least until we get the compilation
> more under control in the context of R and across
> Win/Linux/Mac for g++ and clang++. I just don't want to
> have to field questions about it.
>
> OK, although in general I would say that stan should support whatever compilers are supported by the intersection of
> boost and Eigen.
Maybe we mean different things by "support". Right now,
our support is at the level of "works on my machine".
Here's what the Eigen FAQ has to say about their compiler
support:
------------------------------
Compiler support
Eigen is standard C++98 and so should theoretically be compatible with any compliant compiler. Whenever we use some
non-standard feature, that is optional and can be disabled.
Eigen is being successfully used with the following compilers:
GCC, version 3.4 and newer. Very good performance with GCC 4.2 and newer.
MSVC (Visual Studio), 2005 and newer. Vectorization is enabled with 2008 and newer, which also gives good performance.
Intel C++ compiler. Very good performance.
LLVM/CLang++ (2.8 and newer).
MinGW, recent versions. Very good performance when using GCC 4.
QNX's QCC compiler.
--------------------------
If that's all you mean by support, then by all means. Let's list
everything where we've been able to get it to compile. Anyone want
to volunteer to try MinGW on Windows?
The same version of g++ behaves very differently on the different platforms,
and what workedin 4.8 doesn't seem to work in 4.9. It's been driving
us nuts. It even behaves differently in terms of being able to succeed
with compilation at different optimization levels on the same platform.
Right now, our situation with Windows is that MSVC can compile the
parser, but not the models, whereas a suitably binary-edited verison of
g++ can compile the models but not the parser, and then only at
optimization level 3. The other optimization levels cause the compiler
to output an empty object file.
- Bob
> OK, although in general I would say that stan should support whatever compilers are supported by the intersection of
> boost and Eigen.
Anyone want to volunteer to try MinGW on Windows?
The same version of g++ behaves very differently on the different platforms,
and what workedin 4.8 doesn't seem to work in 4.9. It's been driving
us nuts. It even behaves differently in terms of being able to succeed
with compilation at different optimization levels on the same platform.
Right now, our situation with Windows is that MSVC can compile the
parser, but not the models, whereas a suitably binary-edited verison of
g++ can compile the models but not the parser, and then only at
optimization level 3. The other optimization levels cause the compiler
to output an empty object file.
I can't help much with Windows
is there some canonical way for the makefile to prefix $STAN_HOME to all paths so that they are absolute?
It's a ton of work. I've spent about 10 hours on it
already and there's probably another 4 or 5 left if all
goes well. So maybe early next week. This is something
to do on a big monitor, not at home.
Should've listened to Matt harder in the beginning when
he said there were advantages to splitting. I just followed
Eigen and Boost's practice, which apparently doesn't scale
very well.
The same kind of pain awaits in adding "const" declarations
everywhere they should go. I was very bad about not doing
that back in the days when I could hardly even get hello world
to compile in C++.
- Bob
On 3/30/12 6:10 PM, Ben Goodrich wrote:
> Well, the good news is that i686-w64-mingw32-g++ with -03 on my laptop can get through test-all and is now going through
> test-bugs and has made it through a couple of BUGS models now.
That's fantastic news.
I know Daniel was playing around with which tests
ran, but if you could run all the tests that are
turned on AND build stanc and run the models, that's
real progress.
> So, the question is why does this not work on Windows? Does mingw need the default system g++ (which is 4.6.x in my
> case) in any way? Maybe your Windows machine has a different version? I have not tried cross-compiling with -m32 yet, so
> maybe it is a problem with a 64 bit system trying to generate 32 bit binaries?
Daniel was wondering similar things
today about which versions of the compilers are getting
used and how they all depend on each other.
I think he's running 4.6 on Windows. Which version
does R expect?
> Daniel and I probably need to create proper make options when the compiler is i686-w64-mingw32-g++. The make/detect_os
> concludes that I am Linux but make/detect_cc concludes that I am using g++ rather than i686-w64-mingw32-g++. So, what we
> really want in this case is a mix of the existing Linux and Windows options.
Am I ever glad I'm not the only person working on
this project!
- Bob
On 3/30/12 6:10 PM, Ben Goodrich wrote:
> Well, the good news is that i686-w64-mingw32-g++ with -03 on my laptop can get through test-all and is now going through
> test-bugs and has made it through a couple of BUGS models now.That's fantastic news.
I know Daniel was playing around with which tests
ran, but if you could run all the tests that are
turned on AND build stanc and run the models, that's
real progress.
> So, the question is why does this not work on Windows? Does mingw need the default system g++ (which is 4.6.x in my
> case) in any way? Maybe your Windows machine has a different version? I have not tried cross-compiling with -m32 yet, so
> maybe it is a problem with a 64 bit system trying to generate 32 bit binaries?Daniel was wondering similar things
today about which versions of the compilers are getting
used and how they all depend on each other.I think he's running 4.6 on Windows. Which version
does R expect?
> Daniel and I probably need to create proper make options when the compiler is i686-w64-mingw32-g++. The make/detect_os
> concludes that I am Linux but make/detect_cc concludes that I am using g++ rather than i686-w64-mingw32-g++. So, what we
> really want in this case is a mix of the existing Linux and Windows options.Am I ever glad I'm not the only person working on
this project!
In the best case, this would signal a problem with
our Windows machine (the one running Jenkins), not
Windows in general.
I'll try to build under Windows using an old notebook
I have lying around and see if my mileage varies.
- Bob
More below inline.
On 3/31/12 3:17 PM, Ben Goodrich wrote:
> On Saturday, March 31, 2012 1:47:45 PM UTC-4, Bob Carpenter wrote:
>
> I'll try to build under Windows using an old notebook
> I have lying around and see if my mileage varies.
>
> Try to use whatever versions of all the tools come with the latest Rtools because that is closest to what CRAN will
> have. Also, in make/tests, I am pretty sure you will need to uncomment adding -static-libgcc and -static-libstdc++ and
> maybe they should be CFLAGS rather than LDFLAGS. These two options may be implied by the -static option, but then again
> the -static option may be too static.
Thanks for the tip. This page
http://cran.r-project.org/bin/windows/Rtools/
says to use the latest R and latest Rtools.
The latest R appears to be 2.15 (I'm already
a release behind and I just reinstalled last week!).
The toolchain Rtools215.exe is listed as "not frozen".
I take it that means they're giving us a moving target?
And do you think 215 is the one to use?
And what in the world do they mean by "releases after 2.14.1 will
use a new toolchain based on pre-4.6.3 gcc"? Are they really
using a pre-relese version of an old GCC?
> Also, I thought I got Jenkins working again last night ("Jenkins build is back to normal") but this morning it says it
> is broken again in a different place with no intervening commits. Is Jenkins quantum?
No, but I'm pretty sure there can be false positives. It
might be a timeout issue? I'm pretty sure I've seen false
positives as in I commit some doc and it says the build's fixed
or vice versa (submit doc and it says build is broken).
- Bob
Is it OK with everyone if we only support the latest
version of R? There's a new one out as of yesterday,
2.15, and they changed versions of GCC.
On 3/31/12 3:17 PM, Ben Goodrich wrote:
> On Saturday, March 31, 2012 1:47:45 PM UTC-4, Bob Carpenter wrote:
The toolchain Rtools215.exe is listed as "not frozen".
I take it that means they're giving us a moving target?
And do you think 215 is the one to use?
And what in the world do they mean by "releases after 2.14.1 will
use a new toolchain based on pre-4.6.3 gcc"? Are they really
using a pre-relese version of an old GCC?
> Also, I thought I got Jenkins working again last night ("Jenkins build is back to normal") but this morning it says it
> is broken again in a different place with no intervening commits. Is Jenkins quantum?No, but I'm pretty sure there can be false positives. It
might be a timeout issue? I'm pretty sure I've seen false
positives as in I commit some doc and it says the build's fixed
or vice versa (submit doc and it says build is broken).
On 3/31/12 4:04 PM, Ben Goodrich wrote:
> Okay, now it is saying that MSVC makes a file that is too big when trying to build the parser, but I don't think I did
> anything to affect the settings in the MSVC case.
Hmm. That's the problem we were having before.
These C++ compilers sure are squirrely.
- Bob
I should have said that I could help test building on windows. I have windows 7 64bits and windows xp 32 bits. But I guess the issue to me is that there is not a shell on which `make` could run as on Unix-like system.
I have no idea what a "STATUS_ACCESS_VIOLATION" is,
but it looks like it's related to permissions:
http://gaoithe.blogspot.com/2011/03/solved-cygwin-windows7.html
That would make sense as these tests need to read rather
than just run.
- Bob
On 3/31/12 10:57 PM, Jiqiang Guo wrote:
> As instructed, I installed Rtools215 and installed git. Under the git-bash, `make test-all' fails with log message at
> http://justpaste.it/uwb. `make test-bugs' is still testing models after stanc is built successfully.
>
> Gcc in Rtools215:
>
> $ gcc -v
> Using built-in specs.
> COLLECT_GCC=c:\Rtools\gcc-4.6.3\bin\gcc.exe
> COLLECT_LTO_WRAPPER=c:/rtools/gcc-4.6.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/lto-wrapper.exe
> Target: i686-w64-mingw32
> Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32
> --build=x86_64-linux-gnu --target=i686-w64-mingw32
> --with-sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32
> --prefix=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32
> --with-gmp=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install
> --with-mpfr=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install
> --with-mpc=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --disable-shared --enable-static
> --enable-targets=all --enable-languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions
> --enable-fully-dynamic-string --disable-nls --disable-werror --enable-checking=release --disable-win32-registry
> --disable-rpath --disable-werror CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
> Thread model: win32
> gcc version 4.6.3 20111208 (prerelease) (GCC)
>
>
>
> Jiqiang
>
As instructed, I installed Rtools215 and installed git. Under the git-bash, `make test-all' fails with log message at http://justpaste.it/uwb. `make test-bugs' is still testing models after stanc is built successfully.
Sorry I've been pretty silent on this issue.
I'll take a look at our Jenkins box and try to figure out what's going on.
Ben, do you want administrative access over the Jenkins process?
I have no idea what a "STATUS_ACCESS_VIOLATION" is,
but it looks like it's related to permissions:http://gaoithe.blogspot.com/2011/03/solved-cygwin-windows7.html
Whatever the issue cause that (Exception: STATUS_
ACCESS_VIOLATION), it is from mingw32 (or more specifically, the mingw32 packaged by Git on windows). I tried to build just using windows `cmd', all went well (uname is not found, but it is fine).This is a link to a snapshot of cmd and gitbash, giving you an idea of what are on windows:
Sorry, I'm confused. Where do you see this error?
The issue on the Jenkins configuration is O > 0. cc1plus.exe runs out of memory (that's what g++ calls).
Looks like it's a 32 bit compiler. Hopefully the rtools g++ is 64 bit. I'll try to install it this week.
The key to using less space in the compiler is
cutting down on the size of our translation units.
That doesn't play nicely with all of our header-only
template libs (Boost, Eigen, and the way we currently
have Stan organized).
I'm pretty sure it's possible to refactor the parser.
There are examples in the Boost parser doc:
http://www.boost.org/doc/libs/1_49_0/libs/spirit/example/qi/compiler_tutorial/
I haven't been able to refactor the parser so that
it uses explicit instantiation rather than being
header only. There's a simple working example of how to
do explicit instantiation with doc in
src/demo/templ_inst_demo
So far, I can't get it to link. The refactoring of the
grammars is in the subdirectory
stan/gm/grammars
I just added a couple of files that aren't being
used:
src/stan/gm/ast_header_def_unused_attempt.hpp
src/stan/gm/ast_header_unused_attempt.hpp
in which I tried to refactor the abstract
syntax tree (the data structure created by the parser
to represent a Stan program).
I can compile .o files, but I can't link. Rather than duplicate
defs, I get missing defs this time. I think it may
have something to do with the remaining templates in
ast.hpp, which could either be explicitly instantiated
during compilation with another file like the .cpp files
in the stan/gm/grammars directory or
replaced with their instantiations directly in the code.
- Bob
The key to using less space in the compiler is
cutting down on the size of our translation units.
Let me try to explain.
C and C++ compilation involves two stages:
1. Building one or more relocatable object files (.o)
> clang++ -c foo.cpp
> ls foo.o
> clang++ -c bar.cpp
> ls bar.o
2. Linking the relocatable object files into an executable:
> clang++ foo.o bar.o -o myprog
> ls myprog
The unit through which a relocatable object file is
built is called a "translation unit". In the first
example, that's the contents of "foo.cpp", with all of
the (recursive) includes folded in. In the second, it's
the same for "bar.cpp".
Now, to achieve this, we need to split definitions and
declarations.
A. Declaration (traditionally in a .h file)
int foo(int x);
B. Definition (traditionally in a .c file)
int foo(int x) { return x + 1; }
In order to generate relocatable object files, we only need
the declarations of functions/variables on which we depend.
Here's the key:
In order to link, every function and constant needs to be
DEFINED in EXACTLY ONE of the .o files.
Templates mess all of this up. They're halfway between
declarations and definitions. It's only when you specify the
type for a template that you get a definition (or declaration).
So template libs, like Eigen and Boost, are often what's
called "header only", meaning that they put the declarations
and definitions in a single file and everything gets built
as one big translation unit.
That's what Stan does now. For instance, the following
does both the compilation and linking:
> clang++ baz.cpp -o myprog
but it requires baz to import DEFINITIONS of everything
it needs (other than the std libs, which presumably get
linked in as necessary).
The header guards on the .hpp files make sure that each
item is only defined once.
So what we want to do is break the parser and perhaps
the models into pieces, one with a declaration, and one
with a definition.
Because templates don't have a definition until they're
instantiated, C++ lets you create a third type of file called
a template instantiation file. This is usually a .cpp
file that indicates which instantiations of the templates
you want. It then plays the role of the definition file,
getting compiled separately and then linked in later against
a .o file compiled by including only the declarations.
The simplest way to understand this in action is to look
at the example in:
stan/src/demo/templ_inst_demo
where I provide a very simple textbook example.
- Bob
So anyone with a 32-bit Windows machine will
be out of luck trying to compile multivariate
models at -O3. We just watched it crash at the 2GB
mark, which is all 32-bit hardware supports in
terms of process size (the OS/motherboard reserves
the other 2GB of potential address space).
I'm getting tired of waiting for small programs to compile, so maybe
I'll start breaking things out according to this template over the
next few days.
Matt
More inline below.
On 4/7/12 2:26 PM, Matt Hoffman wrote:
> Fascinating. This trick doesn't seem to be particularly well
> documented on the internet�I guess there's a good reason to buy books
> after all!
It was only in the uber-template book (by two guys who
were on the spec team) that's sitting on Daniel's desk
(Vandevoorde and Josuttis).
>
> I'm getting tired of waiting for small programs to compile, so maybe
I also think it's a big wall time disadvantage against BUGS
or JAGS, because they load small models quickly. But BUGS and JAGS
slow down very quickly as data sets get larger.
> I'll start breaking things out according to this template over the
> next few days.
We'll need to change the makefiles to accomodate.
I'm going to wait until I can get Daniel in person
to fix the build as I check it in so we don't kill
everyone's compiler.
And if I didn't mention it in the rant below, there's
a fully worked out example in a directory under src/demo.
It was just the way I got hello world going, so I
thought I'd check it in.
I'm pretty sure the way we're using Eigen through
a bunch of explicitly defined functions (in
stan/math/matrix.hpp and stan/agrad/matrix.hpp)
will let us do that with Eigen, too.
I could probably also do something with the code
generator so we don't even include the Eigen libraries
if we don't have any vector or matrix data types in
the Stan program. It should be pretty easy.
Although I don't think he ever brought it up on the
list, Daniel got precompiled headers working, but with
these header-only libs, that only reduced compile time
by 5 or 10%, so didn't seem worth it.
It might be a bigger percentage reduction if we use the
inclusion model, but probably still won't be a huge
amount of wall time.
- Bob
Although I don't think he ever brought it up on the
list, Daniel got precompiled headers working, but with
these header-only libs, that only reduced compile time
by 5 or 10%, so didn't seem worth it.
Matt
The name "precompiled headers" is misleading. You'd think
it would mean what Matt said, namely precompiled object (.o) files.
But it doesn't. Instead, it's a way for the
compiler to cache the parsing it does of #includes.
That way, the next translation unit you get to, you can lookup
the parsed form of all the header includes up to the point where
the includes diverge.
We're going to use "explicit template instantiation". That's
just the template version of separating out a pure
declaration header file from the definition source. This
will let us compile a bunch of smaller .o files separately
and then link them together.
I'm hoping that's kosher on CRAN -- they don't require
header-only libs, do they?
- Bob
We're going to use "explicit template instantiation". That's
just the template version of separating out a pure
declaration header file from the definition source. This
will let us compile a bunch of smaller .o files separately
and then link them together.I'm hoping that's kosher on CRAN -- they don't require
header-only libs, do they?
It's a moot point because we decided not to use them.
Good news. I finished the refactoring of the
parser with explicit instantiation. It took some
fighting because it was pretty template-heavy and
recursive code, but it works.
We'll need to change the makefiles to accomodate.
I'm going to wait until I can get Daniel in person
to fix the build as I check it in so we don't kill
everyone's compiler.
Although I don't think he ever brought it up on the
list, Daniel got precompiled headers working, but with
these header-only libs, that only reduced compile time
by 5 or 10%, so didn't seem worth it.