"Logging specific to SIMIX (network)");
static xbt_dict_t rdv_points = NULL;
-unsigned long int smx_total_comms = 0;
+XBT_IMPORT_NO_EXPORT(unsigned long int) smx_total_comms = 0;
static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall);
static void SIMIX_comm_copy_data(smx_action_t comm);
static smx_action_t SIMIX_comm_new(e_smx_comm_type_t type);
static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm);
+static smx_action_t SIMIX_fifo_probe_comm(xbt_fifo_t fifo, e_smx_comm_type_t type,
+ int (*match_fun)(void *, void *,smx_action_t),
+ void *user_data, smx_action_t my_action);
static smx_action_t SIMIX_fifo_get_comm(xbt_fifo_t fifo, e_smx_comm_type_t type,
int (*match_fun)(void *, void *,smx_action_t),
void *user_data, smx_action_t my_action);
void SIMIX_network_init(void)
{
rdv_points = xbt_dict_new_homogeneous(SIMIX_rdv_free);
+ if(MC_is_active())
+ MC_ignore(&smx_total_comms, sizeof(smx_total_comms));
}
void SIMIX_network_exit(void)
}
+/**
+ * \brief Checks if there is a communication action queued in a fifo matching our needs, but leave it there
+ * \param type The type of communication we are looking for (comm_send, comm_recv)
+ * \return The communication action if found, NULL otherwise
+ */
+smx_action_t SIMIX_fifo_probe_comm(xbt_fifo_t fifo, e_smx_comm_type_t type,
+ int (*match_fun)(void *, void *,smx_action_t),
+ void *this_user_data, smx_action_t my_action)
+{
+ smx_action_t action;
+ xbt_fifo_item_t item;
+ void* other_user_data = NULL;
+
+ xbt_fifo_foreach(fifo, item, action, smx_action_t) {
+ if (action->comm.type == SIMIX_COMM_SEND) {
+ other_user_data = action->comm.src_data;
+ } else if (action->comm.type == SIMIX_COMM_RECEIVE) {
+ other_user_data = action->comm.dst_data;
+ }
+ if (action->comm.type == type &&
+ (!match_fun || match_fun(this_user_data, other_user_data, action)) &&
+ (!action->comm.match_fun || action->comm.match_fun(other_user_data, this_user_data, my_action))) {
+ XBT_DEBUG("Found a matching communication action %p", action);
+ action->comm.refcount++;
+
+ return action;
+ }
+ XBT_DEBUG("Sorry, communication action %p does not match our needs:"
+ " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)",
+ action, (int)action->comm.type, (int)type);
+ }
+ XBT_DEBUG("No matching communication action found");
+ return NULL;
+}
/******************************************************************************/
/* Communication Actions */
/******************************************************************************/
other_action->comm.match_fun = match_fun;
- if (MC_IS_ENABLED) {
+ if (MC_is_active()) {
other_action->state = SIMIX_RUNNING;
return other_action;
}
other_action->state = SIMIX_DONE;
other_action->comm.type = SIMIX_COMM_DONE;
other_action->comm.rdv = NULL;
- SIMIX_comm_destroy(this_action);
- --smx_total_comms; // this creation was a pure waste
+ //SIMIX_comm_destroy(this_action);
+ //--smx_total_comms; // this creation was a pure waste
//already_received=1;
- other_action->comm.refcount--;
+ //other_action->comm.refcount--;
}/*else{
XBT_DEBUG("Not yet finished, we have to wait %d\n", xbt_fifo_size(rdv->comm_fifo));
}*/
- other_action->comm.refcount--;
+ // other_action->comm.refcount--;
SIMIX_comm_destroy(this_action);
--smx_total_comms; // this creation was a pure waste
}
--smx_total_comms; // this creation was a pure waste
other_action->state = SIMIX_READY;
other_action->comm.type = SIMIX_COMM_READY;
- xbt_fifo_push(dst_proc->comms, other_action);
-
+ // other_action->comm.refcount--;
}
+ xbt_fifo_push(dst_proc->comms, other_action);
}
-
/* Setup communication action */
other_action->comm.dst_proc = dst_proc;
other_action->comm.dst_buff = dst_buff;
SIMIX_comm_copy_data(other_action);*/
- if (MC_IS_ENABLED) {
+ if (MC_is_active()) {
other_action->state = SIMIX_RUNNING;
return other_action;
}
return other_action;
}
+
+smx_action_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_rdv_t rdv, int src,
+ int tag, int (*match_fun)(void *, void *, smx_action_t), void *data)
+{
+ XBT_DEBUG("iprobe from %p %p\n", rdv, rdv->comm_fifo);
+ smx_action_t this_action = SIMIX_comm_new(SIMIX_COMM_RECEIVE);
+
+ smx_action_t other_action=NULL;
+ if(rdv->permanent_receiver && xbt_fifo_size(rdv->done_comm_fifo)!=0){
+ //find a match in the already received fifo
+ XBT_DEBUG("first try in the perm recv mailbox \n");
+
+ other_action = SIMIX_fifo_probe_comm(rdv->done_comm_fifo, SIMIX_COMM_SEND, match_fun, data, this_action);
+ }
+ // }else{
+ if(!other_action){
+ XBT_DEBUG("second try in the other mailbox");
+ other_action = SIMIX_fifo_probe_comm(rdv->comm_fifo, SIMIX_COMM_SEND, match_fun, data, this_action);
+ }
+// }
+ if(other_action)other_action->comm.refcount--;
+
+ SIMIX_comm_destroy(this_action);
+ --smx_total_comms;
+ return other_action;
+}
+
void SIMIX_pre_comm_wait(smx_simcall_t simcall, smx_action_t action, double timeout, int idx)
{
xbt_fifo_push(action->simcalls, simcall);
simcall->issuer->waiting_action = action;
- if (MC_IS_ENABLED) {
+ if (MC_is_active()) {
if (idx == 0) {
action->state = SIMIX_DONE;
} else {
{
smx_action_t action = simcall->comm_test.comm;
- if(MC_IS_ENABLED){
+ if(MC_is_active()){
simcall->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
if(simcall->comm_test.result){
action->state = SIMIX_DONE;
xbt_dynar_t actions = simcall->comm_testany.comms;
simcall->comm_testany.result = -1;
- if (MC_IS_ENABLED){
+ if (MC_is_active()){
if(idx == -1){
SIMIX_simcall_answer(simcall);
}else{
unsigned int cursor = 0;
xbt_dynar_t actions = simcall->comm_waitany.comms;
- if (MC_IS_ENABLED){
+ if (MC_is_active()){
action = xbt_dynar_get_as(actions, idx, smx_action_t);
xbt_fifo_push(action->simcalls, simcall);
simcall->comm_waitany.result = idx;
return it as the result of the simcall */
if (simcall->call == SIMCALL_COMM_WAITANY) {
SIMIX_waitany_remove_simcall_from_actions(simcall);
- if (!MC_IS_ENABLED)
+ if (!MC_is_active())
simcall->comm_waitany.result = xbt_dynar_search(simcall->comm_waitany.comms, &action);
}
SIMIX_rdv_remove(action->comm.rdv, action);
action->state = SIMIX_CANCELED;
}
- else if (!MC_IS_ENABLED /* when running the MC there are no surf actions */
+ else if (!MC_is_active() /* when running the MC there are no surf actions */
&& (action->state == SIMIX_READY || action->state == SIMIX_RUNNING)) {
surf_workstation_model->action_cancel(action->comm.surf_comm);