Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bugfix: do not assume that request of different type are independent, as it is wrong.
[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   return TRUE;
31 }
32
33 char *MC_request_to_string(smx_req_t req)
34 {
35   char *type = NULL, *args = NULL, *str = NULL; 
36   smx_action_t act = NULL;
37   size_t size = 0;
38   
39   switch(req->call){
40     case REQ_COMM_ISEND:
41       type = bprintf("iSend");
42       args = bprintf("src=%s, buff=%p, size=%zu", req->issuer->name, 
43                      req->comm_isend.src_buff, req->comm_isend.src_buff_size);
44       break;
45     case REQ_COMM_IRECV:
46       size = req->comm_irecv.dst_buff_size ? *req->comm_irecv.dst_buff_size : 0;
47       type = bprintf("iRecv");
48       args = bprintf("dst=%s, buff=%p, size=%zu", req->issuer->name, 
49                      req->comm_irecv.dst_buff, size);
50       break;
51     case REQ_COMM_WAIT:
52       act = req->comm_wait.comm;
53       type = bprintf("Wait");
54       args  = bprintf("%p [%s(%lu) -> %s(%lu)]", act,
55                       act->comm.src_proc ? act->comm.src_proc->name : "",
56                       act->comm.src_proc ? act->comm.src_proc->pid : 0,
57                       act->comm.dst_proc ? act->comm.dst_proc->name : "",
58                       act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
59       break;
60     case REQ_COMM_TEST:
61       act = req->comm_test.comm;
62       type = bprintf("Test");
63       args  = bprintf("%p [%s -> %s]", act, 
64                       act->comm.src_proc ? act->comm.src_proc->name : "",
65                       act->comm.dst_proc ? act->comm.dst_proc->name : "");
66       break;
67
68     case REQ_COMM_WAITANY:
69       type = bprintf("WaitAny");
70       args = bprintf("-");
71       /* FIXME: improve output */
72       break;
73
74     case REQ_COMM_TESTANY:
75        type = bprintf("TestAny");
76        args = bprintf("-");
77        /* FIXME: improve output */
78        break;
79
80     default:
81       THROW_UNIMPLEMENTED;
82   }
83
84   str = bprintf("[(%lu)%s] %s (%s)", req->issuer->pid ,req->issuer->name, type, args);
85   xbt_free(type);
86   xbt_free(args);
87   return str;
88 }
89
90 unsigned int MC_request_testany_fail(smx_req_t req)
91 {
92   unsigned int cursor;
93   smx_action_t action;
94
95   xbt_dynar_foreach(req->comm_testany.comms, cursor, action){
96     if(action->comm.src_proc && action->comm.dst_proc)
97       return FALSE;
98   }
99
100   return TRUE;
101 }