A logging facility

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: A logging facility

Post by Daniel Shawul »

What most of people think is object oriented it is just name mangling, but there is more than name mangling in OO. And I can add that using classes to achieve name mangling is something I am not interested in.
A cheap shot? My objection (if any) is to you preaching us as follows:

QUESTION:
"What is the name of the endgame _bitbase_ that can be loaded in RAM whose name with starts with a _S_ but an h don't follow ? :)
ANSWER:
Somebody shouts "Shredder"!? I said it starts with "Sc" goddamit.. and so on

Get the picture? My point being I don't know if you think very high of yourself about C++, or think the rest of us are stupid or both , but you do come out as someone who thinks his solution is the only way... And I do not consider Stockfish or any other engine I have seen as a C++ work of art. Don't take it personally because like I said chess engine search , eval, move generation all need to be fast. Packages that I mentioned before have all something unique that affected/contributed to C++ in a way. What is it that you consider in Stockfish that highlights a feature of C++ in a unique way? I am not asking for an invention but for example something c would have some difficulties with ?

Incoming cheap shot:
My C++ is as good as yours. I just don't want to replace my macros with templates just to show off :)
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: A logging facility

Post by Daniel Shawul »

Would it be useful to introduces some more levels of logging? E.g. where the user can select whether:
Yes it may help to motivate engine authors to rely on the winboard debug if they can get a debug file with output only from their own engine. What the engine can log by itself, surely the GUI could do it better. But I am happy with one debug file as it is but it won't hurt to add options.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: A logging facility

Post by Rein Halbersma »

Daniel Shawul wrote: Incoming cheap shot:
My C++ is as good as yours. I just don't want to replace my macros with templates just to show off :)
It's simply bad C++ style to use macros where a template function can be used. You have it completely backwards: given their lack of lexical scoping and type safety, it's macros that are an example of showing off! ("Look ma, no helmet and protective suit for my motor bike")
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: A logging facility

Post by Daniel Shawul »

Yes I know the advantages of templates over macros. What is the point of replacing something you know is already working with a more verbose version that basically does the same thing?

Code: Select all

#define queen_value 900
vs
const int queen_value = 900
or

Code: Select all

#define is_cap(x)        ((x) & CAPTURE_FLAG)
#define is_prom(x)       ((x) & PROMOTION_FLAG)
#define is_cap_prom(x)   ((x) & CAP_PROM)
#define is_ep(x)         ((x) & EP_FLAG)
#define is_castle(x)     ((x) & CASTLE_FLAG)

vs

inline File file_of(Square s) {
  return File(s & 7);
}

inline Rank rank_of(Square s) {
  return Rank(s >> 3);
}

inline Square mirror(Square s) {
  return Square(s ^ 7);
}

inline Square relative_square(Color c, Square s) {
  return Square(s ^ (c * 56));
}

inline Rank relative_rank(Color c, Rank r) {
  return Rank(r ^ (c * 7));
}

inline Rank relative_rank(Color c, Square s) {
  return relative_rank(c, rank_of(s));
}
Now you start to think stockish is strictly c++ but wait

Code: Select all

#  define lock_init(x) pthread_mutex_init(&(x), NULL)
#  define lock_grab(x) pthread_mutex_lock(&(x))
#  define lock_release(x) pthread_mutex_unlock(&(x))
What? the evil macros again... I guess this is ripe for Marco to Marcotemplatization :)
No seriously though I recently came across that prevented me from using my beloved macros that I had to ask in a forum. Even thouhgh I knew the template solution already

Code: Select all

#	define l_lock(x)     omp_set_lock(&x)
#	define l_unlock(x)   omp_unset_lock(&x)   
template <class T>
inline void l_add&#40;T x,T v&#41; &#123; 
	#pragma omp atomic 
		x+=v;
&#125;
The other solution with macros was os dependent so I had to use the "evil" templates. My point is I am comfortable with macros and I just don't want to replace them when it serves me no purpose other than being strictly adherent (servant) to the language.

What would be interesting is using for example using stl containers and algorithms in search and compare performance. At least you come along and shook his world a bit there :)
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: A logging facility

Post by Rein Halbersma »

Daniel Shawul wrote:Yes I know the advantages of templates over macros. What is the point of replacing something you know is already working with a more verbose version that basically does the same thing?
If you know the disadvantages of macros, then why ask the question? Macros don't respect scope and type. This is an invitation for hidden bugs. Sure, if you are careful, you can avoid them. Same thing with a motor bike helmet ;-) Template just lets you detect the most common macro errors at compile-time, rather than at run-time.
What would be interesting is using for example using stl containers and algorithms in search and compare performance. At least you come along and shook his world a bit there :)
It's my belief & experience that raw engine performance might suffer a bit when relying heavily on STL algorithms and containers. This penalty can be as large as 10%, perhaps even 20%. But not more than that, as long as you don't spam the heap and create deep class hierarchies. The reason for the algorithms overhead is not the innate slowness of C++, but rather the lack of application-specific assumptions on the data passed to the generic algorithms (such as the typical size of a move vector, or the degree of sortedness of moves etc.)

