OpenMP for chess programming

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
BeyondCritics
Posts: 346
Joined: Sat May 05, 2012 12:48 pm
Location: Bergheim

OpenMP for chess programming

Post by BeyondCritics » Thu Jun 27, 2019 11:12 pm

I have a simple question: Would you consider to use OpenMP for chess programming? If i look a certain chess programs, this would be possible. Can you back up your opinion with facts? Thanks in advance.

Dann Corbit
Posts: 10128
Joined: Wed Mar 08, 2006 7:57 pm
Location: Redmond, WA USA
Contact:

Re: OpenMP for chess programming

Post by Dann Corbit » Fri Jun 28, 2019 12:17 am

Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.

Daniel Shawul
Posts: 3758
Joined: Tue Mar 14, 2006 10:34 am
Location: Ethiopia
Contact:

Re: OpenMP for chess programming

Post by Daniel Shawul » Fri Jun 28, 2019 3:52 pm

BeyondCritics wrote:
Thu Jun 27, 2019 11:12 pm
I have a simple question: Would you consider to use OpenMP for chess programming? If i look a certain chess programs, this would be possible. Can you back up your opinion with facts? Thanks in advance.
OpenMP has task based parallelism since 4.0 i think, so why not. It is easier if you use easy algorithms such as
MCTS, LazySMP, ABDADA etc but should be possible with YBW too. All you need from the library is to be able
to fork threads and provide some primitive synchronizations.

Sample code from my MCTS chess and Hex engine that uses OpenMP on the CPU and CUDA on the GPU.

Code: Select all

//
// locks
//
#ifdef GPU
#	define LOCK          int
#	define l_create(x)   ((x) = 0)
#	define l_trylock(x)  (atomicExch(&(x),1))
#	define l_lock(x)     while(l_trylock(x) != 0);
#	define l_unlock(x)   (atomicExch(&(x),0))
#	define l_add(x,v)	 (atomicAdd(&x,v))
#	define l_sub(x,v)	 (atomicSub(&x,v))
#else
#	define LOCK          omp_lock_t
#	define l_create(x)   omp_init_lock(&x)
#	define l_trylock(x)  omp_test_lock(&x)
#	define l_lock(x)     omp_set_lock(&x)
#	define l_unlock(x)   omp_unset_lock(&x)   
template <class T>
inline void l_add(T x,T v) { 
	#pragma omp atomic 
		x+=v;
}
template <class T>
inline void l_sub(T x,T v) { 
	#pragma omp atomic 
		x-=v;
}
#endif

Post Reply