SERVING THE QUANTITATIVE FINANCE COMMUNITY

  • 1
  • 4
  • 5
  • 6
  • 7
  • 8
  • 13
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 18th, 2017, 9:26 pm

No, the link compare boost vs GCC 4.8 (which could be as old as 2013).
So, gcc 4.8 was no good? will 5.x be any better??? Wishful thinking IMHO
when was C++11 finalized? 
Gcc is at 7.2 now I think
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 18th, 2017, 10:11 pm

I didn't have boost (nor C++) on my machine, but I did it online at wandbox, which also lets you choose compilers:

Results:
Boost 1.65.1

compiler: gcc 4.8.2 
1E7 x std::mt19937_64           126ms ans=9.22183e+25
1E7 x boost::random::mt19937_64 131ms ans=9.22183e+25

compiler: gcc 7.2.0 
1E7 x std::mt19937_64           172ms ans=9.22183e+25
1E7 x boost::random::mt19937_64 125ms ans=9.22183e+25

compiler: gcc 8.0.0 201712 HEAD
1E7 x std::mt19937_64           174ms ans=9.22183e+25
1E7 x boost::random::mt19937_64 138ms ans=9.22183e+25

compiler: clang 5.0.0
1E7 x std::mt19937_64           136ms ans=9.22183e+25
1E7 x boost::random::mt19937_64  66ms ans=9.22183e+25

compiler: clang 6.0.0 HEAD
1E7 x std::mt19937_64           124ms ans=9.22183e+25
1E7 x boost::random::mt19937_64  67ms ans=9.22183e+25
source:
#include <cstdint>
#include <chrono>
#include <iostream>
#include <random>
#include "boost/random.hpp"


int main(void) {

    std::chrono::steady_clock::time_point start, end;

    // --------------------------------------------------------------------------------------
    {
        double sum = 0.0;
        std::mt19937_64 eng;

        start = std::chrono::steady_clock::now();
        for (std::uint_fast64_t i=0; i<10000000; ++i) {
            sum +=  eng();
        }
        end = std::chrono::steady_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

        std::cout << "1E7 x std::mt19937_64          " << duration << "ms ans=" << sum << std::endl;
    }

    // --------------------------------------------------------------------------------------
    {
        double sum = 0.0;
        boost::random::mt19937_64 eng;

        start = std::chrono::steady_clock::now();
        for (std::uint_fast64_t i=0; i<10000000; ++i) {
            sum +=  eng();
        }
        end = std::chrono::steady_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

        std::cout << "1E7 x boost::random::mt19937_64 " << duration << "ms ans=" << sum << std::endl;
    }

    return 0;
}
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 18th, 2017, 10:28 pm

also VS vs and old version of Clang.

* Boost::mt is 4x faster on CLANG than on Visual Studio 
* std::mt is 3x faster of CLANG than Visual Studio
* boost::mt is 50% faster than std::mt

..but I'm not sure is -O3 is the command line argument in Visual Studio for optimization? 
source_file.cpp -o a.exe /EHsc /MD /I C:\boost_1_60_0 /link /LIBPATH:C:\boost_1_60_0\stage\lib -O3
http://rextester.com/l/cpp_online_compiler_visual

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
1E7 x std::mt19937_64           386ms ans=9.22183e+25
1E7 x boost::random::mt19937_64 296ms ans=9.22183e+25

clang 3.8.0
1E7 x std::mt19937_64          119ms ans=9.22183e+25
1E7 x boost::random::mt19937_64 73ms ans=9.22183e+25
 
User avatar
Billy7
Posts: 282
Joined: March 30th, 2016, 2:12 pm

Re: Using Quantlib

December 19th, 2017, 1:20 am

Wow, good tests! Thanks outrun. I am wondering now if Clang could be faster for other code as well, not just the mt rng... Any experience?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 19th, 2017, 6:53 am

Thanks.

I don't know much about VS, when I used it a long time ago it was a buggy non-compliant compiler.

I'm mostly working with Linux servers and at home with OSX. At some point I switched from GCC to Clang on Linux but not for speed but because it felt more robustly designed and it did some things better. The code I ran had not much speed difference, and benchmarks showed that in some bits of code one was better, others the other. The adoptation rate of C++11 features was a bit faster on Clang from what I remember?
 
User avatar
Cuchulainn
Topic Author
Posts: 62395
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 19th, 2017, 10:14 am

