That sounds awesome. We're glad the makefile worked.
Were you using -O3 in the g++ compilation? I think
Ben tested MKL a while ago and didn't see that much difference.
More below.
On 1/11/14, 6:30 PM, Kyle Foreman wrote:
> I've seen some speculation on the list that using the Intel MKL libraries to compile Stan and Eigen might speed up
> sampling, but no confirmation. I just got MKL working and thought I'd pass along my results.
>
> To test I ran the stan/src/models/speed/logistic model with following sampling setup:
>
> sample
> num_samples = 100000
> num_warmup = 100000
> thin = 1000
>
> random
> seed = 1
>
>
> Here's the results from a vanilla (g++) run:
>
> Elapsed Time: 23.43 seconds (Warm-up)
> 36.5 seconds (Sampling)
> 59.93 seconds (Total)
>
>
> And here's the results for MKL (using icc to compile and linking in the appropriate libraries):
>
> Elapsed Time: 14.33 seconds (Warm-up)
> 17.67 seconds (Sampling)
> 32 seconds (Total)
>
>
> So MKL cuts sampling time nearly in half!
>
> Same system, same random seed, same stan version (latest commit b63bfa7), both versions single threaded, etc.
> Compilation takes a bit longer with the Intel compiler (I haven't timed it, but I estimate 2x).
>
> Implementing this is rather easy once you've got MKL installed on your system:
>
> 1. Download and extract a fresh copy of Stan
> 2. In your makefile change CC = g++ to CC = icc
> 3. Add the MKL path to makefile (e.g. MKLROOT = /apps/intel/2013/mkl)
> 4. Add the following to makefile's CFLAGS: -I $(MKLROOT)/include and -DEIGEN_USE_MKL_ALL
> 5. Link to your MKL library by adding to your makefile's LDLIBS
> * The exact implementation will depend on your system. Use the MKL link line advisor
> <
http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/> for help.
> * e.g. in my case: -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread -lm
> 6. Compile your model as usual
> * e.g. make src/models/speed/logistic/logistic
> * Note: make sure to do the above changes before compiling for the first time - otherwise Stan will be compiled
> with g++ and you won't see any performance gains
> o p.s. Devs - is there anyway to force stan to recompile? (short of deleting all the .cpp files I suppose)
You can touch the .stan file, which should cause everything to be
done again. Or you can touch the cpp file, which will
force recompilation. But it still won't rebuild all the libs.
It's just the way makefile works --- if nothing's changed, it
won't recompile.
> I've also attached an example makefile here (just remove .txt extension) in case the above isn't clear. I hope others
> find this useful!
Thanks!
Do you mind if we include these instructions in the manual?
It looks like they have some kind of non-commercial license:
http://software.intel.com/en-us/non-commercial-software-development
But it appears to be linux only.
- Bob