Beispiel #1
0
	/*
	 * This function provides the Reactive Model with a post-simulation 'main'
	 */
void
tlm_md_final()
{
	if(!tw_ismaster())
		return;

	if(!g_rn_environment)
		return;

	fprintf(g_tlm_output_f, "\nTransmission Line Matrix Model: Statistics: \n");
#if DWB
#if SAVE_MEM
	fprintf(g_tlm_output_f, "\tRange Statistics: \n");
	fprintf(g_tlm_output_f, "\t\t%-42s %11ld\n", "Range Particles Received", 
						g_tlm_stats->s_nparticles);
#endif
#endif
	fprintf(g_tlm_output_f, "\tWave Statistics: \n\n");
	fprintf(g_tlm_output_f, "\t\t%-42s %11lld\n", "Initiate", 
						g_tlm_stats->s_ncell_initiate);
	fprintf(g_tlm_output_f, "\t\t%-42s %11lld\n", "Scatters", 
						g_tlm_stats->s_ncell_scatter);
	fprintf(g_tlm_output_f, "\t\t%-42s %11lld\n", "Gathers", 
						g_tlm_stats->s_ncell_gather);


	if(g_tlm_output_f != stdout)
		fclose(g_tlm_output_f);

	//fclose(g_tlm_waves_plt_f);
	//fclose(g_tlm_nodes_plt_f);
	//fclose(g_tlm_parts_plt_f);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    int i;
    
    g_tw_events_per_pe = nlp_per_pe * nlp_per_pe * 1;
    
    tw_opt_add(olsr_opts);
    
    tw_init(&argc, &argv);
    
    tw_define_lps(nlp_per_pe, sizeof(olsr_msg_data), 0);
    
    for (i = 0; i < g_tw_nlp; i++) {
        tw_lp_settype(i, &olsr_lps[0]);
    }
    
    tw_run();
    
    if (tw_ismaster()) {
        printf("Complete.\n");
    }
    
    tw_end();
    
    return 0;
}
Beispiel #3
0
static void
match_opt(const char *arg)
{
    const char *eq = strchr(arg + 2, '=');
    const tw_optdef **group = all_groups;

    for (; *group; group++)
    {
        const tw_optdef *def = *group;
        for (; def->type; def++)
        {
            if (!def->name || def->type == TWOPTTYPE_GROUP)
                continue;
            if (!eq && !strcmp(def->name, arg + 2))
            {
                apply_opt(def, NULL);
                return;
            }
            else if (eq && !strncmp(def->name, arg + 2, eq - arg - 2))
            {
                apply_opt(def, eq + 1);
                return;
            }
        }
    }

    if (tw_ismaster())
        fprintf(stderr,
                "%s: option '%s' not recognized; see --help for details\n",
                program, arg);
    tw_net_stop();
    exit(1);
}
Beispiel #4
0
void tw_end(void) {
    if(tw_ismaster()) {
        fprintf(g_tw_csv, "\n");
        fclose(g_tw_csv);
    }

    tw_net_stop();
}
Beispiel #5
0
void tw_init(int *argc, char ***argv) {
    int i;
#if HAVE_CTIME
    time_t raw_time;
#endif

    tw_opt_add(tw_net_init(argc, argv));

    // Print out the command-line so we know what we passed in
    if (tw_ismaster()) {
        for (i = 0; i < *argc; i++) {
            printf("%s ", (*argv)[i]);
        }
        printf("\n\n");
    }

    // Print our revision if we have it
#ifdef ROSS_VERSION
    if (tw_ismaster()) {
#if HAVE_CTIME
        time(&raw_time);
        printf("%s\n", ctime(&raw_time));
#endif
        printf("ROSS Revision: %s\n\n", ROSS_VERSION);
    }
#endif

    tw_opt_add(kernel_options);
    tw_opt_add(tw_gvt_setup());
    tw_opt_add(tw_clock_setup());
#ifdef USE_RIO
    tw_opt_add(io_opts);
#endif

    // by now all options must be in
    tw_opt_parse(argc, argv);

    if(tw_ismaster() && NULL == (g_tw_csv = fopen("ross.csv", "a"))) {
        tw_error(TW_LOC, "Unable to open: ross.csv\n");
    }

    tw_opt_print();

    tw_net_start();
    tw_gvt_start();
}
Beispiel #6
0
static void
need_argument(const tw_optdef *def)
{
    if (tw_ismaster())
        fprintf(stderr,
                "%s: option --%s requires a valid argument\n",
                program, def->name);
    tw_net_stop();
    exit(1);
}
Beispiel #7
0
void
tw_end(void)
{
	if(tw_ismaster())
	{
		fprintf(g_tw_csv, "\n");
		fclose(g_tw_csv);
	}

	tw_net_stop();

	// print end event array marker and end json file marker 
	fputs("]\n}\n", desTraceFile);
	fclose(desTraceFile);
}
Beispiel #8
0
void
tw_opt_print(void)
{
    FILE *f = g_tw_csv;
    const tw_optdef **group = all_groups;

    if(!tw_ismaster() || NULL == f)
        return;

    for (; *group; group++)
    {
        const tw_optdef *def = *group;
        for (; def->type; def++)
        {
            if (def->type == TWOPTTYPE_GROUP ||
                    (def->name && 0 == strcmp(def->name, "help")))
                continue;

            if (def->value)
            {
                switch (def->type)
                {
                case TWOPTTYPE_ULONG:
                    fprintf(f, "%lu,", *((unsigned long*)def->value));
                    break;

                case TWOPTTYPE_UINT:
                    fprintf(f, "%u,", *((unsigned int*)def->value));
                    break;

                case TWOPTTYPE_STIME:
                    fprintf(f, "%.2f,", *((tw_stime*)def->value));
                    break;

                case TWOPTTYPE_CHAR:
                    fprintf(f, "%s,", (char *)def->value);
                    break;

                default:
                    break;
                }
            } else
                fprintf(f, "undefined,");
        }
    }

    //print_options(f);
}
Beispiel #9
0
void
epi_model_final()
{
    int	 i;

    for(i = 0; i < g_epi_ndiseases; i++)
        if(g_epi_log_f && g_epi_log_f[i])
            fclose(g_epi_log_f[i]);

    if(!tw_ismaster())
        return;

    printf("\nPandemic Flu Initial State Variables: \n");
    printf("\n");
    printf("\t%-50s %11d\n", "Total Population", g_epi_nagents);
    printf("\t%-50s\n", "Initial Sick Populations:");

    for(i = 0; i < g_epi_ndiseases; i++)
        printf("\t\tDisease %-40d %5d\n", i, g_epi_sick_init_pop[i]);

    printf("\t%-50s %11d\n", "Initial Worried Well Pop", g_epi_ww_init_pop);
    printf("\t%-50s %11d\n", "Initial Work While Sick Pop", g_epi_wws_init_pop);
    printf("\n");
    printf("\nEPI Statistics: \n");
    printf("\t%-50s %11.4lf\n", "Initial Infection Prob", g_epi_sick_rate);
    printf("\t%-50s %11.4lf\n", "Initial Worried Well Prob", g_epi_ww_rate);
    printf("\t%-50s %11.4lf\n", "Initial Work While Sick Prob", g_epi_wws_rate);
    printf("\n");
    printf("\t%-50s\n", "Initial Infection Populations:");

    for(i = 0; i < g_epi_ndiseases; i++)
        printf("\t\tDisease %-40d %5d\n", i, g_epi_sick_init_pop[i]);

    printf("\t%-50s %11d\n", "Initial Worried Well Population", g_epi_ww_init_pop);
    printf("\t%-50s %11d\n", "Initial Work While Sick Population", g_epi_wws_init_pop);
    printf("\n");
    printf("\t%-50s %11d\n", "Ttl Number of Infected Agents", g_epi_stats->s_ninfected);
    printf("\t%-50s %11d\n", "Ttl Number of Dead Agents", g_epi_stats->s_ndead);
    printf("\n");

#if 0
    printf("\t%-50s %11ld\n", "Ttl Move Events", g_epi_stats->s_move_ev);
    printf("\t%-50s %11ld\n", "Ttl Agents Checked for Infection", g_epi_stats->s_nchecked);
    printf("\t%-50s %11ld\n", "Ttl Draws from Uniform Random Distribution", g_epi_stats->s_ndraws);
#endif
}
Beispiel #10
0
void
rp_md_init(int argc, char ** argv, char ** env)
{
	int	 nbufs;

	g_rp_stats = tw_calloc(TW_LOC, "", sizeof(*g_rp_stats), 1);

	nbufs = 1000000 / g_tw_nkp;
	nbufs = 10000 / g_tw_nkp;

	g_rp_fd = tw_memory_init(nbufs, sizeof(rp_message), 1);

	if(tw_ismaster())
	{
		printf("\nInitializing Model: Random Walk\n");
		printf("\t%-50s %11d (%ld)\n", 
			"Membufs Allocated", nbufs, g_rp_fd);
	}
}
Beispiel #11
0
/**
 * If the global variable g_rn_tools_dir is set, look for the xml
 * topology, link topology, and routing table configuration in that
 * directory.  Should not interfere with NetDMF configuration regardless
 * of the value of g_rn_tools_dir
 */