These preliminary results confirm my suspicion that algorithm performance depends on a) the compiler use and b) the libraries used by the compiler.

For VS I see Boost MT 64 as approx [2,3] times faster than C++11 MT64. I conclude that we are talking about two implementations by two independent developer groups.

So, let's say you want to speed up  MC; then the choice of RN library play a big role. They are not all the same. 
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 19th, 2017, 10:34 am

And also: there are other random number generator than MT, and you get a good speedup on the exact same code when you switch to better compilers
 
User avatar
Cuchulainn
Topic Author
Posts: 62395
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 19th, 2017, 10:40 am

And also: there are other random number generator than MT,  and you get a good speedup on the exact same code when you switch to better compilers
Of course. 
I ran a few lagged Fibonacci, knuth, default random but the picture remains the same.  Moving to a "better" compiler doesn't solve the problem.
Like Betamax and VHS, everyone uses VS and no one uses clang, relatively speaking. Your VS contact is  from years ago. 
 
User avatar
Cuchulainn
Topic Author
Posts: 62395
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 19th, 2017, 10:51 am

On a more philosophical note, there seems to be little coordination between the different C++ groups.. I wonder does FORTRAN have these issues?

The very fact that so many posts were needed to reach a conclusion says buckets.
 
User avatar
Cuchulainn
Topic Author
Posts: 62395
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 19th, 2017, 11:24 am

Wow, good tests! Thanks outrun. I am wondering now if Clang could be faster for other code as well, not just the mt rng... Any experience?
Does this need to be revised based on outrun's tests, for example? What were the assumptions?

but a 3-fold difference in performance because of different compiler implementations on something as widely used as rng seems unlikely to me.
 
User avatar
Billy7
Posts: 282
Joined: March 30th, 2016, 2:12 pm

Re: Using Quantlib

December 19th, 2017, 11:27 am

It is definitely very interesting to have examples of what kind of speed difference a compiler can make...Maybe compile a simple BS PDE solver in Clang and see if the code runs with significantly different speed than when compiled in VS? The Intel compiler is supposed to produce faster code in many cases, has anyone tried/compared it?
 
User avatar
Billy7
Posts: 282
Joined: March 30th, 2016, 2:12 pm

Re: Using Quantlib

December 19th, 2017, 11:37 am

Wow, good tests! Thanks outrun. I am wondering now if Clang could be faster for other code as well, not just the mt rng... Any experience?
Does this need to be revised based on outrun's tests, for example? What were the assumptions?

but a 3-fold difference in performance because of different compiler implementations on something as widely used as rng seems unlikely to me.
Well yes, unlikely doesn't mean impossible, I didn't even say highly unlikely:)
I am surprised, but then again an RNG may be a special case. Now I would be a lot more surprised if VS turned out to be producing 3 or even 2 times slower PDE code. Then I could switch compiler and have my codes run 2-3 time faster. That would be something.
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 19th, 2017, 11:40 am

And also: there are other random number generator than MT,  and you get a good speedup on the exact same code when you switch to better compilers
Of course. 
I ran a few lagged Fibonacci, knuth, default random but the picture remains the same.  Moving to a "better" compiler doesn't solve the problem.
Like Betamax and VHS, everyone uses VS and no one uses clang, relatively speaking. Your VS contact is  from years ago. 
"Clang is *very* widely used. Maybe not by you, but you don't see production systems, internet systems,.. only windows desktop, right? Clang is the goto compiler on  production systems running Linux, local or in the cloud. All iOS (iPhone, iPad, iThing) development is done with Clang. The whole Android markets.., it's huge..
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 19th, 2017, 11:43 am

Wow, good tests! Thanks outrun. I am wondering now if Clang could be faster for other code as well, not just the mt rng... Any experience?
Does this need to be revised based on outrun's tests, for example? What were the assumptions?

but a 3-fold difference in performance because of different compiler implementations on something as widely used as rng seems unlikely to me.
Well yes, unlikely doesn't mean impossible, I didn't even say highly unlikely:)
I am surprised, but then again an RNG may be a special case. Now I would be a lot more surprised if VS turned out to be producing 3 or even 2 times slower PDE code. Then I could switch compiler and have my codes run 2-3 time faster. That would be something.
I just saw a couple of blogpost on how to get rid of the MS C++ compiler on Windows and still use the VS IDE. People are doing this.
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 19th, 2017, 12:01 pm

an interesting read on Clang for MSVC: https://clang.llvm.org/docs/MSVCCompatibility.html
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On