OTOH, programmer productivity goes up greatly because you can use higher-level (and most often higher-quality!) code. This saves enormously on debugging common vector & list routines such as searching, sorting and partioning. Algorithmic improvements will usually catch up quickly with raw speedup improvements. The Stockfish team emphasizes raw performance, but still produces cleaner code than anything else that is out there. Stockfish also does not depend on high-level libraries such as Boost (the entire logging facility could have been largely imported). It's a reasonable trade-off now, but in the long run I think it's a burden for maintenance.

BTW, the new C++11 standard does create some very nice opportunities for optimization. E.g. the new move semantics will eliminate copy-overhead for some common C++ idioms. In Stockfish e.g. one could streamline the insertion of TT entries quite a bit. The new lambda functionality can likewise remove some of the function objects / passed function pointers.
mar
Posts: 2567
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A logging facility

Post by mar »

Rein Halbersma wrote: Stockfish also does not depend on high-level libraries such as Boost (the entire logging facility could have been largely imported). It's a reasonable trade-off now, but in the long run I think it's a burden for maintenance.
Oh, Boost in a chess engine?
Boost itself is a burden (happy chewing through all the includes, let the compiler suffocate).
Occam's razor reversed.
It's powerful but this is like "killing a mosquito with a hammer" :wink:
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: A logging facility

Post by Daniel Shawul »

If you know the disadvantages of macros, then why ask the question? Macros don't respect scope and type. This is an invitation for hidden bugs. Sure, if you are careful, you can avoid them. Same thing with a motor bike helmet Template just lets you detect the most common macro errors at compile-time, rather than at run-time.
Pedantic type checking clutters my code and is really too verbose for me. File, Rank, Piece, Color, Square are all ints in my engine. I am not that paranoid about it because one can make more mistakes dealing with c++ details than passing the wrong type of parameter in chess programming.
It's my belief & experience that raw engine performance might suffer a bit when relying heavily on STL algorithms and containers. This penalty can be as large as 10%, perhaps even 20%. But not more than that, as long as you don't spam the heap and create deep class hierarchies. The reason for the algorithms overhead is not the innate slowness of C++, but rather the lack of application-specific assumptions on the data passed to the generic algorithms (such as the typical size of a move vector, or the degree of sortedness of moves etc.)
For a 10% slowdown, I think my engine Nebiyu would really benefit from the added productivity. Right now it is a mess handling all those games with special needs every where.
BTW, the new C++11 standard does create some very nice opportunities for optimization. E.g. the new move semantics will eliminate copy-overhead for some common C++ idioms. In Stockfish e.g. one could streamline the insertion of TT entries quite a bit. The new lambda functionality can likewise remove some of the function objects / passed function pointers.
Yes C++11 looks interesting. It seems it has incorporated lots of features that C#/Java do already have except maybe garbage collection. Lambda expressions, regular expressions , threading library and most of boost sure will make life easier for many projects (maybe even for chess). Adding a GC will take away too much from the fact that c/c++ is meant for speed. But clearly c++ was falling behind those two as a modern programming language and this new version may just reinvigorate it. In general the bigger the library the better for me...others may disagree though. In a c++ project where I had to collect memory back from heap allocated objects as soon as they go out of scope, I ended up using lots of braces for no other reason than to force a destructor call. Should have used a language with a GC there...
OTOH, programmer productivity goes up greatly because you can use higher-level (and most often higher-quality!) code. This saves enormously on debugging common vector & list routines such as searching, sorting and partioning. Algorithmic improvements will usually catch up quickly with raw speedup improvements. The Stockfish team emphasizes raw performance, but still produces cleaner code than anything else that is out there. Stockfish also does not depend on high-level libraries such as Boost (the entire logging facility could have been largely imported). It's a reasonable trade-off now, but in the long run I think it's a burden for maintenance.
Exactly stockfish don't use fancy c++ stuff where it matters like the rest of us. So for it to be representative c++ chess engine it should use it in search , eval, and move generation (hearts of a chess engine). For example author of Blitz++ didn't complain about the difficulty of adding matrix A + B efficiently in c++ with all the copies that compiler may generate, they just came up with a solution to get equal performance as a simple for loop of fortran would achieve. Now that is what I call art and it will motivate others to do numerical computation with the language.
RoadWarrior
Posts: 73
Joined: Fri Jan 13, 2012 12:39 am
Location: London, England

Re: A logging facility

Post by RoadWarrior »

bhlangonijr wrote:oh my... don't you guys get tired of this kind of language wars? :)
This is a very known pattern:

Assembly guys bashing C language -->
C guys bashing C++ (vide Linus Torvalds vs some random c++ dude famous thread in the internet) -->
C++ guys bashing Java -->
Java guys bashing Scala, Python, Erlang, ....
You know that a specific discussion is turning towards a religious war rather than genuine technical debate when you learn more about the mindset of the developer doing the debating than you learn about the languages under debate. People start to confuse the strength of their feeling for the strength of their argument, and pass off personal value choices and cultural attachments as objective technical evaluations.

In my opinion:
  • Realise that although you're probably fairly intelligent given this esoteric field, you aren't as intelligent as you think you are. :shock:
    Try to have an open mind about new languages - but not so open that your brain falls out. :lol:
    Every language will teach you new stuff about software development. That stuff may not, however, be immediately useful.
    Do find out what you can learn from other software development cultures. For example, developers of chess engines and trading systems can learn a lot from each other.
There are two types of people in the world: Avoid them both.