void phold_init(phold_state * s, tw_lp * lp) { int i; if( stagger ) { for (i = 0; i < g_phold_start_events; i++) { tw_event_send( tw_event_new(lp->gid, tw_rand_exponential(lp->rng, mean) + lookahead + (tw_stime)(lp->gid % (unsigned int)g_tw_ts_end), lp)); } } else { for (i = 0; i < g_phold_start_events; i++) { tw_event_send( tw_event_new(lp->gid, tw_rand_exponential(lp->rng, mean) + lookahead, lp)); } } }
void traffic_light_intersection_startup(intersection_state* SV, tw_lp* LP) { tw_stime ts = 0; tw_event* current_event; message_data* new_message; // Initialize the total number of cars arrived: SV->total_cars_arrived = 0; SV->total_cars_finished = 0; // Initialize the number of cars arriving into the intersection: SV->num_cars_south = 0; SV->num_cars_west = 0; SV->num_cars_north = 0; SV->num_cars_east = 0; SV->num_cars_south_left = 0; SV->num_cars_west_left = 0; SV->num_cars_north_left = 0; SV->num_cars_east_left = 0; SV->north_south_green_until = -1; SV->north_south_left_green_until = -1; SV->east_west_green_until = -1; SV->east_west_left_green_until = -1; // Initialize a random direction to be green SV->traffic_direction = tw_rand_ulong(LP->rng, NORTH_SOUTH, EAST_WEST_LEFT); // Schedule the first light change current_event = tw_event_new(LP->gid, ts, LP); new_message = (message_data*)tw_event_data(current_event); new_message->event_type = LIGHT_CHANGE; tw_event_send(current_event); // Put cars on the road int i; for(i = 0; i < g_traffic_start_events; i++) { // Arrival time ts = tw_rand_exponential(LP->rng, INITIAL_ARRIVAL_MEAN); current_event = tw_event_new(LP->gid, ts, LP); new_message = (message_data*)tw_event_data(current_event); new_message->event_type = CAR_ARRIVES; assign_rand_dest: new_message->car.x_to_go = tw_rand_integer(LP->rng, -MAX_TRAVEL_DISTANCE, MAX_TRAVEL_DISTANCE); new_message->car.y_to_go = tw_rand_integer(LP->rng, -MAX_TRAVEL_DISTANCE, MAX_TRAVEL_DISTANCE); new_message->car.x_to_go_original = new_message->car.x_to_go; new_message->car.y_to_go_original = new_message->car.y_to_go; if (new_message->car.y_to_go == 0) new_message->car.has_turned = 1; else new_message->car.has_turned = 0; new_message->car.start_time = tw_now(LP); tw_event_send(current_event); } }
void Airport_EventHandler(Airport_State *SV, tw_bf *CV, Msg_Data *M, tw_lp *lp) { tw_stime ts; tw_event *CurEvent; Msg_Data *NewM; *(int *)CV = (int)0; switch(M->event_type) { case ARRIVAL: // Schedule a landing in the future SV->InTheAir++; if((CV->c1 = (SV->RunwayFree == 1))){ SV->RunwayFree = 0; ts = tw_rand_exponential(lp->id, R); CurEvent = tw_event_new(lp, ts, lp); NewM = (Msg_Data *)tw_event_data(CurEvent); NewM->event_type = LAND; tw_event_send(CurEvent); } break; case LAND: SV->InTheAir--; SV->OnTheGround++; SV->NumLanded++; ts = tw_rand_exponential(lp->id, G); CurEvent = tw_event_new(lp, ts, lp); NewM = (Msg_Data *)tw_event_data(CurEvent); NewM->event_type = DEPARTURE; tw_event_send(CurEvent); if ((CV->c1 = (SV->InTheAir > 0))){ ts = tw_rand_exponential(lp->id, R); CurEvent = tw_event_new(lp, ts, lp); NewM = (Msg_Data *)tw_event_data(CurEvent); NewM->event_type = LAND; tw_event_send(CurEvent); } else SV->RunwayFree = 1; break; case DEPARTURE: SV->OnTheGround--; ts = tw_rand_exponential(lp->id, A); CurEvent = tw_event_new(tw_getlp((lp->id + 1) % 3) , ts, lp); NewM = (Msg_Data *) tw_event_data(CurEvent); NewM->event_type = ARRIVAL; tw_event_send(CurEvent); break; } }
void mem_init(mem_state * s, tw_lp * lp) { tw_event *e; tw_memory *b; int i; for (i = 0; i < g_mem_start_events; i++) { e = tw_event_new(lp->gid, tw_rand_exponential(lp->rng, mean), lp); for(i = 0; i < nbufs; i++) { b = mem_alloc(lp); mem_fill(b); tw_event_memory_set(e, b, my_fd); s->stats.s_mem_alloc++; } tw_event_send(e); s->stats.s_sent++; } }
int ForwardPacket (tw_lp * srcLp, tw_lp * dstLp, Packet * p, tw_stime t) { tw_event * e; EventMsg * em; double now = tw_now (dstLp); if (t + now >= g_tw_ts_end) return 0; /* Otherwise the program will exit when * creating event */ #ifdef DEBUG_PKT_FWD printf ("%lf : pkt(%d:%lu) from %d to %d (in-port %d) at %lf\n", tw_now (srcLp), _addrToIdx[p->srcAddr_], p->od_.sqn_, srcLp->id, dstLp->id, p->inPort_, now + t); fflush (stdout); #endif if ((e = tw_event_new (dstLp, t, dstLp)) == NULL) { printf ("Failed to create event for packet.\n"); tw_exit (-1); } (em = (EventMsg *) tw_event_data (e))->type_ = DATA_PKT; memcpy ((void *) &(em->content_.pkt_), (void *) p, sizeof (Packet)); tw_event_send (e); return 1; }
/*Sends a 8-byte credit back to the torus node LP that sent the message */ void credit_send( nodes_state * s, tw_bf * bf, tw_lp * lp, nodes_message * msg) { //if(lp->gid == TRACK_LP) // printf("\n (%lf) sending credit tmp_dir %d tmp_dim %d %lf ", tw_now(lp), msg->source_direction, msg->source_dim, credit_delay ); tw_event * buf_e; nodes_message *m; tw_stime ts; int src_dir = msg->source_direction; int src_dim = msg->source_dim; msg->saved_available_time = s->next_credit_available_time[(2 * src_dim) + src_dir][0]; s->next_credit_available_time[(2 * src_dim) + src_dir][0] = max(s->next_credit_available_time[(2 * src_dim) + src_dir][0], tw_now(lp)); ts = credit_delay + tw_rand_exponential(lp->rng, credit_delay/1000); s->next_credit_available_time[(2 * src_dim) + src_dir][0] += ts; buf_e = tw_event_new( msg->sender_lp, s->next_credit_available_time[(2 * src_dim) + src_dir][0] - tw_now(lp), lp); m = tw_event_data(buf_e); m->source_direction = msg->source_direction; m->source_dim = msg->source_dim; m->type = CREDIT; tw_event_send( buf_e ); }
void packet_buffer_process( nodes_state * s, tw_bf * bf, nodes_message * msg, tw_lp * lp ) { msg->wait_loc = -1; s->buffer[ msg->source_direction + ( msg->source_dim * 2 ) ][ 0 ]-=1; tw_event * e_h; nodes_message * m; tw_stime ts; bf->c3 = 0; int loc=s->wait_count, j=0; for(j = 0; j < loc; j++) { if( s->waiting_list[j].dim == msg->source_dim && s->waiting_list[j].dir == msg->source_direction) { bf->c3=1; ts = tw_rand_exponential(lp->rng, MEAN_INTERVAL/100); e_h = tw_event_new( lp->gid, ts, lp ); m = tw_event_data( e_h ); memcpy(m, s->waiting_list[j].packet, sizeof(nodes_message)); // For reverse computation, also copy data to the msg memcpy(msg, s->waiting_list[j].packet, sizeof(nodes_message)); msg->wait_loc = j; msg->type = CREDIT; m->type = SEND; tw_event_send(e_h); waiting_packet_free(s, j); break; } } }
/* * Create and send new boundary particle */ tw_event * rm_particle_send(tw_lpid gid, tw_stime offset, tw_lp * src_lp) { tw_event *e; //tw_memory *b; rm_message *m; //rm_particle *p; //printf("%ld: sending particle to cell %ld \n", src_lp->id, gid); if(gid == 0) tw_error(TW_LOC, "here"); e = tw_event_new(gid, offset, src_lp); m = tw_event_data(e); m->type = RM_PARTICLE; #if DWB b = tw_memory_alloc(src_lp, g_rm_fd); tw_event_memory_set(e, b, g_rm_fd); p = tw_memory_data(b); p->user_lp = src_lp; #endif tw_event_send(e); return e; }
void torus_init(nodes_state * s, tw_lp * lp) { tw_event *e; tw_stime ts; nodes_message *m; /* * Set up the initial state for each LP (node) * according to the number of dimensions */ torus_setup(s, lp); /* * Start a GENERATE event on each LP */ //ts = tw_rand_exponential(lp->rng, MEAN_INTERVAL); ts = tw_rand_exponential(lp->rng, 10); int i; for(i=0;i<N_nodes;i++) { e = tw_event_new(lp->gid, ts, lp); m = tw_event_data(e); m->type = GENERATE; m->next_stop = i; m->dest_lp = lp->gid; tw_event_send(e); } }
void event_handler(ping_pong_state * s, tw_bf * bf, ping_pong_message * in_m, tw_lp * lp) { tw_stime ts; tw_event *e; ping_pong_message *m; int dest=0; ts=1; // if(g_tw_mynode == 0) if(lp->gid == 0) { dest = 1; } // else if (g_tw_mynode == 1) else if (lp->gid == 1) { dest = 0; } else { cout<<"invalid core number"<<endl; assert(false); } e = tw_event_new(dest, ts, lp); m = (ping_pong_message *)tw_event_data(e); tw_event_send(e); }
/* * epi_agent_send: create new event, and pack on the agent membuf and * associated pathogen membufs */ void epi_agent_send(tw_lp * src, tw_memory * buf, tw_stime offset, tw_lpid dst) { tw_event *e; tw_memory *b; tw_memory *next; epi_agent *a; e = tw_event_new(dst, 0.0, src); a = tw_memory_data(buf); printf("%lld: Sending agent to %lld (%d, %lld) at %lf\n", src->id, dst, a->curr, a->loc[a->curr], tw_now(src)); // place agent membuf on event, and pack pathogen membufs on after that // in case this event/agent is sent over the network. for(next = b = a->pathogens; b; b = next) { next = b->next; tw_event_memory_set(e, b, g_epi_pathogen_fd); } tw_event_memory_set(e, buf, g_epi_fd); a->pathogens = NULL; tw_event_send(e); }
/** * Initializer for OLSR */ void olsr_init(node_state *s, tw_lp *lp) { hello *h; tw_event *e; olsr_msg_data *msg; tw_stime ts; //s->num_tuples = 0; s->num_neigh = 0; s->num_two_hop = 0; s->local_address = lp->gid; s->lng = tw_rand_unif(lp->rng) * GRID_MAX; s->lat = tw_rand_unif(lp->rng) * GRID_MAX; ts = tw_rand_unif(lp->rng) * STAGGER_MAX; e = tw_event_new(lp->gid, ts, lp); msg = tw_event_data(e); msg->type = HELLO_TX; msg->originator = s->local_address; msg->lng = s->lng; msg->lat = s->lat; h = &msg->mt.h; h->num_neighbors = 0; //h->neighbor_addrs[0] = s->local_address; tw_event_send(e); }
void cont_create_process( CON_state* s, tw_bf* bf, MsgData* msg, tw_lp* lp ) { tw_event * e; tw_stime ts; MsgData * m; #ifdef TRACE printf("create %d process at controller travel time is %lf\n", msg->message_CN_source, tw_now(lp) - msg->travel_start_time ); #endif ts = CONT_CONT_msg_prep_time; e = tw_event_new( lp->gid, ts , lp ); m = tw_event_data(e); m->event_type = CREATE_ACK; m->travel_start_time = msg->travel_start_time; m->io_offset = msg->io_offset; m->io_payload_size = msg->io_payload_size; m->collective_group_size = msg->collective_group_size; m->collective_group_rank = msg->collective_group_rank; m->collective_master_node_id = msg->collective_master_node_id; m->io_type = msg->io_type; m->message_ION_source = msg->message_ION_source; m->message_FS_source = msg->message_FS_source; m->message_CN_source = msg->message_CN_source; m->io_tag = msg->io_tag; tw_event_send(e); }
void wifi_station_arrival(wifi_access_point_state * s, tw_bf * bf, wifi_message * m, tw_lp * lp) { unsigned int rng_calls=0; tw_event *e=NULL; wifi_message *m_new=NULL; // packets coming from access point have much more power and so better snr s->stations[m->station].total_packets++; s->stations[m->station].station_snr = tw_rand_normal_sd(lp->rng,4.0,8.0, &rng_calls); // New Function - to add prop loss, but not ready yet. //s->stations[m->station].station_snr = calcRxPower (txPowerDbm, distance, minDistance, lambda, systemLoss); s->stations[m->station].station_success_rate = WiFi_80211b_DsssDqpskCck11_SuccessRate(s->stations[m->station].station_snr, num_of_bits); if( tw_rand_normal_sd(lp->rng,0.5,0.1, &rng_calls) < s->stations[m->station].station_success_rate) { bf->c1 = 1; s->stations[m->station].failed_packets++; } // schedule event back to AP w/ exponential service time e = tw_event_new(lp->gid, tw_rand_exponential(lp->rng, 10.0), lp); m_new = (wifi_message *) tw_event_data(e); m_new->type = WIFI_PACKET_ARRIVAL_AT_ACCESS_POINT; m_new->station = m->station; tw_event_send(e); }
void mem_event_handler(mem_state * s, tw_bf * bf, mem_message * m, tw_lp * lp) { tw_lpid dest; tw_event *e; tw_memory *b; int i; s->stats.s_recv++; // read membufs off inbound event, check it and free it for(i = 0; i < nbufs; i++) { b = tw_event_memory_get(lp); if(!b) tw_error(TW_LOC, "Missing memory buffers: %d of %d", i+1, nbufs); mem_verify(b); tw_memory_free(lp, b, my_fd); s->stats.s_mem_free++; s->stats.s_mem_get++; } if(tw_rand_unif(lp->rng) <= percent_remote) { bf->c1 = 1; dest = tw_rand_integer(lp->rng, 0, ttl_lps - 1); dest += offset_lpid; if(dest >= ttl_lps) dest -= ttl_lps; } else { bf->c1 = 0; dest = lp->gid; } e = tw_event_new(dest, tw_rand_exponential(lp->rng, mean), lp); // allocate membufs and attach them to the event for(i = 0; i < nbufs; i++) { b = mem_alloc(lp); if(!b) tw_error(TW_LOC, "no membuf allocated!"); mem_fill(b); tw_event_memory_set(e, b, my_fd); s->stats.s_mem_alloc++; } tw_event_send(e); }
// Helpers void raid_controller_gen_send( tw_lpid dest, Event event_type, tw_stime event_time, tw_lp* lp ) { // Generate and send message to dest tw_event* event = tw_event_new( dest, event_time, lp ); MsgData* message = (MsgData*)tw_event_data( event ); message->event_type = event_type; tw_event_send( event ); }
void tmr_event_handler(tmr_state * s, tw_bf * bf, tmr_message * m, tw_lp * lp) { tw_lpid dest; * (int *) bf = 0; if(s->timer) { // if current event being processed is the timer if(tw_event_data(s->timer) == m) { bf->c1 = 1; m->old_timer = s->timer; s->timer = NULL; fprintf(f, "%lld: tmr fired at %lf\n", lp->gid, tw_now(lp)); return; } else { bf->c2 = 1; m->old_time = s->timer->recv_ts; tw_timer_reset(lp, &s->timer, tw_now(lp) + 100.0); if(s->timer == NULL) fprintf(f, "%lld: reset tmr failed %lf\n", lp->gid, tw_now(lp) + 100.0); else fprintf(f, "%lld: reset tmr to %lf\n", lp->gid, tw_now(lp) + 100.0); } } if(tw_rand_unif(lp->rng) <= percent_remote) { bf->c3 = 1; dest = tw_rand_integer(lp->rng, 0, ttl_lps - 1); dest += offset_lpid; if(dest >= ttl_lps) dest -= ttl_lps; } else { bf->c3 = 0; dest = lp->gid; } if(!lp->gid) dest = 0; tw_event_send(tw_event_new(dest, tw_rand_exponential(lp->rng, mean), lp)); }
void lsm_io_event( const char * lp_io_category, uint64_t io_object, int64_t io_offset, uint64_t io_size_bytes, int io_type, tw_stime delay, tw_lp *sender, struct codes_mctx const * map_ctx, int return_tag, msg_header const * return_header, struct codes_cb_info const * cb) { assert(strlen(lp_io_category) < CATEGORY_NAME_MAX-1); assert(strlen(lp_io_category) > 0); SANITY_CHECK_CB(cb, lsm_return_t); tw_lpid lsm_id = codes_mctx_to_lpid(map_ctx, LSM_NAME, sender->gid); tw_stime delta = delay + codes_local_latency(sender); if (lsm_in_sequence) { tw_stime tmp = lsm_msg_offset; lsm_msg_offset += delta; delta += tmp; } tw_event *e = tw_event_new(lsm_id, delta, sender); lsm_message_t *m = tw_event_data(e); m->magic = lsm_magic; m->event = (lsm_event_t) io_type; m->data.object = io_object; m->data.offset = io_offset; m->data.size = io_size_bytes; strcpy(m->data.category, lp_io_category); // get the priority count for checking int num_prios = lsm_get_num_priorities(map_ctx, sender->gid); // prio checks and sets if (num_prios <= 0) // disabled scheduler - ignore m->data.prio = 0; else if (temp_prio < 0) // unprovided priority - defer to max possible m->data.prio = num_prios-1; else if (temp_prio < num_prios) // valid priority m->data.prio = temp_prio; else tw_error(TW_LOC, "LP %lu, LSM LP %lu: Bad priority (%d supplied, %d lanes)\n", sender->gid, lsm_id, temp_prio, num_prios); // reset temp_prio temp_prio = -1; m->cb.info = *cb; m->cb.h = *return_header; m->cb.tag = return_tag; tw_event_send(e); }
/** * Forward event handler for SRW. Supported operations are currently: * - GPS * - MOVEMENT * - COMMUNICATION */ void srw_event(srw_state *s, tw_bf *bf, srw_msg_data *m, tw_lp *lp) { tw_stime ts; tw_event *e; srw_msg_data *msg; switch(m->type) { case GPS: // Schedule next event e = tw_event_new(lp->gid, SRW_GPS_RATE, lp); msg = tw_event_data(e); msg->node_id = m->node_id; msg->type = GPS; tw_event_send(e); break; case MOVEMENT: s->movements++; (s->nodes[m->node_id]).movements++; // Schedule next event ts = tw_rand_exponential(lp->rng, SRW_MOVE_MEAN); e = tw_event_new(lp->gid, ts, lp); msg = tw_event_data(e); msg->node_id = m->node_id; msg->type = MOVEMENT; tw_event_send(e); break; case COMMUNICATION: s->comm_try++; (s->nodes[m->node_id]).comm_try++; // Schedule next event ts = tw_rand_exponential(lp->rng, SRW_COMM_MEAN); e = tw_event_new(lp->gid, ts, lp); msg = tw_event_data(e); msg->node_id = m->node_id; msg->type = COMMUNICATION; tw_event_send(e); break; } }
static void st_create_sample_event(tw_lp *lp) { if (tw_now(lp) + g_st_vt_interval <= g_st_sampling_end) { tw_event *e = tw_event_new(lp->gid, g_st_vt_interval, lp); analysis_msg *m = (analysis_msg*) tw_event_data(e); m->src = lp->gid; tw_event_send(e); } }
void packet_process(nodes_state * s, tw_bf * bf, nodes_message * msg, tw_lp * lp) { int i; tw_event *e; nodes_message *m; bf->c3 = 1; // One packet leaves the queue s->node_queue_length[msg->source_direction][msg->source_dim]--; s->N_wait_to_be_processed--; if(lp->gid==msg->dest_lp) { // one packet arrives and dies bf->c3 = 0; N_finished++; int index = floor(N_COLLECT_POINTS*(tw_now(lp)/g_tw_ts_end)); N_finished_storage[index]++; total_time += tw_now(lp) - msg->travel_start_time; if (max_latency<tw_now(lp) - msg->travel_start_time) max_latency=tw_now(lp) - msg->travel_start_time; total_hops += msg->my_N_hop; total_queue_length += msg->my_N_queue; queueing_times_sum += msg->queueing_times; //total_queue_length += msg->accumulate_queue_length; } else { e = tw_event_new(lp->gid, MEAN_PROCESS, lp); m = tw_event_data(e); m->type = SEND; // Carry on the message info for( i = 0; i < N_dims; i++ ) m->dest[i] = msg->dest[i]; m->dest_lp = msg->dest_lp; m->transmission_time = msg->transmission_time; m->source_dim = msg->source_dim; m->source_direction = msg->source_direction; m->packet_ID = msg->packet_ID; m->travel_start_time = msg->travel_start_time; m->my_N_hop = msg->my_N_hop; m->my_N_queue = msg->my_N_queue; m->queueing_times = msg->queueing_times; tw_event_send(e); } }
//Init function // - called once for each LP // ! LP can only send messages to itself during init ! void decrement_init (decrement_state *s, tw_lp *lp) { int self = lp->gid; // init state data s->decrement_value = 1; s->round_count = 0; // Init message to myself tw_event *e = tw_event_new(self, 2, lp); message *msg = tw_event_data(e); msg->type = WAKEUP; tw_event_send(e); }
/* Trigger getting next event at LP */ static void codes_issue_next_event(tw_lp* lp) { tw_event *e; nw_message* msg; tw_stime ts; ts = g_tw_lookahead + 0.1 + tw_rand_exponential(lp->rng, noise); e = tw_event_new( lp->gid, ts, lp ); msg = tw_event_data(e); msg->msg_type = MPI_OP_GET_NEXT; tw_event_send(e); }
void packet_send(nodes_state * s, tw_bf * bf, nodes_message * msg, tw_lp * lp) { int i; tw_lpid dst_lp; tw_stime ts; tw_event *e; nodes_message *m; ts = LINK_DELAY+msg->transmission_time; /* * Routing in the torus, start from the first dimension */ if (lp->gid != msg->dest_lp ) { bf->c3 = 1; dimension_order_routing(s,msg,&dst_lp); msg->source_dim = s->source_dim; msg->source_direction = s->direction; } else { bf->c3 = 0; dst_lp = lp->gid; } e = tw_event_new(dst_lp, ts, lp); m = tw_event_data(e); m->type = ARRIVAL; // Carry on the message info for( i = 0; i < N_dims; i++ ) m->dest[i] = msg->dest[i]; m->dest_lp = msg->dest_lp; m->transmission_time = msg->transmission_time; m->source_dim = msg->source_dim; m->source_direction = msg->source_direction; m->packet_ID = msg->packet_ID; m->travel_start_time = msg->travel_start_time; m->my_N_hop = msg->my_N_hop; m->my_N_queue = msg->my_N_queue; m->queueing_times = msg->queueing_times; tw_event_send(e); }
//Forward event handler void decrement_event (decrement_state *s, tw_bf *bf, message *in_msg, tw_lp *lp) { int self = lp->gid; if (in_msg->type != WAKEUP) { tw_error(TW_LOC, "Decrement LP received wrong message type"); } s->round_count++; int i; for (i = 0; i < total_receivers; i++) { tw_event *e = tw_event_new(i+2, 1, lp); message *msg = tw_event_data(e); msg->type = DECREMENT; msg->value = s->decrement_value; tw_event_send(e); } // Wakeup self tw_event *e = tw_event_new(self, 2, lp); message *msg = tw_event_data(e); msg->type = WAKEUP; tw_event_send(e); }
void Intersection_StartUp(Intersection_State *SV, tw_lp * lp) { //printf("begin init\n"); int i; tw_event *CurEvent; tw_stime ts; Msg_Data *NewM; SV->total_cars_arrived = 0; SV->total_cars_finished = 0; SV->num_in_west_left = 0; SV->num_in_west_straight = 0; SV->num_in_west_right = 0; SV->num_in_north_left = 0; SV->num_in_north_straight = 0; SV->num_in_north_right = 0; SV->num_in_south_left = 0; SV->num_in_south_straight = 0; SV->num_in_south_right = 0; SV->num_in_east_left = 0; SV->num_in_east_straight = 0; SV->num_in_east_right = 0; SV->num_out_west_left = 0; SV->num_out_west_straight = 0; SV->num_out_west_right = 0; SV->num_out_north_left = 0; SV->num_out_north_straight = 0; SV->num_out_north_right = 0; SV->num_out_south_left = 0; SV->num_out_south_straight = 0; SV->num_out_south_right = 0; SV->num_out_east_left = 0; SV->num_out_east_straight = 0; SV->num_out_east_right = 0; for(i = 0; i < g_traffic_start_events; i++) { ts = tw_rand_exponential(lp->rng, MEAN_SERVICE ); CurEvent = tw_event_new(lp->gid, ts, lp); NewM = (Msg_Data *)tw_event_data(CurEvent); NewM->event_type = ARIVAL; NewM->car.x_to_go = rand() % 200 - 99; NewM->car.y_to_go = rand() % 200 - 99; NewM->car.current_lane = rand() % 12; NewM->car.sent_back = 0; NewM->car.in_out = IN; tw_event_send(CurEvent); } }
//Init function // - called once for each LP // ! LP can only send messages to itself during init ! void model_init (state *s, tw_lp *lp) { int self = lp->gid; // init state data s->rcvd_count_H = 0; s->rcvd_count_G = 0; s->value = -1; // Init message to myself tw_event *e = tw_event_new(self, 1, lp); message *msg = tw_event_data(e); msg->type = HELLO; msg->contents = tw_rand_unif(lp->rng); msg->sender = self; tw_event_send(e); }
/* * The event being processed that caused this function to be * called is a user model event. Therefore, I cannot use it * for state saving. Solution: create my own event and send * it with a 0.0 offset timestamp. */ void tlm_wave_initiate(double * position, double signal, tw_lp * lp) { tw_lpid gid = tlm_getcell(position); tw_event *e; tlm_message *m; e = tw_event_new(gid, g_tlm_scatter_ts, lp); m = tw_event_data(e); m->type = RM_WAVE_INIT; m->displacement = signal; m->id = lp->gid; tw_event_send(e); }
/* initialize MPI process LP */ void mpi_init( mpi_process * p, tw_lp * lp) { tw_event *e; tw_stime ts; nodes_message *m; p->message_counter = 0; /* Start a MPI send event on each MPI LP */ ts = tw_rand_exponential(lp->rng, MEAN_INTERVAL); e = tw_event_new( lp->gid, ts, lp ); m = tw_event_data( e ); m->type = MPI_SEND; p->available_time = 0.0; tw_event_send( e ); }
void phold_pre_run(phold_state * s, tw_lp * lp) { tw_lpid dest; if(tw_rand_unif(lp->rng) <= percent_remote) { dest = tw_rand_integer(lp->rng, 0, ttl_lps - 1); } else { dest = lp->gid; } if(dest >= (g_tw_nlp * tw_nnodes())) tw_error(TW_LOC, "bad dest"); tw_event_send(tw_event_new(dest, tw_rand_exponential(lp->rng, mean) + lookahead, lp)); }