C++11 for chess engines

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

C++11 for chess engines

Post by mcostalba »

I have experimented a bit with C++11 and I have to say that it is really a big step forward, at least regarding code portability. I have created an experimental 'c++11' branch of Stockfish

https://github.com/mcostalba/Stockfish/ ... /c%2B%2B11

Amazingly in just few hours I was able to completely retire all the platform dependant code, using the new C++11 libraries instead. Namely I have removed all the platform dependant code (and surrounding wrappers cruft) dealing with:

- Threads and locking
- System time and timers
- Fixed signed integers and numeric types
- And even detection of number of cpus !

All in all about 200 lines of 'obscure' code removed !

I plan to keep the 'c++11' as a parallel branch and still use 'master' branch for main development for the time being because at the moment the support of C++11 among different compilers has still many rough edges. For instance I was able to use only gcc 4.7 on Linux. The corresponding mingw on Windows works only after replacing the standard libraries with the corresponding boost ones, because in that platform the gcc supplied libraries still don't enable std::thread.

Nevertheless my first impression is that in the medium/long term the upgrade to the new version of the language it is the way to go for C++ engines.
rreagan
Posts: 102
Joined: Sun Sep 09, 2007 6:32 am

Re: C++11 for chess engines

Post by rreagan »

How did you detect the number of CPUs in C++11?
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: C++11 for chess engines

Post by ZirconiumX »

rreagan wrote:How did you detect the number of CPUs in C++11?
std::thread::hardware_concurrency()

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
User avatar
trojanfoe
Posts: 65
Joined: Sun Jul 31, 2011 11:57 am
Location: Waterlooville, Hampshire, UK

Re: C++11 for chess engines

Post by trojanfoe »

mcostalba wrote: (snip)
Amazingly in just few hours I was able to completely retire all the platform dependant code, using the new C++11 libraries instead.

(snip)
I did the same thing with my C++ chess library, but then had to bring the old code back again as OS X Snow Leopard (10.6) doesn't have the C++11 runtime library. That is something you might want to look-out for...
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: C++11 for chess engines

Post by mcostalba »

trojanfoe wrote:
mcostalba wrote: That is something you might want to look-out for...
I plan to keep the master in C++03....
User avatar
velmarin
Posts: 1600
Joined: Mon Feb 21, 2011 9:48 am

Re: C++11 for chess engines

Post by velmarin »

Code: Select all

Intel® C++ Composer XE 2013 for Windows*, Initial Release
Submitted by (not verified) on Tue, 08/21/2012 - 16:12


Categories: Intel® C++ Compiler  Intel® C++ Composer XE  Intel® Composer XE  Intel® Integrated Performance Primitives  Intel® Math Kernel Library  C/C++  Developers  Microsoft Windows* (XP, Vista, 7)  Microsoft Windows* 8
Intel® C++ Composer XE 2013 includes the latest Intel C/C++ compilers and performance libraries for IA-32 and Intel® 64 architecture systems. This new product release now includes: Intel® C++ Compiler XE Version 13.0.0, Intel® Math Kernel Library (Intel® MKL) Version 11.0, Intel® Integrated Performance Primitives (Intel® IPP) Version 7.1, Intel® Threading Building Blocks (Intel® TBB) Version 4.1

New in this release:

Intel® C++ Compiler updated to version 13.0.
Intel® Parallel Debugger Extension has been removed.
Intel® Math Kernel Library updated to version 11.0
Removed support for Intel® Pentium® III processor.
Intel® Integrated Performance Primitives updated to version 7.1
Intel® IPP static threaded libraries now available in separate package
Intel® Threading Building Blocks updated to version 4.1
Microsoft Windows Vista* and Windows Server 2003* are not supported.
Microsoft Visual Studio 2005* is not supported.
The Intel® Software Manager has been added to help you manage product updates and
license activation
Notes on Use with Microsoft Windows 8*, Microsoft Windows Server 2012*, and Microsoft Visual Studio 2012* products
New C++11 features
Improved support for future Intel processors
New Intel Performance Wizard
Out-of-bounds memory checking
Static Analysis Improvements 
Note:  For more information on the changes listed above, please read the individual component release notes.
New C++11 features

Intel joins the party :D
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: C++11 for chess engines

Post by mcostalba »

velmarin wrote: Intel joins the party :D
Are you able to compile the c++11 branch of SF with Intel and verify if it works, or if it is even faster than master ;-) .....but I doubt.
User avatar
velmarin
Posts: 1600
Joined: Mon Feb 21, 2011 9:48 am

Re: C++11 for chess engines

Post by velmarin »

src\misc.h(23): error : cannot open source file "chrono"
1> #include <chrono>
1> ^

Already tried,
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: C++11 for chess engines

Post by mcostalba »

velmarin wrote:src\misc.h(23): error : cannot open source file "chrono"
1> #include <chrono>
1> ^

Already tried,
:-) :-) :-) You need to try much harder. C++11 is not "plug and play" yet. I know because I had to work quite a bit to make it on gcc and clang (where it just compiles but it still doesn't run).
User avatar
velmarin
Posts: 1600
Joined: Mon Feb 21, 2011 9:48 am

Re: C++11 for chess engines

Post by velmarin »

It seems I need Visual C + + 2012,
Microsoft pulls Metro.,
Here's a partial list of the changes in Visual C++ in Visual Studio 2012:
New headers: <atomic>, <chrono>, <condition_variable>, <future>, <mutex>, <ratio>, <scoped_allocator>, and <thread>.
http://msdn.microsoft.com/en-us/library/hh567368.aspx
I had already installed, but I like Visual C + +2010, I created a problem and uninstall it.

Maybe install in a virtual machine.