void
rn_setup()
{
	if(0 != strcmp(g_rn_tools_dir, ""))
	{
		char * dir = g_rn_tools_dir;
		sprintf(g_rn_xml_topology, "tools/%s/%s.xml", dir, dir);
		sprintf(g_rn_rt_table, "tools/%s/%s.rt", dir, dir);
		sprintf(g_rn_xml_link_topology, "tools/%s/links.xml", dir);
		//sprintf(g_rn_xml_model, "tools/%s/model.xml", dir);

		if(tw_ismaster())
		{
			printf("Opening config file: %s \n", g_rn_xml_topology);
			printf("Opening link file: %s \n", g_rn_xml_link_topology);
			printf("Opening routing table file: %s \n", g_rn_rt_table);
		}
	}
}
Beispiel #12
0
void
ip_md_init(int argc, char ** argv, char ** env)
{
	//int	 i;

	char	 log[1024];

	g_ip_stats = tw_calloc(TW_LOC, "", sizeof(ip_stats), 1);

	// in secs..
	g_ip_minor_interval = 60;
	g_ip_major_interval = 86400;

	tw_opt_add(ip_opts);

	if(g_ip_log_on)
	{
		sprintf(log, "%s/ip.log", g_rn_logs_dir);
		g_ip_log = fopen(log, "w");

		if(!g_ip_log)
			tw_error(TW_LOC, "Unable to open: %s \n", log);
	}

#if 0
	for(i = 0; i < g_tw_nkp; i++)
		g_ip_fd = tw_kp_memory_init(tw_getkp(i), 1000000, sizeof(ip_message), 1);
#endif

	ip_routing_init();

	if(tw_ismaster())
	{
		printf("\nInitializing Model: IPv4\n");
#if 0
		printf("\t%-50s %11d (%ld)\n", 
			"IP Membufs", 1000000, g_ip_fd);
#endif
	}
}
Beispiel #13
0
void
ip_md_final()
{
	if(!tw_ismaster())
		return;

	printf("\nIP Model Statistics:\n\n");
	printf("\t%-50s %11ld \n", "Total Packets Completed", g_ip_stats->s_ncomplete);
	printf("\t%-50s %11ld \n", "Total Packets Dropped", g_ip_stats->s_ndropped);
	printf("\t%-50s %11ld \n", "Packets Dropped at Source", 
		g_ip_stats->s_ndropped_source);
	printf("\t%-50s %11ld \n", "Packets Dropped (TTL)", g_ip_stats->s_ndropped_ttl);
	printf("\t%-50s %11ld \n", "Packets Dropped by Network Failure", 
		g_ip_stats->s_nnet_failures);
	printf("\t%-50s %11ld \n", "Packets Forwarded", g_ip_stats->s_nforward);
	printf("\n");
	printf("\t%-50s %11d \n", "Packet Avg TTL", 
		g_ip_stats->s_avg_ttl ? 
			(int) (g_ip_stats->s_avg_ttl / g_ip_stats->s_ncomplete) :
			(int) g_ip_stats->s_avg_ttl);
	printf("\t%-50s %11ld \n", "Packet Max TTL", g_ip_stats->s_max_ttl);
}
Beispiel #14
0
void
tcp_finalize()
{
    struct Tcp_Statistics  stats;
    // START HERE -- fix!!
//    if(MPI_Reduce(&(g_tcp_stats.bad_msgs),
//                  &stats,
//                  8,
//                  MPI_LONG_LONG,
//                  MPI_SUM,
//                  g_tw_masternode,
//                  MPI_COMM_WORLD) != MPI_SUCCESS)
//        tw_error(TW_LOC, "TCP Final: unable to reduce statistics");
    
        if(MPI_Reduce(&(g_tcp_stats.throughput),
                      &(stats.throughput),
                      3,
                      MPI_DOUBLE,
                      MPI_SUM,
                      g_tw_masternode,
                      MPI_COMM_WORLD) != MPI_SUCCESS)
            tw_error(TW_LOC, "TCP Final: unable to reduce statistics");
            
            if(!tw_ismaster())
                return;
    
    printf("\nTCP Model Statistics: \n\n");
    printf("\t%-50s %11ld\n", "Sent Packets", stats.sent_packets);
    printf("\t%-50s %11ld\n", "Recv Packets", stats.received_packets);
//    printf("\t%-50s %11lld\n", "Sent ACKs", stats.ack_sent);
//    printf("\t%-50s %11lld\n", "Recv ACKs", stats.ack_recv);
//    printf("\t%-50s %11lld\n", "Invalid ACKs", stats.ack_invalid);
    printf("\t%-50s %11ld\n", "TimeOut Packets", stats.timedout_packets);
    printf("\t%-50s %11ld\n", "Drop Packets", stats.dropped_packets);
    printf("\t%-50s %11.4lf Kbps\n", "Total Throughput", stats.throughput);
}
Beispiel #15
0
void
rp_md_final()
{
	if(!tw_ismaster())
		return;

	printf("\nRandom Walk Model Statistics: \n\n");
	printf("\t%-50s %11.2lf\n", "Waves Percentage", percent_wave);
	printf("\t%-50s %11lld\n", "Number of Waves", g_rp_stats->s_nwaves);
	printf("\t%-50s %11lld\n", "Number of Moves", g_rp_stats->s_move_ev);

#if 0
	printf("\t%-50s %11ld\n", "Ttl PROX Events", g_rp_stats->s_prox_ev);
	printf("\t%-50s %11ld\n", "Ttl Recv Events", g_rp_stats->s_recv_ev);
	printf("\n");

	printf("PM Connections:\n\n");
	printf("\t%-42s %11ld\n", "Ttl Direct Conns",
						g_rp_stats->s_nconnect);
	printf("\t%-42s %11ld\n", "Ttl Direct Disconnects",
						g_rp_stats->s_ndisconnect);
	printf("\n");
#endif
}
Beispiel #16
0
void
mem_stats_print()
{
    mem_statistics	 stats;

    if(MPI_Reduce(&(g_stats.s_rb),
                  &(stats.s_rb),
                  9,
                  MPI_LONG_LONG,
                  MPI_SUM,
                  g_tw_masternode,
                  MPI_COMM_WORLD) != MPI_SUCCESS)
        tw_error(TW_LOC, "TCP Final: unable to reduce statistics");

    if(!tw_ismaster())
        return;

    printf("\nMemory Model Statistics:\n");
    printf("\n");
    printf("\t%-50s %11lld\n", "Total Rollbacks", stats.s_rb);
    printf("\t%-50s %11lld\n", "Total Events Sent", stats.s_sent);
    printf("\t%-50s %11lld\n", "Total Events Recv", stats.s_recv);
    printf("\n");
    printf("\t%-50s %11lld\n", "Total Allocated", stats.s_mem_alloc);
    printf("\t%-50s %11lld\n", "Total Allocated RC", stats.s_mem_alloc_rc);
    printf("\t%-50s %11lld\n", "NET Allocated", stats.s_mem_alloc - stats.s_mem_alloc_rc);
    printf("\n");
    printf("\t%-50s %11lld\n", "Total Freed", stats.s_mem_free);
    printf("\t%-50s %11lld\n", "Total Freed RC", stats.s_mem_free_rc);
    printf("\t%-50s %11lld *\n", "NET Freed", stats.s_mem_free - stats.s_mem_free_rc);
    printf("\n");
    printf("\t%-50s %11lld\n", "Total Gets", stats.s_mem_get);
    printf("\t%-50s %11lld\n", "Total Gets RC", stats.s_mem_get_rc);
    printf("\t%-50s %11lld *\n", "NET Gets", stats.s_mem_get - stats.s_mem_get_rc);
    printf("\n");
}
Beispiel #17
0
int srw_main(int argc, char *argv[])
{
  int i;
  int num_lps_per_pe = 1;

  tw_opt_add(srw_opts);

  /* This configures g_tw_npe */
  tw_init(&argc, &argv);

  /* Must call this to properly set g_tw_nlp */
  tw_define_lps(num_lps_per_pe, sizeof(srw_msg_data), 0);

#ifdef WITH_NETDMF
  /* IF we ARE using NETDMF... */

  if (!strcmp("", netdmf_config)) {
    /* AND we DO NOT have a config file */

    /* There is no NetDMF configuration file.  Create a scenario with fake
     * data, i.e. no changes are required: fake data is created by default */
    for (i = 0; i < g_tw_nlp; i++) {
      tw_lp_settype(i, &srw_lps[0]);
    }
    printf("No NetDMF configuration specified.\n");
  }
  else {
    /* OR we DO have a config file */

    /* Must repeatedly call this to copy the function pointers appropriately */
    for (i = 0; i < g_tw_nlp; i++) {
      tw_lp_settype(i, &netdmf_srw_lps[0]);
    }
    /* Read in the netdmf_config file.  This must be done after
     * we set up the LPs (via tw_lp_settype) so we have data
     * to configure. */
    for (i = 0; i < g_tw_npe; i++) {
      tw_pe_settype(g_tw_pe[i], &srw_pes[0]);
    }
  }
#else /* WITH_NETDMF */
  /* WE are NOT using NETDMF */

  /* Must repeatedly call this to copy the function pointers appropriately */
  for (i = 0; i < g_tw_nlp; i++) {
    tw_lp_settype(i, &srw_lps[0]);
  }
#endif /* WITH_NETDMF */

  tw_run();

  if (tw_ismaster()) {
    printf("Total radios in simulation:    %d\n", total_radios);
    printf("Total movements:               %d\n", total_movements);
    printf("Total communcation failures:   %d\n", total_fail);
    printf("Total communcation attempts:   %d\n", total_comm);
    printf("Total communication successes: %d\n", total_comm - total_fail);
    printf("Node %d moved the most:        %d\n", top_node, top_move);
  }

  tw_end();

  return 0;
}
Beispiel #18
0
/* 
 * This function creates and setups the g_rn_machines global data structure of nodes
 */
