Speed up your engine Part 3

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Speed up your engine Part 3

Post by lauriet »

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: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Speed up your engine Part 3

Post by Henk »

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: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Speed up your engine Part 3

Post by hgm »

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: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Speed up your engine Part 3

Post by mar »

hgm wrote:unless poor programming techniques make you waste orders of magnitude.
reminds me of Embla (C++), searching ~150kn/s
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Speed up your engine Part 3

Post by cdani »

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: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Speed up your engine Part 3

Post by Henk »

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: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Speed up your engine Part 3

Post by mar »

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: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: Speed up your engine Part 3

Post by ZirconiumX »

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 »

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: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Speed up your engine Part 3

Post by Sven »

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"?