Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Translate the executed TestAny and WaitAny requests into Test and Wait ones.
[simgrid.git] / src / mc / mc_request.c
1 #include "private.h"
2
3 int MC_request_depend(smx_req_t r1, smx_req_t r2)
4 {
5   if (r1->issuer == r2->issuer)
6     return FALSE;
7
8   if (r1->call == REQ_COMM_ISEND && r2->call == REQ_COMM_ISEND
9       && r1->comm_isend.rdv != r2->comm_isend.rdv)
10     return FALSE;
11
12   if (r1->call == REQ_COMM_IRECV && r2->call == REQ_COMM_IRECV
13       && r1->comm_irecv.rdv != r2->comm_irecv.rdv)
14     return FALSE;
15
16   if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
17       && r1->comm_wait.comm == r2->comm_wait.comm)
18     return FALSE;
19
20   if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
21       && r1->comm_wait.comm->comm.src_buff != NULL
22       && r1->comm_wait.comm->comm.dst_buff != NULL
23       && r2->comm_wait.comm->comm.src_buff != NULL
24       && r2->comm_wait.comm->comm.dst_buff != NULL
25       && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.src_buff
26       && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.dst_buff
27       && r2->comm_wait.comm->comm.dst_buff != r1->comm_wait.comm->comm.src_buff)
28     return FALSE;
29
30   if(r1->call == REQ_COMM_TEST &&
31       (r1->comm_test.comm == NULL
32        || r1->comm_test.comm->comm.src_buff == NULL
33        || r1->comm_test.comm->comm.dst_buff == NULL))
34     return FALSE;
35
36   if(r2->call == REQ_COMM_TEST &&
37       (r2->comm_test.comm == NULL
38        || r2->comm_test.comm->comm.src_buff == NULL
39        || r2->comm_test.comm->comm.dst_buff == NULL))
40     return FALSE;
41
42   if (r1->call == REQ_COMM_TEST && r2->call == REQ_COMM_WAIT
43       && r1->comm_test.comm == r2->comm_wait.comm)
44     return FALSE;
45
46   if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_TEST
47       && r1->comm_wait.comm == r2->comm_test.comm)
48     return FALSE;
49
50   return TRUE;
51 }
52
53 char *MC_request_to_string(smx_req_t req)
54 {
55   char *type = NULL, *args = NULL, *str = NULL; 
56   smx_action_t act = NULL;
57   size_t size = 0;
58   
59   switch(req->call){
60     case REQ_COMM_ISEND:
61       type = bprintf("iSend");
62       args = bprintf("src=%s, buff=%p, size=%zu", req->issuer->name, 
63                      req->comm_isend.src_buff, req->comm_isend.src_buff_size);
64       break;
65     case REQ_COMM_IRECV:
66       size = req->comm_irecv.dst_buff_size ? *req->comm_irecv.dst_buff_size : 0;
67       type = bprintf("iRecv");
68       args = bprintf("dst=%s, buff=%p, size=%zu", req->issuer->name, 
69                      req->comm_irecv.dst_buff, size);
70       break;
71     case REQ_COMM_WAIT:
72       act = req->comm_wait.comm;
73       type = bprintf("Wait");
74       args  = bprintf("%p [%s(%lu) -> %s(%lu)]", act,
75                       act->comm.src_proc ? act->comm.src_proc->name : "",
76                       act->comm.src_proc ? act->comm.src_proc->pid : 0,
77                       act->comm.dst_proc ? act->comm.dst_proc->name : "",
78                       act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
79       break;
80     case REQ_COMM_TEST:
81       act = req->comm_test.comm;
82       type = bprintf("Test");
83       args  = bprintf("%p [%s -> %s]", act, 
84                       act->comm.src_proc ? act->comm.src_proc->name : "",
85                       act->comm.dst_proc ? act->comm.dst_proc->name : "");
86       break;
87
88     case REQ_COMM_WAITANY:
89       type = bprintf("WaitAny");
90       args = bprintf("-");
91       /* FIXME: improve output */
92       break;
93
94     case REQ_COMM_TESTANY:
95        type = bprintf("TestAny");
96        args = bprintf("-");
97        /* FIXME: improve output */
98        break;
99
100     default:
101       THROW_UNIMPLEMENTED;
102   }
103
104   str = bprintf("[(%lu)%s] %s (%s)", req->issuer->pid ,req->issuer->name, type, args);
105   xbt_free(type);
106   xbt_free(args);
107   return str;
108 }
109
110 unsigned int MC_request_testany_fail(smx_req_t req)
111 {
112   unsigned int cursor;
113   smx_action_t action;
114
115   xbt_dynar_foreach(req->comm_testany.comms, cursor, action){
116     if(action->comm.src_proc && action->comm.dst_proc)
117       return FALSE;
118   }
119
120   return TRUE;
121 }