static inline void event_cancel(tw_event * event) { tw_pe *send_pe = event->src_lp->pe; tw_peid dest_peid; if(event->state.owner == TW_net_asend || event->state.owner == TW_pe_sevent_q) { /* Slowest approach of all; this has to be sent over the * network to let the dest_pe know it shouldn't have seen * it in the first place. */ tw_net_cancel(event); send_pe->stats.s_nsend_net_remote--; if(tw_gvt_inprogress(send_pe)) { send_pe->trans_msg_ts = ROSS_MIN(send_pe->trans_msg_ts, event->recv_ts); } return; } dest_peid = event->dest_lp->pe->id; if (send_pe->id == dest_peid) { switch (event->state.owner) { case TW_pe_pq: /* Currently in our pq and not processed; delete it and * free the event buffer immediately. No need to wait. */ tw_pq_delete_any(send_pe->pq, event); tw_event_free(send_pe, event); break; case TW_pe_event_q: case TW_kp_pevent_q: local_cancel(send_pe, event); if(tw_gvt_inprogress(send_pe)) { send_pe->trans_msg_ts = ROSS_MIN(send_pe->trans_msg_ts, event->recv_ts); } break; default: tw_error(TW_LOC, "unknown fast local cancel owner %d", event->state.owner); } } else if (send_pe->node == dest_peid) { /* Slower, but still a local cancel, so put into * top of dest_pe->cancel_q for final deletion. */ local_cancel(event->dest_lp->pe, event); send_pe->stats.s_nsend_loc_remote--; if(tw_gvt_inprogress(send_pe)) { send_pe->trans_msg_ts = ROSS_MIN(send_pe->trans_msg_ts, event->recv_ts); } } else { tw_error(TW_LOC, "Should be remote cancel!"); } }
static int recv_begin(tw_pe *me) { MPI_Status status; tw_event *e = NULL; int flag = 0; int changed = 0; while (posted_recvs.cur < read_buffer) { unsigned id = posted_recvs.cur; if(!(e = tw_event_grab(me))) { if(tw_gvt_inprogress(me)) tw_error(TW_LOC, "Out of events in GVT! Consider increasing --extramem"); return changed; } #if ROSS_MEMORY if( MPI_Irecv(posted_recvs.buffers[id], EVENT_SIZE(e), MPI_BYTE, MPI_ANY_SOURCE, EVENT_TAG, MPI_COMM_ROSS, &posted_recvs.req_list[id]) != MPI_SUCCESS) #else if( MPI_Irecv(e, (int)EVENT_SIZE(e), MPI_BYTE, MPI_ANY_SOURCE, EVENT_TAG, MPI_COMM_ROSS, &posted_recvs.req_list[id]) != MPI_SUCCESS) #endif { tw_event_free(me, e); return changed; } posted_recvs.event_list[id] = e; posted_recvs.cur++; changed = 1; } return changed; }
void tw_event_send(tw_event * event) { tw_lp *src_lp = event->src_lp; tw_pe *send_pe = src_lp->pe; tw_pe *dest_pe = NULL; tw_peid dest_peid = -1; tw_stime recv_ts = event->recv_ts; if (event == send_pe->abort_event) { if (recv_ts < g_tw_ts_end) { send_pe->cev_abort = 1; } return; } //Trap lookahead violations in debug mode //Note that compiling with the -DNDEBUG flag will turn this off! if (g_tw_synchronization_protocol == CONSERVATIVE) { if (recv_ts - tw_now(src_lp) < g_tw_lookahead) { tw_error(TW_LOC, "Lookahead violation: decrease g_tw_lookahead"); } } if (event->out_msgs) { tw_error(TW_LOC, "It is an error to send an event with pre-loaded output message."); } link_causality(event, send_pe->cur_event); // call LP remote mapping function to get dest_pe dest_peid = (*src_lp->type->map) ((tw_lpid) event->dest_lp); if (dest_peid == g_tw_mynode) { event->dest_lp = tw_getlocal_lp((tw_lpid) event->dest_lp); dest_pe = event->dest_lp->pe; if (send_pe == dest_pe && event->dest_lp->kp->last_time <= recv_ts) { /* Fast case, we are sending to our own PE and there is * no rollback caused by this send. We cannot have any * transient messages on local sends so we can return. */ tw_pq_enqueue(send_pe->pq, event); return; } else { /* Slower, but still local send, so put into top of * dest_pe->event_q. */ event->state.owner = TW_pe_event_q; tw_eventq_push(&dest_pe->event_q, event); if(send_pe != dest_pe) { send_pe->stats.s_nsend_loc_remote++; } } } else { /* Slowest approach of all; this is not a local event. * We need to send it over the network to the other PE * for processing. */ send_pe->stats.s_nsend_net_remote++; event->state.owner = TW_net_asend; tw_net_send(event); } if(tw_gvt_inprogress(send_pe)) { send_pe->trans_msg_ts = ROSS_MIN(send_pe->trans_msg_ts, recv_ts); } }
/** * @brief Determines how to handle the newly received event. * * @param[in] me pointer to PE * @param[in] e pointer to event that we just received * @param[in] buffer not currently used */ static void recv_finish(tw_pe *me, tw_event *e, char * buffer) { (void) buffer; tw_pe *dest_pe; tw_clock start; me->stats.s_nread_network++; me->s_nwhite_recv++; // printf("recv_finish: remote event [cancel %u] FROM: LP %lu, PE %lu, TO: LP %lu, PE %lu at TS %lf \n", // e->state.cancel_q, (tw_lpid)e->src_lp, e->send_pe, (tw_lpid)e->dest_lp, me->id, e->recv_ts); e->dest_lp = tw_getlocal_lp((tw_lpid) e->dest_lp); dest_pe = e->dest_lp->pe; // instrumentation e->dest_lp->kp->kp_stats->s_nread_network++; e->dest_lp->lp_stats->s_nread_network++; if(e->send_pe > tw_nnodes()-1) tw_error(TW_LOC, "bad sendpe_id: %d", e->send_pe); e->cancel_next = NULL; e->caused_by_me = NULL; e->cause_next = NULL; if(e->recv_ts < me->GVT) tw_error(TW_LOC, "%d: Received straggler from %d: %lf (%d)", me->id, e->send_pe, e->recv_ts, e->state.cancel_q); if(tw_gvt_inprogress(me)) me->trans_msg_ts = ROSS_MIN(me->trans_msg_ts, e->recv_ts); // if cancel event, retrieve and flush // else, store in hash table if(e->state.cancel_q) { tw_event *cancel = tw_hash_remove(me->hash_t, e, e->send_pe); // NOTE: it is possible to cancel the event we // are currently processing at this PE since this // MPI module lets me read cancel events during // event sends over the network. cancel->state.cancel_q = 1; cancel->state.remote = 0; cancel->cancel_next = dest_pe->cancel_q; dest_pe->cancel_q = cancel; tw_event_free(me, e); return; } if (g_tw_synchronization_protocol == OPTIMISTIC || g_tw_synchronization_protocol == OPTIMISTIC_DEBUG || g_tw_synchronization_protocol == OPTIMISTIC_REALTIME ) { tw_hash_insert(me->hash_t, e, e->send_pe); e->state.remote = 1; } /* NOTE: the final check in the if conditional below was added to make sure * that we do not execute the fast case unless the cancellation queue is * empty on the destination PE. Otherwise we need to invoke the normal * scheduling routines to make sure that a forward event doesn't bypass a * cancellation event with an earlier timestamp. This is helpful for * stateful models that produce incorrect results when presented with * duplicate messages with no rollback between them. */ if(me == dest_pe && e->dest_lp->kp->last_time <= e->recv_ts && !dest_pe->cancel_q) { /* Fast case, we are sending to our own PE and * there is no rollback caused by this send. */ start = tw_clock_read(); tw_pq_enqueue(dest_pe->pq, e); dest_pe->stats.s_pq += tw_clock_read() - start; return; } if (me->id == dest_pe->id) { /* Slower, but still local send, so put into top * of dest_pe->event_q. */ e->state.owner = TW_pe_event_q; tw_eventq_push(&dest_pe->event_q, e); return; } /* Never should happen; MPI should have gotten the * message to the correct node without needing us * to redirect the message there for it. This is * probably a serious bug with the event headers * not being formatted right. */ tw_error( TW_LOC, "Event recived by PE %u but meant for PE %u", me->id, dest_pe->id); }
static int recv_begin(tw_pe *me) { MPI_Status status; tw_event *e = NULL; int flag = 0; int changed = 0; while (posted_recvs.cur < read_buffer) { unsigned id = posted_recvs.cur; MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status); if(flag) { if(!(e = tw_event_grab(me))) { if(tw_gvt_inprogress(me)) tw_error(TW_LOC, "out of events in GVT!"); break; } } else { return changed; } #if ROSS_MEMORY if(!flag || MPI_Irecv(posted_recvs.buffers[id], EVENT_SIZE(e), MPI_BYTE, MPI_ANY_SOURCE, EVENT_TAG, MPI_COMM_WORLD, &posted_recvs.req_list[id]) != MPI_SUCCESS) #else if(!flag || MPI_Irecv(e, (int)EVENT_SIZE(e), MPI_BYTE, MPI_ANY_SOURCE, EVENT_TAG, MPI_COMM_WORLD, &posted_recvs.req_list[id]) != MPI_SUCCESS) #endif { tw_event_free(me, e); return changed; } posted_recvs.event_list[id] = e; posted_recvs.cur++; changed = 1; } return changed; }