Speed up your engine Part 3

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, bob, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
lauriet
Posts: 197
Joined: Sun Nov 03, 2013 8:32 am
Contact:

Speed up your engine Part 3

Post by lauriet » Mon Jul 18, 2016 8:19 am

Hi,
My program is written using FreePascal for LINUX.
I am about the furthest thing away from a C programmer and do not want to start a religious wars thread so....

Would a simple minded conversion to C provide any benefit, or do you need to change "style" to take advantage of
any C benefits ?

I could do a conversion but it would essentially be a Pascal program with C syntax.

Thanks

Laurie.

Henk
Posts: 6531
Joined: Mon May 27, 2013 8:31 am

Re: Speed up your engine Part 3

Post by Henk » Mon Jul 18, 2016 10:33 am

Maybe start with (magic) bitboards. Don't even know if Pascal has bit operations. Usually evaluation makes a program slow. For instance my program slowed down by a factor seven when I tried to implement a normal evaluation. Pawn table did not help much either.

User avatar
hgm
Posts: 24922
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Speed up your engine Part 3

Post by hgm » Mon Jul 18, 2016 11:11 am

Beware that speed contributes almost nothing to the strength of your program, unless poor programming techniques make you waste orders of magnitude. Doing things like bitboards is a complete waste of time when the search and eval are not good enough to reach 2700 Elo.

mar
Posts: 2185
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Speed up your engine Part 3

Post by mar » Mon Jul 18, 2016 12:35 pm

hgm wrote:unless poor programming techniques make you waste orders of magnitude.
reminds me of Embla (C++), searching ~150kn/s

User avatar
cdani
Posts: 2175
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

Re: Speed up your engine Part 3

Post by cdani » Mon Jul 18, 2016 12:54 pm

lauriet wrote:Hi,
My program is written using FreePascal for LINUX.
I am about the furthest thing away from a C programmer and do not want to start a religious wars thread so....

Would a simple minded conversion to C provide any benefit, or do you need to change "style" to take advantage of
any C benefits ?

I could do a conversion but it would essentially be a Pascal program with C syntax.

Thanks

Laurie.
I started Andscacs in Lazarus pascal. When it already was playing (bad) I translated it to C at it was clearly faster, but I dont remember the details. I sticked to C.

Henk
Posts: 6531
Joined: Mon May 27, 2013 8:31 am

Re: Speed up your engine Part 3

Post by Henk » Mon Jul 18, 2016 1:27 pm

mar wrote:
hgm wrote:unless poor programming techniques make you waste orders of magnitude.
reminds me of Embla (C++), searching ~150kn/s
Skipper running now 300kn/sec. That's 2-3 times slower than fairy-max on my computer. I get normal speed if it does not do much more than counting material incrementally.

mar
Posts: 2185
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Speed up your engine Part 3

Post by mar » Mon Jul 18, 2016 1:55 pm

Henk wrote:Skipper running now 300kn/sec. That's 2-3 times slower than fairy-max on my computer. I get normal speed if it does not do much more than counting material incrementally.
Yes, nps depends on a lot of factors.
Here Fairy-max runs at 1mn/sec.
But since there's no consensus on how to count nodes, perhaps Folkert doesn't count qs nodes (in my case, nps decreases to ~25% counting this way; in startposition)

EDIT: with other words, the only fair comparison is using same compiler on same hardware and most importantly counting nodes the same way

ZirconiumX
Posts: 1327
Joined: Sun Jul 17, 2011 9:14 am

Re: Speed up your engine Part 3

Post by ZirconiumX » Mon Jul 18, 2016 2:06 pm

hgm wrote:Beware that speed contributes almost nothing to the strength of your program, unless poor programming techniques make you waste orders of magnitude. Doing things like bitboards is a complete waste of time when the search and eval are not good enough to reach 2700 Elo.
I am ashamed to admit I fell into that trap. I spent the better part of two weeks converting Dorpsgek from an attack table based program to a 16x12 array based program.

Perft-wise, I'm 3.5x faster. Search wise, I am 1.5x faster.

But the old code still beats the new code hands down.
Some believe in the almighty dollar.

I believe in the almighty printf statement.

flok

Re: Speed up your engine Part 3

Post by flok » Mon Jul 18, 2016 2:53 pm

That's not because of bad programming - the algorithm used is implemented very efficiently. It's only the algorithm which lacks a bit (e.g. no bitboard).

Sven
Posts: 3882
Joined: Thu May 15, 2008 7:57 pm
Location: Berlin, Germany
Full name: Sven Schüle
Contact:

Re: Speed up your engine Part 3

Post by Sven » Mon Jul 18, 2016 3:18 pm

lauriet wrote:My program is written using FreePascal for LINUX.
I am about the furthest thing away from a C programmer and do not want to start a religious wars thread so....

Would a simple minded conversion to C provide any benefit, or do you need to change "style" to take advantage of
any C benefits ?

I could do a conversion but it would essentially be a Pascal program with C syntax.
It depends on your goals.

If you want to keep the "same" program but you want it to run faster then perhaps you might want to translate it from Pascal into C/C++. But beware: you will probably introduce new bugs, and you will get program code in a language that you are not familiar with, so initially it will be harder for you to maintain it.

If you want to learn C/C++ then there are several ways to achieve that. At least working through a good book is one of these ways. Another way could be to translate your program into C/C++, or even better: to rewrite it in C/C++. That will take some time, but if learning is the goal then you might be willing to invest time.

If you want to become familiar with bitboards in the context of chess programming then it might be a good idea to do that in C/C++, although Pascal has some bit operations as well as far as I know - but I would not do that with your first C/C++ program, so having rewritten your program in C/C++ would be the first step.

If you want to improve your existing program step by step and do not care much about optimal speed or about learning another language then it is certainly better to stick with your Pascal code. Most programmers successfully use those languages and tools they are most familiar with, so why not Pascal if that is the language you are "speaking"?

Post Reply