3 #include "../simix/private.h"
8 * \brief Creates a state data structure used by the exploration algorithm
10 mc_state_t MC_state_new(void)
12 mc_state_t state = NULL;
14 state = xbt_new0(s_mc_state_t, 1);
15 state->max_pid = simix_process_maxpid;
16 state->proc_status = xbt_new0(s_mc_procstate_t, state->max_pid);
18 mc_stats->expanded_states++;
23 * \brief Deletes a state data structure
24 * \param trans The state to be deleted
26 void MC_state_delete(mc_state_t state)
28 xbt_free(state->proc_status);
32 void MC_state_interleave_process(mc_state_t state, smx_process_t process)
34 state->proc_status[process->pid].state = MC_INTERLEAVE;
35 state->proc_status[process->pid].interleave_count = 0;
38 unsigned int MC_state_interleave_size(mc_state_t state)
40 unsigned int i, size=0;
42 for(i=0; i < state->max_pid; i++){
43 if(state->proc_status[i].state == MC_INTERLEAVE)
50 int MC_state_process_is_done(mc_state_t state, smx_process_t process){
51 return state->proc_status[process->pid].state == MC_DONE ? TRUE : FALSE;
54 void MC_state_set_executed_request(mc_state_t state, smx_req_t req, int value)
56 state->executed_req = *req;
57 state->req_num = value;
59 /* The waitany and testany request are transformed into a wait or test request over the
60 * corresponding communication action so it can be treated later by the dependence
63 case REQ_COMM_WAITANY:
64 state->internal_req.call = REQ_COMM_WAIT;
65 state->internal_req.issuer = req->issuer;
66 state->internal_comm = *xbt_dynar_get_as(req->comm_waitany.comms, value, smx_action_t);
67 state->internal_req.comm_wait.comm = &state->internal_comm;
68 state->internal_req.comm_wait.timeout = 0;
71 case REQ_COMM_TESTANY:
72 state->internal_req.call = REQ_COMM_TEST;
73 state->internal_req.issuer = req->issuer;
76 state->internal_comm = *xbt_dynar_get_as(req->comm_testany.comms, value, smx_action_t);
78 state->internal_req.comm_wait.comm = &state->internal_comm;
79 state->internal_req.comm_test.result = value;
83 state->internal_req = *req;
84 state->internal_comm = *(req->comm_wait.comm);
85 state->executed_req.comm_wait.comm = &state->internal_comm;
86 state->internal_req.comm_wait.comm = &state->internal_comm;
90 state->internal_req = *req;
91 state->internal_comm = *req->comm_test.comm;
92 state->executed_req.comm_test.comm = &state->internal_comm;
93 state->internal_req.comm_test.comm = &state->internal_comm;
97 state->internal_req = *req;
102 smx_req_t MC_state_get_executed_request(mc_state_t state, int *value)
104 *value = state->req_num;
105 return &state->executed_req;
108 smx_req_t MC_state_get_internal_request(mc_state_t state)
110 return &state->internal_req;
113 smx_req_t MC_state_get_request(mc_state_t state, int *value)
115 smx_process_t process = NULL;
116 mc_procstate_t procstate = NULL;
117 unsigned int start_count;
119 xbt_swag_foreach(process, simix_global->process_list){
120 procstate = &state->proc_status[process->pid];
122 if(procstate->state == MC_INTERLEAVE){
123 if(MC_process_is_enabled(process)){
124 switch(process->request.call){
125 case REQ_COMM_WAITANY:
127 while(procstate->interleave_count < xbt_dynar_length(process->request.comm_waitany.comms)){
128 if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){
129 *value = procstate->interleave_count-1;
134 if(procstate->interleave_count >= xbt_dynar_length(process->request.comm_waitany.comms))
135 procstate->state = MC_DONE;
138 return &process->request;
142 case REQ_COMM_TESTANY:
143 start_count = procstate->interleave_count;
145 while(procstate->interleave_count < xbt_dynar_length(process->request.comm_testany.comms)){
146 if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){
147 *value = procstate->interleave_count - 1;
152 if(procstate->interleave_count >= xbt_dynar_length(process->request.comm_testany.comms))
153 procstate->state = MC_DONE;
155 if(*value != -1 || start_count == 0)
156 return &process->request;
161 if(process->request.comm_wait.comm->comm.src_proc
162 && process->request.comm_wait.comm->comm.dst_proc){
167 procstate->state = MC_DONE;
168 return &process->request;
173 procstate->state = MC_DONE;
175 return &process->request;