void
rn_xml_topology()
{
	xmlXPathObjectPtr	obj;

	xmlNodePtr		node;

	unsigned int		i;
	//unsigned int		j;
	unsigned int		id;
	unsigned int		size;

	rn_as			*as;
	rn_area			*ar;
	rn_subnet		*sn;
	rn_machine		*m;

	size = 0;

	/* Environment */
	obj = xpath("//environment", ctxt);
	if(obj->nodesetval->nodeTab)
		g_rn_environment = *obj->nodesetval->nodeTab;
	xmlXPathFreeObject(obj);

	/* ASes */
	obj = xpath("/rossnet/as", ctxt);
	g_rn_nas = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nas > 0)
	{
		g_rn_as = (rn_as *) tw_calloc(TW_LOC, "", sizeof(rn_as), g_rn_nas);
		size += sizeof(rn_as) * g_rn_nas;
	}

	node = obj->nodesetval->nodeTab[0];
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		g_rn_as[i].low = -1;
		g_rn_as[i].id = atoi(xml_getprop(node, "id"));	
		//g_rn_as[i].frequency = atoi(xml_getprop(node, "frequency"));	

#if WASTE_MEM
		if(0 == strcmp(xml_getprop(node, "name"), "name"))
			g_rn_as[i].name = (char *) xmlStrdup((xmlChar *) xml_getprop(node, "name"));
