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++;
22 mc_state_t MC_state_pair_new(void)
24 mc_state_t state = NULL;
26 state = xbt_new0(s_mc_state_t, 1);
27 state->max_pid = simix_process_maxpid;
28 state->proc_status = xbt_new0(s_mc_procstate_t, state->max_pid);
30 //mc_stats->expanded_states++;
35 * \brief Deletes a state data structure
36 * \param trans The state to be deleted
38 void MC_state_delete(mc_state_t state)
40 xbt_free(state->proc_status);
44 void MC_state_interleave_process(mc_state_t state, smx_process_t process)
46 state->proc_status[process->pid].state = MC_INTERLEAVE;
47 state->proc_status[process->pid].interleave_count = 0;
50 unsigned int MC_state_interleave_size(mc_state_t state)
52 unsigned int i, size=0;
54 for(i=0; i < state->max_pid; i++){
55 if(state->proc_status[i].state == MC_INTERLEAVE)
62 int MC_state_process_is_done(mc_state_t state, smx_process_t process){
63 return state->proc_status[process->pid].state == MC_DONE ? TRUE : FALSE;
66 void MC_state_set_executed_request(mc_state_t state, smx_req_t req, int value)
68 state->executed_req = *req;
69 state->req_num = value;
71 /* The waitany and testany request are transformed into a wait or test request over the
72 * corresponding communication action so it can be treated later by the dependence
75 case REQ_COMM_WAITANY:
76 state->internal_req.call = REQ_COMM_WAIT;
77 state->internal_req.issuer = req->issuer;
78 state->internal_comm = *xbt_dynar_get_as(req->comm_waitany.comms, value, smx_action_t);
79 state->internal_req.comm_wait.comm = &state->internal_comm;
80 state->internal_req.comm_wait.timeout = 0;
83 case REQ_COMM_TESTANY:
84 state->internal_req.call = REQ_COMM_TEST;
85 state->internal_req.issuer = req->issuer;
88 state->internal_comm = *xbt_dynar_get_as(req->comm_testany.comms, value, smx_action_t);
90 state->internal_req.comm_wait.comm = &state->internal_comm;
91 state->internal_req.comm_test.result = value;
95 state->internal_req = *req;
96 state->internal_comm = *(req->comm_wait.comm);
97 state->executed_req.comm_wait.comm = &state->internal_comm;
98 state->internal_req.comm_wait.comm = &state->internal_comm;
102 state->internal_req = *req;
103 state->internal_comm = *req->comm_test.comm;
104 state->executed_req.comm_test.comm = &state->internal_comm;
105 state->internal_req.comm_test.comm = &state->internal_comm;
109 state->internal_req = *req;
114 smx_req_t MC_state_get_executed_request(mc_state_t state, int *value)
116 *value = state->req_num;
117 return &state->executed_req;
120 smx_req_t MC_state_get_internal_request(mc_state_t state)
122 return &state->internal_req;
125 smx_req_t MC_state_get_request(mc_state_t state, int *value)
127 smx_process_t process = NULL;
128 mc_procstate_t procstate = NULL;
129 unsigned int start_count;
131 xbt_swag_foreach(process, simix_global->process_list){
132 procstate = &state->proc_status[process->pid];
134 if(procstate->state == MC_INTERLEAVE){
135 if(MC_process_is_enabled(process)){
136 switch(process->request.call){
137 case REQ_COMM_WAITANY:
139 while(procstate->interleave_count < xbt_dynar_length(process->request.comm_waitany.comms)){
140 if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){
141 *value = procstate->interleave_count-1;
146 if(procstate->interleave_count >= xbt_dynar_length(process->request.comm_waitany.comms))
147 procstate->state = MC_DONE;
150 return &process->request;
154 case REQ_COMM_TESTANY:
155 start_count = procstate->interleave_count;
157 while(procstate->interleave_count < xbt_dynar_length(process->request.comm_testany.comms)){
158 if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){
159 *value = procstate->interleave_count - 1;
164 if(procstate->interleave_count >= xbt_dynar_length(process->request.comm_testany.comms))
165 procstate->state = MC_DONE;
167 if(*value != -1 || start_count == 0)
168 return &process->request;
173 if(process->request.comm_wait.comm->comm.src_proc
174 && process->request.comm_wait.comm->comm.dst_proc){
179 procstate->state = MC_DONE;
180 return &process->request;
185 procstate->state = MC_DONE;
187 return &process->request;