ybwc.h
Go to the documentation of this file.
1 
12 #ifndef EDAX_YBWC_H
13 #define EDAX_YBWC_H
14 
15 #include "util.h"
16 #include "const.h"
17 #include "settings.h"
18 
19 #include <stdbool.h>
20 
21 struct Search;
22 struct Move;
23 struct MoveList;
24 struct Task;
25 
29 typedef struct Task {
30  volatile bool loop;
31  volatile bool run;
32  volatile bool is_helping;
33  struct Search *search;
34  struct Node *node;
35  struct Move *move;
36  Thread thread;
37  unsigned long long n_calls;
38  unsigned long long n_nodes;
39  Lock lock;
40  Condition cond;
41  struct TaskStack *container;
42 } Task;
43 
48 typedef struct Node {
49  volatile int bestmove;
50  volatile int bestscore;
51  volatile int alpha;
52  int beta;
53  bool pv_node;
54  volatile int n_slave;
55  volatile bool stop_point;
56  volatile bool is_waiting;
57  int depth;
58  int height;
59  struct Search *search;
61  struct Node *parent;
62  struct Move *move;
63  volatile int n_moves_done;
64  volatile int n_moves_todo;
65  volatile bool is_helping;
66  Task help[1];
67  Lock lock;
68  Condition cond;
69 } Node;
70 
71 /* node function declaration */
72 void node_init(Node*, struct Search*, const int, const int, const int, const int, Node*);
73 void node_free(Node*);
74 bool node_split(Node*, struct Move*);
75 void node_stop_slaves(Node*);
76 void node_wait_slaves(Node*);
77 void node_update(Node*, struct Move*);
78 struct Move * node_first_move(Node*, struct MoveList*);
79 struct Move * node_next_move(Node*);
80 
81 /* task function declaration */
82 void* task_loop(void*);
83 void* task_help(void*);
84 void task_init(Task*);
85 void task_free(Task*);
86 void task_update(Task*);
87 void task_search(Task *task);
88 
93 typedef struct TaskStack {
94  SpinLock spin;
96  Task **stack;
97  int n;
98  int n_idle;
99 } TaskStack;
100 
101 /* task stack function declaration */
102 void task_stack_init(TaskStack*, const int);
104 void task_stack_resize(TaskStack*, const int);
105 void task_stack_stop(TaskStack*, const Stop);
109 unsigned long long task_stack_count_nodes(TaskStack*);
110 
111 #endif
112 
void task_stack_stop(TaskStack *, const Stop)
Condition cond
Definition: ybwc.h:68
volatile bool is_waiting
Definition: ybwc.h:56
struct Node * node
Definition: ybwc.h:34
unsigned long long n_calls
Definition: ybwc.h:37
int n
Definition: ybwc.h:97
void node_init(Node *, struct Search *, const int, const int, const int, const int, Node *)
Initialize a node.
Definition: ybwc.c:59
volatile bool run
Definition: ybwc.h:31
Definition: move.h:20
void node_wait_slaves(Node *)
Wait for slaves termination.
Definition: ybwc.c:212
Task * task
Definition: ybwc.h:95
void node_free(Node *)
Free Resources allocated by a node.
Definition: ybwc.c:95
Condition cond
Definition: ybwc.h:40
Definition: ybwc.h:48
struct Move * move
Definition: ybwc.h:35
void task_stack_put_idle_task(TaskStack *, Task *)
Put back an idle task after using it.
Definition: ybwc.c:661
bool pv_node
Definition: ybwc.h:53
void task_update(Task *)
struct Move * node_first_move(Node *, struct MoveList *)
Get the first move of the move list.
Definition: ybwc.c:297
Lock lock
Definition: ybwc.h:39
bool node_split(Node *, struct Move *)
Node split.
Definition: ybwc.c:167
struct Search * search
Definition: ybwc.h:33
void task_stack_init(TaskStack *, const int)
Initialize the stack of tasks.
Definition: ybwc.c:560
int beta
Definition: ybwc.h:52
volatile bool loop
Definition: ybwc.h:30
struct Search * slave[SPLIT_MAX_SLAVES]
Definition: ybwc.h:60
void node_stop_slaves(Node *)
volatile int n_moves_done
Definition: ybwc.h:63
struct Search * search
Definition: ybwc.h:59
Stop
Definition: const.h:70
void task_init(Task *)
Initialize a task.
Definition: ybwc.c:520
volatile int alpha
Definition: ybwc.h:51
struct Node Node
unsigned long long task_stack_count_nodes(TaskStack *)
SpinLock spin
Definition: ybwc.h:94
unsigned long long n_nodes
Definition: ybwc.h:38
Definition: search.h:95
void task_stack_free(TaskStack *)
Free resources used by the stack of tasks.
Definition: ybwc.c:607
void task_free(Task *)
Free resources used by a task.
Definition: ybwc.c:540
void task_stack_resize(TaskStack *, const int)
Resize the stack of tasks.
Definition: ybwc.c:626
volatile int n_slave
Definition: ybwc.h:54
Lock lock
Definition: ybwc.h:67
Miscellaneous utilities header.
void task_stack_clear(TaskStack *)
int depth
Definition: ybwc.h:57
struct Move * move
Definition: ybwc.h:62
Task * task_stack_get_idle_task(TaskStack *)
Return, if available, an idle task.
Definition: ybwc.c:638
void task_search(Task *task)
A parallel search within a Task structure.
Definition: ybwc.c:362
#define SPLIT_MAX_SLAVES
Definition: settings.h:107
int height
Definition: ybwc.h:58
volatile int bestmove
Definition: ybwc.h:49
void * task_help(void *)
volatile int bestscore
Definition: ybwc.h:50
Thread thread
Definition: ybwc.h:36
struct Task Task
int n_idle
Definition: ybwc.h:98
Definition: ybwc.h:93
Task help[1]
Definition: ybwc.h:66
volatile int n_moves_todo
Definition: ybwc.h:64
Definition: move.h:29
volatile bool is_helping
Definition: ybwc.h:32
Task ** stack
Definition: ybwc.h:96
Definition: ybwc.h:29
struct Move * node_next_move(Node *)
Get the next move of the move list.
Definition: ybwc.c:345
volatile bool stop_point
Definition: ybwc.h:55
volatile bool is_helping
Definition: ybwc.h:65
struct TaskStack * container
Definition: ybwc.h:41
struct TaskStack TaskStack
void node_update(Node *, struct Move *)
Update a node.
Definition: ybwc.c:261
void * task_loop(void *)
The main loop runned by a task.
Definition: ybwc.c:453
struct Node * parent
Definition: ybwc.h:61