#endif

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	/* Areas */
	obj = xpath("/rossnet/as/area", ctxt);
	g_rn_nareas = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nareas > 0)
	{
		g_rn_areas = (rn_area *) tw_calloc(TW_LOC, "", sizeof(rn_area), g_rn_nareas);
		size += sizeof(rn_area) * g_rn_nareas;
	}

	node = obj->nodesetval->nodeTab[0];
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		//g_rn_areas[i].root = INT_MAX;
		//g_rn_areas[i].root_lvl = 0xff;
		g_rn_areas[i].low = INT_MAX;
		g_rn_areas[i].id = atoi(xml_getprop(node, "id"));	
		g_rn_areas[i].as = &g_rn_as[atoi(xml_getprop(node->parent, "id"))];

		if(g_rn_areas[i].as->areas == NULL)
			g_rn_areas[i].as->areas = &g_rn_areas[i];

		if(i > 0 && g_rn_areas[i-1].as->id == g_rn_areas[i].as->id)
			g_rn_areas[i-1].next = &g_rn_areas[i];

		g_rn_areas[i].as->nareas++;

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	/* Subnets */
	obj = xpath("/rossnet/as/area/subnet", ctxt);
	g_rn_nsubnets = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nsubnets > 0)
	{
		g_rn_subnets = (rn_subnet *) tw_calloc(TW_LOC, "", sizeof(rn_subnet), g_rn_nsubnets);
		size += sizeof(rn_subnet) * g_rn_nsubnets;
	}

	node = *obj->nodesetval->nodeTab;
	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		g_rn_subnets[i].low = INT_MAX;
		g_rn_subnets[i].id = atoi(xml_getprop(node, "id"));	
		g_rn_subnets[i].area = &g_rn_areas[atoi(xml_getprop(node->parent, "id"))];

		if(g_rn_subnets[i].area->subnets == NULL)
			g_rn_subnets[i].area->subnets = &g_rn_subnets[i];

		if(i > 0 && g_rn_subnets[i-1].area->id == g_rn_subnets[i].area->id)
			g_rn_subnets[i-1].next = &g_rn_subnets[i];

		g_rn_subnets[i].area->nsubnets++;

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	/* Machines */
	obj = xpath("//node", ctxt);
	g_rn_nmachines = xmlXPathNodeSetGetLength(obj->nodesetval);	

	if(g_rn_nmachines)
	{
		g_rn_machines = tw_calloc(TW_LOC, "machines", 
					  sizeof(rn_machine), 
					  g_rn_nmachines);
		size += sizeof(rn_machine) * g_rn_nmachines;
	} else
		tw_error(TW_LOC, "No machines found in XML!");

	g_tw_nlp = ceil((double) obj->nodesetval->nodeNr / (double) tw_nnodes());

	node = *obj->nodesetval->nodeTab;

	for(i = 0; i < obj->nodesetval->nodeNr; )
	{
		id = atoi(xml_getprop(node, "id"));

		m = rn_getmachine(id);
		m->xml = node;
		m->conn = -1;
		m->id = id;
		m->nlinks = atoi(xml_getprop(node, "links"));	
		//m->level = atoi(xml_getprop(node, "lvl"));
		m->subnet = &g_rn_subnets[atoi(xml_getprop(node->parent, "id"))];

		if(0 != strcmp("", xml_getprop(node, "uid")))
			m->uid = atoi(xml_getprop(node, "uid"));
		else
			m->uid = -1;

		if(strcmp("c_router", xml_getprop(node, "type")) == 0)
		{
			m->type = c_router;
			g_rn_nrouters++;
		} else if(strcmp("c_ct_router", xml_getprop(node, "type")) == 0)
		{
			m->type = c_ct_router;
			g_rn_nrouters++;
		} else if(strcmp("c_og_router", xml_getprop(node, "type")) == 0)
		{
			m->type = c_og_router;
			g_rn_nrouters++;
		} else if(strcmp("c_co_router", xml_getprop(node, "type")) == 0)
		{
			m->type = c_co_router;
			g_rn_nrouters++;
		} else if(strcmp("c_ha_router", xml_getprop(node, "type")) == 0)
		{
			m->type = c_ha_router;
			g_rn_nrouters++;
		} else if(strcmp("c_host", xml_getprop(node, "type")) == 0)
			m->type = c_host;
		else
			tw_error(TW_LOC, "Unknown node type: %s", xml_getprop(node, "type"));

		if(m->subnet->machines == NULL)
			m->subnet->machines = &g_rn_machines[i];

#if 0
		if(id > 0 && 
		   g_rn_machines[id-1].subnet->id == g_rn_machines[id].subnet->id)
			g_rn_machines[id-1].next = &g_rn_machines[id];
#endif

		m->subnet->nmachines++;
		m->subnet->area->nmachines++;
		m->link = (rn_link *) tw_calloc(TW_LOC, "", sizeof(rn_link) * m->nlinks, 1);
		m->hash_link = rn_hash_create(m->nlinks);

		size += sizeof(rn_link) * m->nlinks;

		//printf("Init\'ing Machines id: %d \n", m->id);

		node = obj->nodesetval->nodeTab[++i];
	}

	xmlXPathFreeObject(obj);

	xml_link_topology();

	/*
	 * Set up the global connection library
	 */
	obj = xpath("//connect", ctxt);

	if(obj->nodesetval->nodeNr)
	{
		node = *obj->nodesetval->nodeTab;

		for(i = 0; i < obj->nodesetval->nodeNr; )
		{
			m = rn_getmachine(atoll(xml_getprop(node, "src")));
			m->conn = atoll(xml_getprop(node, "dst"));

			// back link the connection
			//rn_getmachine(m->conn)->conn = m->id;

			node = obj->nodesetval->nodeTab[++i];
		}
	}

	xmlXPathFreeObject(obj);

	for(i = 0; i < g_rn_nmachines; i++)
	{
		m = rn_getmachine(i);

		sn = m->subnet;
		ar = sn->area;
		as = ar->as;

		if(i < sn->low)
		{
			sn->low = i;

			if(i < ar->low)
			{
				ar->low = i;

				if(0 && i < as->low)
					as->low = i;
			}
		}

		if(i > sn->high)
		{
			sn->high = i;

			if(i > ar->high)
			{
				ar->high = i;

				if(0 && i > as->high)
					as->high = i;
			}
		}

		if(m->type == c_host)
			continue;

		ar->g_ospf_nlsa = ar->nmachines + ar->as->nareas + g_rn_nas;

		if(ar->nmachines == 0)
			tw_error(TW_LOC, "No machines in Area %d!\n", ar->id);

#if 0
		m->ft = (int *) tw_calloc(TW_LOC, "", sizeof(int ) * ar->g_ospf_nlsa, 1);
		size += sizeof(int) * ar->g_ospf_nlsa;

		for(j = 0; j < ar->g_ospf_nlsa; j++)
			m->ft[j] = -1;
#endif

/*
		printf("mach %d: alloc FT of size: %d \n", 
			i, ar->nmachines + as->nareas + g_rn_nas);
*/
	}

	ar = NULL;
	as = NULL;
	while(NULL != (as = rn_nextas(as)))
	{
		while(NULL != (ar = rn_nextarea_onas(ar, as)))
		{
			if(as->low == -1)
				as->low = ar->id;
			as->high = ar->id;
		}

		//printf("AS %d: low %ld, high %ld \n", as->id, as->low, as->high);
	}

