YAP 7.1.0
or.insts.h
1/************************************************************************
2** **
3** The YapTab/YapOr/OPTYap systems **
4** **
5** YapTab extends the Yap Prolog engine to support sequential tabling **
6** YapOr extends the Yap Prolog engine to support or-parallelism **
7** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
8** **
9** **
10** Yap Prolog was developed at University of Porto, Portugal **
11** **
12************************************************************************/
13
14/* -------------------------------- **
15** Scheduler instructions **
16** -------------------------------- */
17
18 PBOp(getwork_first_time,e)
19 /* wait for a new parallel goal */
20 while (BITMAP_same(GLOBAL_bm_present_workers,GLOBAL_bm_finished_workers));
21 make_root_choice_point();
22 SCHEDULER_GET_WORK();
23 shared_end:
24 PUT_IN_FINISHED(worker_id);
25 /* wait until everyone else is finished! */
26 while (! BITMAP_same(GLOBAL_bm_present_workers,GLOBAL_bm_finished_workers));
27 PUT_OUT_ROOT_NODE(worker_id);
28 if (worker_id == 0) {
29 finish_yapor();
30 free_root_choice_point();
31 /* wait until no one is executing */
32 while (! BITMAP_empty(GLOBAL_bm_root_cp_workers));
33 goto fail;
34 } else {
35 PREG = GETWORK_FIRST_TIME;
36 PREFETCH_OP(PREG);
37 GONext();
38 }
39 ENDPBOp();
40
41
42
43
44 PBOp(getwork,Otapl)
45#ifdef TABLING
46 if (DepFr_leader_cp(LOCAL_top_dep_fr) == Get_LOCAL_top_cp()) {
47 /* the current top node is a leader node with consumer nodes below */
48 if (DepFr_leader_dep_is_on_stack(LOCAL_top_dep_fr)) {
49 /* the frozen branch depends on the current top node **
50 ** this means that the current top node is a generator node */
51 LOCK_OR_FRAME(LOCAL_top_or_fr);
52 if (OrFr_alternative(LOCAL_top_or_fr) == NULL ||
53 (OrFr_alternative(LOCAL_top_or_fr) == ANSWER_RESOLUTION && B_FZ != Get_LOCAL_top_cp())) {
54 /* there are no unexploited alternatives **
55 ** (NULL if batched scheduling OR ANSWER_RESOLUTION if local scheduling) */
56 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
57 goto completion;
58 } else {
59 /* there are unexploited alternatives **
60 ** we should exploit all the available alternatives before execute completion */
61 PREG = OrFr_alternative(LOCAL_top_or_fr);
62 PREFETCH_OP(PREG);
63 GONext();
64 }
65/* ricroc - obsolete
66#ifdef batched scheduling
67 if (OrFr_alternative(LOCAL_top_or_fr) != NULL) {
68#else local scheduling
69 if (OrFr_alternative(LOCAL_top_or_fr) != ANSWER_RESOLUTION || B_FZ == Get_LOCAL_top_cp()) {
70#endif
71 PREG = OrFr_alternative(LOCAL_top_or_fr);
72 PREFETCH_OP(PREG);
73 GONext();
74 }
75 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
76*/
77 }
78 goto completion;
79 }
80#endif /* TABLING */
81 LOCK_OR_FRAME(LOCAL_top_or_fr);
82 if (OrFr_alternative(LOCAL_top_or_fr)) {
83 PREG = OrFr_alternative(LOCAL_top_or_fr);
84 PREFETCH_OP(PREG);
85 GONext();
86 } else {
87 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
88 SCHEDULER_GET_WORK();
89 }
90 ENDPBOp();
91
92
93
94 /* The idea is to check whether we are the last worker in the node.
95 If we are, we can go ahead, otherwise we should call the scheduler. */
96 PBOp(getwork_seq,Otapl)
97 LOCK_OR_FRAME(LOCAL_top_or_fr);
98 if (OrFr_alternative(LOCAL_top_or_fr) &&
99 BITMAP_alone(OrFr_members(LOCAL_top_or_fr), worker_id)) {
100 PREG = OrFr_alternative(LOCAL_top_or_fr);
101 PREFETCH_OP(PREG);
102 GONext();
103 } else {
104 UNLOCK_OR_FRAME(LOCAL_top_or_fr);
105 SCHEDULER_GET_WORK();
106 }
107 ENDPBOp();
108
109
110
111 PBOp(sync,Otapl)
112 CUT_wait_leftmost();
113 PREG = NEXTOP(PREG,Otapl);
114 PREFETCH_OP(PREG);
115 GONext();
116 ENDPBOp();