Commit 0bb49c3c authored by Noah Wolfe's avatar Noah Wolfe
Browse files

Cleaned up code

parent 37676b1d
......@@ -32,7 +32,7 @@
//#define TRACK 100001
#define TRACK_MSG 0
#define TRACK_OUTPUT 1
#define DEBUG 1
#define DEBUG 0
#define DEBUG_ROUTING 0
#define USE_DIRECT_SCHEME 1
#define LOAD_FROM_FILE 0
......@@ -40,7 +40,7 @@
#define LP_CONFIG_NM (model_net_lp_config_names[SLIMFLY])
#define LP_METHOD_NM (model_net_method_names[SLIMFLY])
/* Begin Noah Visualization Piece */
/* Begin Visualization Piece */
#define TERMINAL_SENDS_RECVS_LOG 0
#define ROUTER_SENDS_RECVS_LOG 0
#define TERMINAL_OCCUPANCY_LOG 0
......@@ -63,9 +63,9 @@ int TEMP_RADIX;
int TEMP_NUM_VC;
int slim_total_routers_noah;
int slim_total_terminals_noah;
/* End Noah Visualization Piece */
/* End Visualization Piece */
/*Begin Noah Misc*/
/*Begin Misc*/
FILE * MMS_input_file=NULL;
int csf_ratio = 1; //Constant selected to balance the ratio between minimal and indirect routes
int num_indirect_routes = 4; //Number of indirect (Valiant) routes to use in Adaptive routing methods
......@@ -76,7 +76,7 @@ float pe_throughput = 0.0;
int *X;
int *X_prime;
int X_size;
/*End Noah Misc*/
/*End Misc*/
static double maxd(double a, double b) { return a < b ? b : a; }
......@@ -556,7 +556,6 @@ static void slimfly_read_config(const char * anno, slimfly_param *params){
for (size_t i = 0; i < length; i++)
{
X[i] = atoi(values[i]);
// printf("X[%d]:%d\n",i,X[i]);
}
free(values);
......@@ -571,7 +570,6 @@ static void slimfly_read_config(const char * anno, slimfly_param *params){
for (size_t i = 0; i < length; i++)
{
X_prime[i] = atoi(values[i]);
// printf("X_prime[%d]:%d\n",i,X_prime[i]);
}
free(values);
......@@ -596,8 +594,6 @@ static void slimfly_read_config(const char * anno, slimfly_param *params){
TEMP_NUM_VC = p->num_vcs;
// set the derived parameters
// p->num_cn = p->num_routers/2;
// p->num_global_channels = p->num_routers/2;
p->num_groups = p->num_routers * 2;
p->radix = (p->num_cn + p->num_global_channels + p->num_local_channels);
p->slim_total_routers = p->num_groups * p->num_routers;
......@@ -798,8 +794,7 @@ static void slimfly_report_stats()
}
/* initialize a slimfly compute node terminal */
void
slim_terminal_init( terminal_state * s,
void slim_terminal_init( terminal_state * s,
tw_lp * lp )
{
uint32_t h1 = 0, h2 = 0;
......@@ -827,9 +822,7 @@ slim_terminal_init( terminal_state * s,
s->anno, 0);
s->terminal_id = (mapping_rep_id * num_lps) + mapping_offset;
// s->router_id=(int)s->terminal_id / (s->params->num_routers/2);
s->router_id=(int)s->terminal_id / (num_lps);
//printf("lp_global_id:%d terminal_id:%d router_id:%d\n",(int)lp->gid,s->terminal_id,s->router_id);
s->terminal_available_time = 0.0;
s->packet_counter = 0;
......@@ -940,7 +933,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
}
#if LOAD_FROM_FILE
//slimfly added
//Load input MMS router and node layout/connection graph from file
char log[500];
sprintf( log, "simulation-input-files/MMS.%d/MMS.%d.%d.bsconf", p->num_global_channels+p->num_local_channels, p->num_global_channels+p->num_local_channels, p->num_cn);
......@@ -971,9 +963,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
temp = fscanf(MMS_input_file,"%s",one_word); // got one word from the file /
temp = fscanf(MMS_input_file,"%d",&one_number);
r->local_channel[i] = one_number;
//#if EVENT_LOG
// printf("local_channel[%d]:%d\n",i,r->local_channel[i]);
//#endif
}
//Set global router connections according to input MMS file
for(i=0;i<p->num_global_channels;i++)
......@@ -981,9 +970,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
temp = fscanf(MMS_input_file,"%s",one_word); // got one word from the file
temp = fscanf(MMS_input_file,"%d",&one_number);
r->global_channel[i] = one_number;
//#if EVENT_LOG
// printf("global_channel[%d]:%d\n",i,r->global_channel[i]);
//#endif
}
fclose(MMS_input_file);
......@@ -998,8 +984,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
int local_idx = 0;
int global_idx = 0;
int generator_size = X_size;
//printf("generator_size:%d\n",generator_size);
//printf("generator size:%d\n",generator_size);
for(rid_d=0;rid_d<r->params->slim_total_routers;rid_d++)
{
......@@ -1038,7 +1022,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
if(abs(j_s-j_d)==X[k])
{
r->local_channel[local_idx++] = rid_d;
// printf("router%d,router%d\n",rid_s,rid_d);
}
}
}
......@@ -1049,7 +1032,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
if(j_s == (i_d*i_s + j_d) % r->params->num_routers) // equation (3) y=mx+c
{
r->global_channel[global_idx++] = rid_d;
// printf("router%d,router%d\n",rid_s,rid_d);
}
}
}
......@@ -1092,7 +1074,6 @@ void slim_router_setup(router_state * r, tw_lp * lp)
if(abs(j_s-j_d)==X_prime[k])
{
r->local_channel[local_idx++] = rid_d;
// printf("router%d,router%d\n",rid_s,rid_d);
}
}
}
......@@ -1103,58 +1084,11 @@ void slim_router_setup(router_state * r, tw_lp * lp)
if(j_d == (i_s*i_d + j_s) % r->params->num_routers) // equation (3) y=mx+c
{
r->global_channel[global_idx++] = rid_d;
// printf("router%d,router%d\n",rid_s,rid_d);
}
}
}
#endif
#if DEBUG
// printf("\n LP ID %d VC occupancy radix %d Router %d group ID %d is connected to ", (int)lp->gid, p->radix, r->router_id, r->group_id);
#endif
//round the number of global channels to the nearest even number
/*#if USE_DIRECT_SCHEME
int first = r->router_id % p->num_routers;
for(int i=0; i < p->num_global_channels; i++)
{
int target_grp = first;
if(target_grp == r->group_id) {
target_grp = p->num_groups - 1;
}
int my_pos = r->group_id % p->num_routers;
if(r->group_id == p->num_groups - 1) {
my_pos = target_grp % p->num_routers;
}
r->global_channel[i] = target_grp * p->num_routers + my_pos;
first += p->num_routers;
}
#else
int router_offset = (r->router_id % p->num_routers) *
(p->num_global_channels / 2) + 1;
for(int i=0; i < p->num_global_channels; i++)
{
if(i % 2 != 0)
{
r->global_channel[i]=(r->router_id + (router_offset * p->num_routers))%p->slim_total_routers;
router_offset++;
}
else
{
r->global_channel[i]=r->router_id - ((router_offset) * p->num_routers);
}
if(r->global_channel[i]<0)
{
r->global_channel[i]=p->slim_total_routers+r->global_channel[i];
}
#if DEBUG == 1
printf("\n channel %d ", r->global_channel[i]);
#endif
}
#endif
*/
#if DEBUG == 1
// printf("\n");
#endif
return;
}
......@@ -1263,8 +1197,8 @@ tw_lpid slim_getRouterFromGroupID(int dest_gid,
}
/*When a packet is sent from the current router and a buffer slot becomes available, a credit is sent back to schedule another packet event*/
void slim_router_credit_send(router_state * s, tw_bf * bf, slim_terminal_message * msg,
tw_lp * lp, int sq) {
void slim_router_credit_send(router_state * s, tw_bf * bf, slim_terminal_message * msg, tw_lp * lp, int sq)
{
tw_event * buf_e;
tw_stime ts;
slim_terminal_message * buf_msg;
......@@ -1321,125 +1255,133 @@ void slim_router_credit_send(router_state * s, tw_bf * bf, slim_terminal_message
void slim_packet_generate_rc(terminal_state * s, tw_bf * bf, slim_terminal_message * msg, tw_lp * lp)
{
tw_rand_reverse_unif(lp->rng);
tw_rand_reverse_unif(lp->rng);
int num_chunks = msg->packet_size/s->params->chunk_size;
if(msg->packet_size % s->params->chunk_size)
num_chunks++;
int num_chunks = msg->packet_size/s->params->chunk_size;
if(msg->packet_size % s->params->chunk_size)
num_chunks++;
if(!num_chunks)
num_chunks = 1;
if(!num_chunks)
num_chunks = 1;
int i;
for(i = 0; i < num_chunks; i++) {
slim_delete_terminal_message_list(return_tail(s->terminal_msgs,
s->terminal_msgs_tail, 0));
s->terminal_length -= s->params->chunk_size;
}
if(bf->c5) {
codes_local_latency_reverse(lp);
s->in_send_loop = 0;
}
if(bf->c11) {
s->issueIdle = 0;
}
struct mn_stats* stat;
stat = model_net_find_stats(msg->category, s->slimfly_stats_array);
stat->send_count--;
stat->send_bytes -= msg->packet_size;
stat->send_time -= (1/s->params->cn_bandwidth) * msg->packet_size;
int i;
for(i = 0; i < num_chunks; i++)
{
slim_delete_terminal_message_list(return_tail(s->terminal_msgs,
s->terminal_msgs_tail, 0));
s->terminal_length -= s->params->chunk_size;
}
if(bf->c5)
{
codes_local_latency_reverse(lp);
s->in_send_loop = 0;
}
if(bf->c11)
{
s->issueIdle = 0;
}
struct mn_stats* stat;
stat = model_net_find_stats(msg->category, s->slimfly_stats_array);
stat->send_count--;
stat->send_bytes -= msg->packet_size;
stat->send_time -= (1/s->params->cn_bandwidth) * msg->packet_size;
}
/* generates packet at the current slimfly compute node */
void slim_packet_generate(terminal_state * s, tw_bf * bf, slim_terminal_message * msg,
tw_lp * lp) {
tw_stime ts, nic_ts;
void slim_packet_generate(terminal_state * s, tw_bf * bf, slim_terminal_message * msg, tw_lp * lp)
{
tw_stime ts, nic_ts;
assert(lp->gid != msg->dest_terminal_id);
const slimfly_param *p = s->params;
assert(lp->gid != msg->dest_terminal_id);
const slimfly_param *p = s->params;
int i, total_event_size;
int num_chunks = msg->packet_size / p->chunk_size;
if (msg->packet_size % s->params->chunk_size)
num_chunks++;
int i, total_event_size;
int num_chunks = msg->packet_size / p->chunk_size;
if (msg->packet_size % s->params->chunk_size)
num_chunks++;
if(!num_chunks)
num_chunks = 1;
if(!num_chunks)
num_chunks = 1;
nic_ts = g_tw_lookahead + s->params->cn_delay * msg->packet_size + tw_rand_unif(lp->rng);
msg->packet_ID = lp->gid + g_tw_nlp * s->packet_counter;
msg->my_N_hop = 0;
msg->my_l_hop = 0;
msg->my_g_hop = 0;
msg->intm_group_id = -1;
msg->intm_router_id = -1;
nic_ts = g_tw_lookahead + s->params->cn_delay * msg->packet_size + tw_rand_unif(lp->rng);
if(msg->packet_ID == TRACK)
printf("\x1B[34m-->Packet generated at terminal %d sending to router %d \x1b[0m\n", (int)lp->gid, s->router_id);
msg->packet_ID = lp->gid + g_tw_nlp * s->packet_counter;
msg->my_N_hop = 0;
msg->my_l_hop = 0;
msg->my_g_hop = 0;
msg->intm_group_id = -1;
msg->intm_router_id = -1;
for(i = 0; i < num_chunks; i++)
{
slim_terminal_message_list *cur_chunk = (slim_terminal_message_list*)malloc(
sizeof(slim_terminal_message_list));
slim_init_terminal_message_list(cur_chunk, msg);
if(msg->packet_ID == TRACK)
printf("\x1B[34m-->Packet generated at terminal %d sending to router %d \x1b[0m\n", (int)lp->gid, s->router_id);
if(msg->remote_event_size_bytes + msg->local_event_size_bytes > 0) {
cur_chunk->event_data = (char*)malloc(
msg->remote_event_size_bytes + msg->local_event_size_bytes);
}
void * m_data_src = model_net_method_get_edata(SLIMFLY, msg);
if (msg->remote_event_size_bytes){
memcpy(cur_chunk->event_data, m_data_src, msg->remote_event_size_bytes);
}
if (msg->local_event_size_bytes){
m_data_src = (char*)m_data_src + msg->remote_event_size_bytes;
memcpy((char*)cur_chunk->event_data + msg->remote_event_size_bytes,
m_data_src, msg->local_event_size_bytes);
}
for(i = 0; i < num_chunks; i++)
{
slim_terminal_message_list *cur_chunk = (slim_terminal_message_list*)malloc(
sizeof(slim_terminal_message_list));
slim_init_terminal_message_list(cur_chunk, msg);
cur_chunk->msg.chunk_id = i;
append_to_terminal_message_list(s->terminal_msgs, s->terminal_msgs_tail,
0, cur_chunk);
s->terminal_length += s->params->chunk_size;
}
if(msg->remote_event_size_bytes + msg->local_event_size_bytes > 0)
{
cur_chunk->event_data = (char*)malloc(
msg->remote_event_size_bytes + msg->local_event_size_bytes);
}
if(s->terminal_length < 2 * s->params->cn_vc_size) {
model_net_method_idle_event(nic_ts, 0, lp);
} else {
bf->c11 = 1;
s->issueIdle = 1;
}
if(s->in_send_loop == 0) {
bf->c5 = 1;
ts = codes_local_latency(lp);
slim_terminal_message *m;
tw_event* e = model_net_method_event_new(lp->gid, ts, lp, SLIMFLY,
(void**)&m, NULL);
m->type = T_SEND;
m->magic = slim_terminal_magic_num;
s->in_send_loop = 1;
tw_event_send(e);
}
void * m_data_src = model_net_method_get_edata(SLIMFLY, msg);
if (msg->remote_event_size_bytes)
{
memcpy(cur_chunk->event_data, m_data_src, msg->remote_event_size_bytes);
}
if (msg->local_event_size_bytes)
{
m_data_src = (char*)m_data_src + msg->remote_event_size_bytes;
memcpy((char*)cur_chunk->event_data + msg->remote_event_size_bytes,
m_data_src, msg->local_event_size_bytes);
}
total_event_size = model_net_get_msg_sz(SLIMFLY) +
msg->remote_event_size_bytes + msg->local_event_size_bytes;
mn_stats* stat;
stat = model_net_find_stats(msg->category, s->slimfly_stats_array);
stat->send_count++;
stat->send_bytes += msg->packet_size;
stat->send_time += (1/p->cn_bandwidth) * msg->packet_size;
if(stat->max_event_size < total_event_size)
stat->max_event_size = total_event_size;
cur_chunk->msg.chunk_id = i;
append_to_terminal_message_list(s->terminal_msgs, s->terminal_msgs_tail,
0, cur_chunk);
s->terminal_length += s->params->chunk_size;
}
return;
if(s->terminal_length < 2 * s->params->cn_vc_size)
{
model_net_method_idle_event(nic_ts, 0, lp);
}
else
{
bf->c11 = 1;
s->issueIdle = 1;
}
if(s->in_send_loop == 0)
{
bf->c5 = 1;
ts = codes_local_latency(lp);
slim_terminal_message *m;
tw_event* e = model_net_method_event_new(lp->gid, ts, lp, SLIMFLY,
(void**)&m, NULL);
m->type = T_SEND;
m->magic = slim_terminal_magic_num;
s->in_send_loop = 1;
tw_event_send(e);
}
total_event_size = model_net_get_msg_sz(SLIMFLY) +
msg->remote_event_size_bytes + msg->local_event_size_bytes;
mn_stats* stat;
stat = model_net_find_stats(msg->category, s->slimfly_stats_array);
stat->send_count++;
stat->send_bytes += msg->packet_size;
stat->send_time += (1/p->cn_bandwidth) * msg->packet_size;
if(stat->max_event_size < total_event_size)
stat->max_event_size = total_event_size;
return;
}
void slim_packet_send_rc(terminal_state * s, tw_bf * bf, slim_terminal_message * msg,
tw_lp * lp)
void slim_packet_send_rc(terminal_state * s, tw_bf * bf, slim_terminal_message * msg, tw_lp * lp)
{
if(bf->c1) {
s->in_send_loop = 1;
......@@ -1471,136 +1413,126 @@ void slim_packet_send_rc(terminal_state * s, tw_bf * bf, slim_terminal_message *
}
return;
}
/* sends the packet from the current slimfly compute node to the attached router */
void slim_packet_send(terminal_state * s, tw_bf * bf, slim_terminal_message * msg,
tw_lp * lp) {
tw_stime ts;
tw_event *e;
slim_terminal_message *m;
tw_lpid router_id;
tw_lp * lp)
{
tw_stime ts;
tw_event *e;
slim_terminal_message *m;
tw_lpid router_id;
slim_terminal_message_list* cur_entry = s->terminal_msgs[0];
slim_terminal_message_list* cur_entry = s->terminal_msgs[0];
if(s->vc_occupancy[0] + s->params->chunk_size > s->params->cn_vc_size
|| cur_entry == NULL) {
bf->c1 = 1;
s->in_send_loop = 0;
// printf("[%d] Skipping send %d %d\n", lp->gid, cur_entry == NULL,
// (s->vc_occupancy[0] + s->params->chunk_size > s->params->cn_vc_size));
return;
}
// printf("\n Packet %ld sent at time %lf ", cur_entry->msg.packet_ID, tw_now(lp));
msg->saved_available_time = s->terminal_available_time;
ts = g_tw_lookahead + s->params->cn_delay + tw_rand_unif(lp->rng);
s->terminal_available_time = maxd(s->terminal_available_time, tw_now(lp));
s->terminal_available_time += ts;
//TODO: be annotation-aware
codes_mapping_get_lp_info(lp->gid, lp_group_name, &mapping_grp_id, NULL,
&mapping_type_id, NULL, &mapping_rep_id, &mapping_offset);
codes_mapping_get_lp_id(lp_group_name, "slimfly_router", NULL, 1,
s->router_id, 0, &router_id);
// we are sending an event to the router, so no method_event here
e = tw_event_new(router_id, s->terminal_available_time - tw_now(lp), lp);
m = tw_event_data(e);
memcpy(m, &cur_entry->msg, sizeof(slim_terminal_message));
if (m->remote_event_size_bytes){
memcpy(model_net_method_get_edata(SLIMFLY, m), cur_entry->event_data,
m->remote_event_size_bytes);
}
if(s->vc_occupancy[0] + s->params->chunk_size > s->params->cn_vc_size
|| cur_entry == NULL)
{
bf->c1 = 1;
s->in_send_loop = 0;
return;
}
/*#if DEBUG
if( msg->message_id == TRACK && (int)lp->gid == 187 )
{
printf( "(%lf) [Terminal %d] packet_ID %lld message_ID %d is sending. ",tw_now(lp), (int)lp->gid, msg->packet_ID, msg->message_id);
msg->saved_available_time = s->terminal_available_time;
ts = g_tw_lookahead + s->params->cn_delay + tw_rand_unif(lp->rng);
s->terminal_available_time = maxd(s->terminal_available_time, tw_now(lp));
s->terminal_available_time += ts;
printf("travel start time is %f. magic %d", msg->travel_start_time, msg->magic);
//TODO: be annotation-aware
codes_mapping_get_lp_info(lp->gid, lp_group_name, &mapping_grp_id, NULL,
&mapping_type_id, NULL, &mapping_rep_id, &mapping_offset);
codes_mapping_get_lp_id(lp_group_name, "slimfly_router", NULL, 1,
s->router_id, 0, &router_id);
// we are sending an event to the router, so no method_event here
e = tw_event_new(router_id, s->terminal_available_time - tw_now(lp), lp);
m = tw_event_data(e);
memcpy(m, &cur_entry->msg, sizeof(slim_terminal_message));
if (m->remote_event_size_bytes)
{
memcpy(model_net_method_get_edata(SLIMFLY, m), cur_entry->event_data,
m->remote_event_size_bytes);
}
printf("My hop now is %d\n",msg->my_N_hop);
}
#endif
*/
m->origin_router_id = s->router_id;
m->type = R_ARRIVE;
m->src_terminal_id = lp->gid;
m->vc_index = 0;
m->last_hop = TERMINAL;
m->intm_group_id = -1;
m->intm_router_id = -1;
m->magic = slim_router_magic_num;
m->path_type = -1;
m->local_event_size_bytes = 0;
m->local_id = s->terminal_id;
tw_event_send(e);
m->origin_router_id = s->router_id;
m->type = R_ARRIVE;
m->src_terminal_id = lp->gid;
m->vc_index = 0;
m->last_hop = TERMINAL;
m->intm_group_id = -1;
m->intm_router_id = -1;
m->magic = slim_router_magic_num;
m->path_type = -1;
m->local_event_size_bytes = 0;
m->local_id = s->terminal_id;
tw_event_send(e);
#if DEBUG
if( m->packet_ID == TRACK)
{
printf( "(%lf) [Terminal %d] packet_ID %lld message_ID %d is sending. ",tw_now(lp), (int)lp->gid, m->packet_ID, (int)m->message_id);
printf("travel start time is %f. ", m->travel_start_time);
printf("My hop now is %d\n",m->my_N_hop);
}
if( m->packet_ID == TRACK)
{
printf( "(%lf) [Terminal %d] packet_ID %lld message_ID %d is sending. ",tw_now(lp), (int)lp->gid, m->packet_ID, (int)m->message_id);
printf("travel start time is %f. ", m->travel_start_time);
printf("My hop now is %d\n",m->my_N_hop);
}
#endif
int index = floor(N_COLLECT_POINTS*(tw_now(lp)/g_tw_ts_end));
int index = floor(N_COLLECT_POINTS*(tw_now(lp)/g_tw_ts_end));
#if TERMINAL_SENDS_RECVS_LOG
terminal_sends[s->terminal_id][index]++;
terminal_sends[s->terminal_id][index]++;
#endif
int num_chunks = cur_entry->msg.packet_size/s->params->chunk_size;
if(cur_entry->msg.packet_size % s->params->chunk_size)
num_chunks++;
int num_chunks = cur_entry->msg.packet_size/s->params->chunk_size;
if(cur_entry->msg.packet_size % s->params->chunk_size)
num_chunks++;
if(!num_chunks)
num_chunks = 1;
if(!num_chunks)
num_chunks = 1;
if(cur_entry->msg.chunk_id == num_chunks - 1 &&
(cur_entry->msg.local_event_size_bytes > 0)) {
bf->c2 = 1;
ts = codes_local_latency(lp);
tw_event *e_new = tw_event_new(cur_entry->msg.sender_lp, ts, lp);
slim_terminal_message* m_new = tw_event_data(e_new);
void *local_event = (char*)cur_entry->event_data +
cur_entry->msg.remote_event_size_bytes;
memcpy(m_new, local_event, cur_entry->msg.local_event_size_bytes);
tw_event_send(e_new);
}