#if RN_XML_DEBUG || 1
	if(tw_ismaster())
	{
		printf("\n");
		printf("%-32s %11d \n", "ASes: ", g_rn_nas);
		printf("%-32s %11d \n", "Areas: ", g_rn_nareas);
		printf("%-32s %11d \n", "Subnets: ", g_rn_nsubnets);
		printf("%-32s %11d \n", "Machines: ", g_rn_nmachines);
		printf("%-32s %11d \n", "Links: ", g_rn_nlinks);
		printf("%-32s %11d bytes\n", "Total topology size: ", size);
		printf("\n");
	}
#endif

	//verify_topology();
}
Beispiel #19
0
int olsr_main(int argc, char *argv[])
{
    int i;
    char log[32];

    tw_opt_add(olsr_opts);
    tw_init(&argc, &argv);

#if DEBUG
    sprintf( log, "olsr-log.%ld", g_tw_mynode );

    olsr_event_log = fopen( log, "w+");
    if( olsr_event_log == nullptr )
        tw_error( TW_LOC, "Failed to Open OLSR Event Log file \n");
#endif

    g_tw_mapping = CUSTOM;
    g_tw_custom_initial_mapping = &olsr_custom_mapping;
    g_tw_custom_lp_global_to_local_map = &olsr_mapping_to_lp;

    // nlp_per_pe = OLSR_MAX_NEIGHBORS;// / tw_nnodes();
    //g_tw_lookahead = SA_INTERVAL;

    SA_range_start = nlp_per_pe;

    // Increase nlp_per_pe by nlp_per_pe / OMN
    nlp_per_pe += nlp_per_pe / OLSR_MAX_NEIGHBORS;

    g_tw_events_per_pe =  OLSR_MAX_NEIGHBORS / 2 * nlp_per_pe  + 65536;
    tw_define_lps(nlp_per_pe, sizeof(olsr_msg_data));

    for(i = 0; i < OLSR_END_EVENT; i++)
        g_olsr_event_stats[i] = 0;

    for (i = 0; i < SA_range_start; i++) {
        tw_lp_settype(i, &olsr_lps[0]);
    }

    for (i = SA_range_start; i < nlp_per_pe; i++) {
        tw_lp_settype(i, &olsr_lps[1]);
    }

#if DEBUG
    printf("g_tw_nlp is %llu\n", g_tw_nlp);
#endif

    tw_run();

    if( g_tw_synchronization_protocol != 1 )
    {
        MPI_Reduce( g_olsr_event_stats, g_olsr_root_event_stats, OLSR_END_EVENT, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
    }
    else {
        for (i = 0; i < OLSR_END_EVENT; i++) {
            g_olsr_root_event_stats[i] = g_olsr_event_stats[i];
        }
    }

    if (tw_ismaster()) {
        for( i = 0; i < OLSR_END_EVENT; i++ )
            printf("OLSR Type %s Event Count = %llu \n", event_names[i], g_olsr_root_event_stats[i]);
        printf("Complete.\n");
    }

    tw_end();

    return 0;
}
Beispiel #20
0
static void
apply_opt(const tw_optdef *def, const char *value)
{
    switch (def->type)
    {
    case TWOPTTYPE_ULONG:
    case TWOPTTYPE_UINT:
    {
        unsigned long v;
        char *end;

        if (!value)
            need_argument(def);
        v = strtoul(value, &end, 10);
        if (*end)
            need_argument(def);
        switch (def->type)
        {
        case TWOPTTYPE_ULONG:
            *((unsigned long*)def->value) = v;
            break;
        case TWOPTTYPE_UINT:
            *((unsigned int*)def->value) = (unsigned int)v;
            break;
        default:
            tw_error(TW_LOC, "Option type not supported here.");
        }
        break;
    }

    case TWOPTTYPE_STIME:
    {
        tw_stime v;
        char *end;

        if (!value)
            need_argument(def);
        v = strtod(value, &end);
        if (*end)
            need_argument(def);
        *((tw_stime*)def->value) = v;
        break;
    }

    case TWOPTTYPE_CHAR:
    {
        if (!value)
            need_argument(def);

        //*((char **)def->value) = tw_calloc(TW_LOC, "string arg", strlen(value) + 1, 1);
        strcpy(def->value, value);
        break;
    }

    case TWOPTTYPE_SHOWHELP:
        if (tw_ismaster())
            show_help();
        tw_net_stop();
        exit(0);
        break;

    default:
        tw_error(TW_LOC, "Option type not supported here.");
    }
}
Beispiel #21
0
void
tw_init(int *argc, char ***argv)
{
        int i;
#if HAVE_CTIME
        time_t raw_time;
#endif

	// setup trace file and print header information */
	desTraceFile = fopen("desTraceFile.json", "w+");
	
	fprintf(desTraceFile, "{\n\"simulator_name\" : \"ROSS Revision: %s ", ROSS_VERSION);
        fprintf(desTraceFile, "(github version, forked on on June 21, 2014)\",\n");
	
	fprintf(desTraceFile, "\"model_name\" : \"");
	des_print_model_name();
	fprintf(desTraceFile, "\",\n");
	
	// capture the current date/timestamp
	time_t current_time;
	time(&current_time);
        char *ascii_time = ctime(&current_time);
	fprintf(desTraceFile, "\"capture_date\" : \"%.*s\",\n", strlen(ascii_time)-1, ascii_time);

	tw_opt_add(tw_net_init(argc, argv));

	// capture command line arguments
	fprintf(desTraceFile, "\"command_line_arguments\" : \"");

        // Print out the command-line so we know what we passed in
	if (tw_ismaster()) {
	        for (i = 0; i < *argc; i++) {
	                printf("%s ", (*argv)[i]);
			// record command line arguments in desTraceFile
	                fprintf(desTraceFile, " %s ", (*argv)[i]);
	        }
	        printf("\n");
	}
    
	// setup entry for capturing events exchanged in the simulation.
	fprintf(desTraceFile,"\",\n\"events\" : [");
	separator = " ";

    // Print our revision if we have it
#ifdef ROSS_VERSION
    if (tw_ismaster()) {
#if HAVE_CTIME
        time(&raw_time);
        printf("%s\n", ctime(&raw_time));
#endif
        printf("ROSS Revision: %s\n\n", ROSS_VERSION);
    }
#endif

	tw_opt_add(kernel_options);
	tw_opt_add(tw_gvt_setup());
	tw_opt_add(tw_clock_setup());

	// by now all options must be in
	tw_opt_parse(argc, argv);

	if(tw_ismaster() && NULL == (g_tw_csv = fopen("ross.csv", "a")))
		tw_error(TW_LOC, "Unable to open: ross.csv\n");

	tw_opt_print();

	tw_net_start();
	tw_gvt_start();

	//tw_register_signals();
}
int main( int argc, char** argv )
{
  int rank, nprocs;
  int num_nets;
  int* net_ids;

  g_tw_ts_end = s_to_ns(60*60*24*365); /* one year, in nsecs */

  workload_type[0]='\0';
  tw_opt_add(app_opt);
  tw_init(&argc, &argv);

  if(strlen(workload_file) == 0)
    {
	if(tw_ismaster())
		printf("\n Usage: mpirun -np n ./codes-nw-test --sync=1/2/3 --workload_type=type --workload_file=workload-file-name");
	tw_end();
	return -1;
    }

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

   configuration_load(argv[2], MPI_COMM_WORLD, &config);

   nw_add_lp_type();

   codes_mapping_setup();

   num_net_lps = codes_mapping_get_lp_count("MODELNET_GRP", 0, "nw-lp", NULL, 0);
   
    tw_run();

    long long total_bytes_sent, total_bytes_recvd;
    double avg_run_time;
    double avg_comm_run_time;
    double avg_col_run_time;
    double total_avg_send_time;
    double total_avg_wait_time;
    double total_avg_recv_time;
    double total_avg_col_time;
    double total_avg_comp_time;
    long overall_sends, overall_recvs, overall_waits, overall_cols;
	
    MPI_Reduce(&num_bytes_sent, &total_bytes_sent, 1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
    MPI_Reduce(&num_bytes_recvd, &total_bytes_recvd, 1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&avg_time, &avg_run_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

   MPI_Reduce(&avg_recv_time, &total_avg_recv_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&avg_comm_time, &avg_comm_run_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&avg_col_time, &avg_col_run_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
  MPI_Reduce(&avg_wait_time, &total_avg_wait_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&avg_send_time, &total_avg_send_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&avg_compute_time, &total_avg_comp_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&total_sends, &overall_sends, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&total_recvs, &overall_recvs, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&total_waits, &overall_waits, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
   MPI_Reduce(&total_collectives, &overall_cols, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);

   if(!g_tw_mynode)
	printf("\n Total bytes sent %lld recvd %lld \n avg runtime %lf \n avg comm time %lf avg compute time %lf \n avg collective time %lf avg send time %lf \n avg recv time %lf \n avg wait time %lf \n total sends %ld total recvs %ld total waits %ld total collectives %ld ", total_bytes_sent, total_bytes_recvd, 
			avg_run_time/num_net_lps,
			avg_comm_run_time/num_net_lps,
			total_avg_comp_time/num_net_lps,
			total_avg_col_time/num_net_lps,
			total_avg_send_time/num_net_lps,
			total_avg_recv_time/num_net_lps,
			total_avg_wait_time/num_net_lps,
			overall_sends, overall_recvs, overall_waits, overall_cols);
   tw_end();
  
  return 0;
}
Beispiel #23
0
int
main(int argc, char **argv, char **env)
{
	int i;
	num_buf_slots = vc_size / chunk_size;
	tw_opt_add(app_opt);
	tw_init(&argc, &argv);

	if(strcmp(traffic_str, "uniform") == 0)
	    TRAFFIC = UNIFORM_RANDOM;
	else if(strcmp(traffic_str, "nearest") == 0)
	    TRAFFIC = NEAREST_NEIGHBOR;
	else if(strcmp(traffic_str, "diagonal") == 0)
	    TRAFFIC = DIAGONAL;
        else
	   printf("\n Incorrect traffic pattern specified, using %s as default ", traffic_str );

	/* for automatically reducing the channel link bandwidth of a 7-D or a 9-D torus */
	link_bandwidth = (link_bandwidth * 10) / (2 * N_dims);

        injection_limit = injection_interval / MEAN_INTERVAL;

	for (i=0; i<N_dims; i++)
        {
	  N_nodes*=dim_length[i];
	  N_mpi_procs*=dim_length[i];
	}
	nlp_nodes_per_pe = N_nodes/tw_nnodes()/g_tw_npe;
	nlp_mpi_procs_per_pe = N_mpi_procs/tw_nnodes()/g_tw_npe;

	num_rows = sqrt(N_nodes);
	num_cols = num_rows;

	total_lps = g_tw_nlp * tw_nnodes();
	node_rem = N_nodes % (tw_nnodes()/g_tw_npe);

	if(g_tw_mynode < node_rem)
	   {
		nlp_nodes_per_pe++;
		nlp_mpi_procs_per_pe++;
	   }
        num_packets=1;
        num_chunks = PACKET_SIZE/chunk_size;

        if( mpi_message_size > PACKET_SIZE)
         {
          num_packets = mpi_message_size / PACKET_SIZE;  
          
	  if(mpi_message_size % PACKET_SIZE != 0 )
	    num_packets++;
         }

	g_tw_mapping=CUSTOM;
     	g_tw_custom_initial_mapping=&torus_mapping;
        g_tw_custom_lp_global_to_local_map=&torus_mapping_to_lp;

	g_tw_events_per_pe = mem_factor * 1024 * (nlp_nodes_per_pe/g_tw_npe + nlp_mpi_procs_per_pe/g_tw_npe) + opt_mem;
	tw_define_lps(nlp_nodes_per_pe + nlp_mpi_procs_per_pe, sizeof(nodes_message), 0);

	head_delay = (1 / link_bandwidth) * chunk_size;
	
        // BG/L torus network paper: Tokens are 32 byte chunks that is why the credit delay is adjusted according to bandwidth * 32
	credit_delay = (1 / link_bandwidth) * 8;
	packet_offset = (g_tw_ts_end/MEAN_INTERVAL) * num_packets; 
	
	if(tw_ismaster())
	{
		printf("\nTorus Network Model Statistics:\n");
		printf("Number of nodes: %d Torus dimensions: %d ", N_nodes, N_dims);
		printf(" Link Bandwidth: %f Traffic pattern: %s \n", link_bandwidth, traffic_str );
	}

	tw_run();
	unsigned long long total_finished_storage[N_COLLECT_POINTS];
	unsigned long long total_generated_storage[N_COLLECT_POINTS];
	unsigned long long total_num_hops[N_COLLECT_POINTS];
	unsigned long long total_queue_depth[N_COLLECT_POINTS];
	unsigned long long wait_length,event_length,N_total_packets_finish, N_total_msgs_finish, N_total_hop;
	tw_stime total_time_sum,g_max_latency;

	for( i=0; i<N_COLLECT_POINTS; i++ )
	  {
	    MPI_Reduce( &N_finished_storage[i], &total_finished_storage[i],1,
                        MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	    MPI_Reduce( &N_generated_storage[i], &total_generated_storage[i],1,
                        MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	    MPI_Reduce( &N_num_hops[i], &total_num_hops[i],1,
			MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	    MPI_Reduce( &N_queue_depth[i], &total_queue_depth[i],1,
		         MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	  }

	MPI_Reduce( &total_time, &total_time_sum,1, 
		    MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &N_finished_packets, &N_total_packets_finish,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
        MPI_Reduce( &N_finished_msgs, &N_total_msgs_finish,1, 
                    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);

	MPI_Reduce( &total_hops, &N_total_hop,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &max_latency, &g_max_latency,1, 
		    MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

	for( i=1; i<N_COLLECT_POINTS; i++ )
	  {
	    total_finished_storage[i]+=total_finished_storage[i-1];
	    total_generated_storage[i]+=total_generated_storage[i-1];
	  }

//	if( total_lp_time > 0 )
//	   total_lp_time /= num_mpi_msgs;

	if(tw_ismaster())
	  {
	    printf("\n ****************** \n");
	    printf("\n total packets finished:         %lld and %lld; \n",
		   total_finished_storage[N_COLLECT_POINTS-1],N_total_packets_finish);
	    printf("\n total MPI messages finished:         %lld; \n",
                   N_total_msgs_finish);
	    printf("\n total generate:       %lld; \n",
		   total_generated_storage[N_COLLECT_POINTS-1]);
	    printf("\n total hops:           %lf; \n",
		   (double)N_total_hop/N_total_packets_finish);
	    printf("\n average travel time:  %lf; \n\n",
		   total_time_sum/N_total_msgs_finish);
#if REPORT_BANDWIDTH	    
	    for( i=0; i<N_COLLECT_POINTS; i++ )
	      {
		printf(" %d ",i*100/N_COLLECT_POINTS);
		printf("total finish: %lld; generate: %lld; alive: %lld \n ",
		       total_finished_storage[i],
		       total_generated_storage[i],
		       total_generated_storage[i]-total_finished_storage[i]);
	      }

	    // capture the steady state statistics
        tw_stime bandwidth;
        tw_stime interval = (g_tw_ts_end / N_COLLECT_POINTS);
	interval = interval/(1000.0 * 1000.0 * 1000.0); //convert ns to seconds
        for( i=1; i<N_COLLECT_POINTS; i++ )
           {
                bandwidth = total_finished_storage[i] - total_finished_storage[i - 1];
		unsigned long long avg_hops = total_num_hops[i]/bandwidth;
                bandwidth = (bandwidth * PACKET_SIZE) / (1024.0 * 1024.0 * 1024.0); // convert bytes to GB
                bandwidth = bandwidth / interval; 
                printf("\n Interval %0.7lf Bandwidth %lf avg hops %lld queue depth %lld ", interval, bandwidth, avg_hops, (unsigned long long)total_queue_depth[i]/num_chunks);
           }

	    unsigned long long steady_sum=0;
	    for( i = N_COLLECT_POINTS/2; i<N_COLLECT_POINTS;i++)
	      steady_sum+=total_generated_storage[i]-total_finished_storage[i];
	    printf("\n Steady state, packet alive: %lld\n",
		   2*steady_sum/N_COLLECT_POINTS);
#endif
	    printf("\nMax latency is %lf\n\n",g_max_latency);
	}
//	  if(packet_sent > 0 || credit_sent > 0)
//	    printf("\n Packet sent are %d, credit sent %d ", packet_sent, credit_sent);
	tw_end();
	return 0;
}
Beispiel #24
0
void
tlm_md_init(int argc, char ** argv, char ** env)
{
	tw_lpid		 nlp_grid;

	int		 i;

	if(!g_rn_environment)
		return;

	g_tlm_stats = tw_calloc(TW_LOC, "", sizeof(*g_tlm_stats), 1);

	// g_tlm_output_fix up global variables
	g_tw_ts_end += 0.1;

	if(0 != strcmp(g_rn_tools_dir, ""))
		sprintf(g_tlm_spatial_terrain_fn, "tools/%s/terrain.txt", g_rn_tools_dir);
	else
		tw_error(TW_LOC, "No terrain file specified!");

	/*
	 * Open debug plotting files
	 */
#if 0
	g_tlm_waves_plt_f = fopen("waves.plt", "w");
	g_tlm_nodes_plt_f = fopen("user_nodes.plt", "w");
	g_tlm_parts_plt_f = fopen("particles.plt", "w");

	if(!g_tlm_nodes_plt_f || !g_tlm_parts_plt_f)
		tw_error(TW_LOC, "Unable to open plotting files!");
#endif

	g_tlm_stats = tw_calloc(TW_LOC, "tlm stats", sizeof(tlm_statistics), 1);
	memset(g_tlm_stats, 0, sizeof(tlm_statistics));

	// # of cells around me = 2 * # spatial_dim
	g_tlm_spatial_dir = g_tlm_spatial_dim * 2;
	g_tlm_spatial_coeff = 2.0 / g_tlm_spatial_dir;

	g_tlm_spatial_grid_i = tw_calloc(TW_LOC, "spatial grid i", sizeof(int), g_tlm_spatial_dim);
	g_tlm_spatial_offset_ts = tw_calloc(TW_LOC, "spatial offset ts", sizeof(tw_stime), g_tlm_spatial_dir);
	g_tlm_spatial_offset = g_rn_nmachines / (tw_nnodes() * g_tw_npe);

	g_tlm_spatial_ground_coeff = 0.75;

	if(0.0 > g_tlm_wave_loss_coeff)
	{
		g_tlm_wave_loss_coeff = 1.0 / exp(g_tlm_wave_attenuation * g_tlm_spatial_d[0]);

		if(tw_ismaster())
			printf("\n\tSETTING WAVE LOSS COEFF %lf! \n\n", g_tlm_wave_loss_coeff);
	}

	// speed of light in m/s
	g_tlm_wave_velocity = 299792458.0;

	nlp_grid = tlm_grid_init();
	ntlm_lp_per_pe = ceil(nlp_grid / (tw_nnodes() * g_tw_npe));

	if(tw_nnodes() == 1)
		ntlm_lp_per_pe = nlp_grid;

	g_tw_events_per_pe = 1.5 * nlp_grid / (tw_nnodes() * g_tw_npe);
	g_tw_events_per_pe += g_tlm_optmem;

#if 0
	for(i = 0; i < g_tlm_spatial_offset; i++)
		tw_lp_settype(i, types);
#endif

	//tw_error(TW_LOC, "setting types not ported");

	if(!tw_ismaster())
		return;

	printf("\nInitializing Model: Transmission Line Matrix\n");
#if DWB
	printf("\t\t%-42s %11d (%ld)\n", "TLM Membufs", 1000000, g_tlm_fd);
#endif

#if RM_LOG_STATS
	g_tlm_output_f = fopen("tlm.log", "w");

	if(!g_tlm_output_f)
		tw_error(TW_LOC, "Unable to open TLM logfile!");
#else
	g_tlm_output_f = stdout;
#endif

	fprintf(g_tlm_output_f, "\n");
	fprintf(g_tlm_output_f, "\t%-50s\n", "Spatial Parameters:");
	fprintf(g_tlm_output_f, "\n");
	fprintf(g_tlm_output_f, "\t\t%-42s %11.4lf\n", "Spatial Coefficient", g_tlm_spatial_coeff);
	fprintf(g_tlm_output_f, "\n");
	fprintf(g_tlm_output_f, "\t\t%-42s %11dD\n", "Dimensions Computed", g_tlm_spatial_dim);

	for(i = 0; i < g_tlm_spatial_dim; i++)
	{
		fprintf(g_tlm_output_f, "\t\t%-42s %11d %dD\n", "Cells per Dimension", 
						g_tlm_spatial_grid[i], i+1);
		fprintf(g_tlm_output_f, "\t\t%-42s %11d %dD\n", "Cell Spacing ", 
						g_tlm_spatial_d[i], i+1);
	}

	fprintf(g_tlm_output_f, "\n");
	fprintf(g_tlm_output_f, "\t%-50s\n", "Temporal Parameters:");
	fprintf(g_tlm_output_f, "\n");
	fprintf(g_tlm_output_f, "\t\t%-42s %11.11lf\n", "Scatter Offset TS", g_tlm_scatter_ts);
	fprintf(g_tlm_output_f, "\t\t%-42s %11.4lf\n", "Loss Coefficient", g_tlm_wave_loss_coeff);
	fprintf(g_tlm_output_f, "\t\t%-42s %11.4lf\n", "Velocity", g_tlm_wave_velocity);

	for(i = 0; i < g_tlm_spatial_dim; i++)
		fprintf(g_tlm_output_f, "\t\t%-42s %11.11lf %dD\n", "Timestep (d/V)", 
					g_tlm_spatial_offset_ts[i], i+1);
	fprintf(g_tlm_output_f, "\t\t%-42s %11.4lf\n", "Amplitude Threshold", g_tlm_wave_threshold);

	fprintf(g_tlm_output_f, "\t%-50s %11d\n", "Spatial Offset", 
						g_tlm_spatial_offset);
}
Beispiel #25
0
int
main(int argc, char **argv, char **env)
{
	int i;
	tw_opt_add(app_opt);
	tw_init(&argc, &argv);

	for (i=0; i<N_dims; i++)
	  N_nodes*=dim_length[i];

	MEAN_INTERVAL = N_nodes/ARRIVAL_RATE;

	nlp_per_pe = N_nodes/tw_nnodes()/g_tw_npe;
	g_tw_events_per_pe = nlp_per_pe/g_tw_npe + opt_mem;
	tw_define_lps(nlp_per_pe, sizeof(nodes_message), 0);

	for(i = 0; i < g_tw_nlp; i++)
	  tw_lp_settype(i, &nodes_lps[0]);

	tw_run();

	if(tw_ismaster())
	{
		printf("\nTorus Network Model Statistics:\n");

		printf("\t%-50s %11lld\n", "Number of nodes", 
			nlp_per_pe * g_tw_npe * tw_nnodes());
	}

	unsigned long long total_finished_storage[N_COLLECT_POINTS];
	unsigned long long total_dropped_storage[N_COLLECT_POINTS];
	unsigned long long total_generated_storage[N_COLLECT_POINTS];
	unsigned long long wait_length,event_length,N_total_finish,N_total_hop;
	tw_stime total_time_sum,g_max_latency;

	for( i=0; i<N_COLLECT_POINTS; i++ )
	  {
	    MPI_Reduce( &N_dropped_storage[i], &total_dropped_storage[i],1, 
			MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	    MPI_Reduce( &N_finished_storage[i], &total_finished_storage[i],1,
                        MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	    MPI_Reduce( &N_generated_storage[i], &total_generated_storage[i],1,
                        MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	  }

	MPI_Reduce( &queueing_times_sum, &event_length,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &total_queue_length, &wait_length,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &total_time, &total_time_sum,1, 
		    MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &N_finished, &N_total_finish,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &total_hops, &N_total_hop,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	MPI_Reduce( &max_latency, &g_max_latency,1, 
		    MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

	unsigned long long total_rand_total;
	MPI_Reduce( &rand_total, &total_rand_total,1, 
		    MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);

	for( i=1; i<N_COLLECT_POINTS; i++ )
	  {
	    total_dropped_storage[i]+=total_dropped_storage[i-1];
	    total_finished_storage[i]+=total_finished_storage[i-1];
	    total_generated_storage[i]+=total_generated_storage[i-1];
	  }

	if(tw_ismaster())
	  {
	    printf("\n ****************** \n");
	    printf("\n Total drop:           %lld; \n",
		   total_dropped_storage[N_COLLECT_POINTS-1]);
	    printf("\n total finish:         %lld and %lld; \n",
		   total_finished_storage[N_COLLECT_POINTS-1],N_total_finish);
	    printf("\n total generate:       %lld; \n",
		   total_generated_storage[N_COLLECT_POINTS-1]);
	    printf("\n total hops:           %lf; \n",
		   (double)N_total_hop/total_finished_storage[N_COLLECT_POINTS-1]);
	    printf("\n total wait length:    %lf; \n",
		   (double)wait_length/total_finished_storage[N_COLLECT_POINTS-1]);
	    printf("\n total total queued:   %lf; \n",
		   (double)event_length/total_finished_storage[N_COLLECT_POINTS-1]);
	    printf("\n average travel time:  %lf; \n\n",
		   total_time_sum/total_finished_storage[N_COLLECT_POINTS-1]);
	    
	    for( i=0; i<N_COLLECT_POINTS; i++ )
	      {
		printf(" %d ",i*100/N_COLLECT_POINTS);
		printf("drop: %lld; finish: %lld; generate: %lld; alive: %lld\n",
		       total_dropped_storage[i],
		       total_finished_storage[i],
		       total_generated_storage[i],
		       total_generated_storage[i]-total_finished_storage[i]);
		       
	      }

	    // capture the steady state statistics
	    unsigned long long steady_sum=0;
	    for( i = N_COLLECT_POINTS/2; i<N_COLLECT_POINTS;i++)
	      steady_sum+=total_generated_storage[i]-total_finished_storage[i];
	    printf("\n Steady state, packet alive: %lld\n",
		   2*steady_sum/N_COLLECT_POINTS);
	    printf("Aeverage is %lld\n",total_rand_total/total_generated_storage[N_COLLECT_POINTS-1]);
	    printf("\nMax latency is %lf\n\n",g_max_latency);

	  }

	tw_end();
	return 0;
}