/* * tw_pe_init: initialize individual PE structs * * id -- local compute node g_tw_pe array index * gid -- global (across all compute nodes) PE id */ void tw_pe_init(tw_peid id, tw_peid gid) { tw_pe *pe = (tw_pe *) tw_calloc(TW_LOC, "Local PE", sizeof(*pe), 1); tw_petype no_type; memset(&no_type, 0, sizeof(no_type)); pe->id = gid; pe->node = g_tw_mynode; tw_pe_settype(pe, &no_type); pe->trans_msg_ts = DBL_MAX; pe->gvt_status = 0; if(id == g_tw_npe-1) pe->pe_next = NULL; else pe->pe_next = &g_tw_pe[id+1]; if (g_tw_pe[id]) tw_error(TW_LOC, "PE %u already initialized", pe->id); g_tw_pe[id] = pe; g_tw_pe[id]->rng = tw_rand_init(31, 41); }
/* * tw_pe_init: initialize individual PE structs * */ void tw_pe_init(void) { if (g_tw_pe) tw_error(TW_LOC, "PE %u already initialized", g_tw_mynode); g_tw_pe = (tw_pe*)tw_calloc(TW_LOC, "PE Struct", sizeof(*g_tw_pe), 1); tw_petype no_type; memset(&no_type, 0, sizeof(no_type)); g_tw_pe->id = g_tw_mynode; tw_pe_settype(&no_type); g_tw_pe->trans_msg_ts = DBL_MAX; g_tw_pe->gvt_status = 0; // TODO is the PE RNG ever actually used? g_tw_pe->rng = tw_rand_init(31, 41); }
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; }
/* * This function initializes the environment model.. should be called * once by user model. Allows EM to control how ROSS is init'd. * * This function provides the Reactive Model with a pre-simulation 'main' */ int rm_initialize(tw_petype * ptypes, tw_lptype * types, tw_peid npe, tw_kpid nkp, tw_lpid nradios, size_t msg_sz) { //FILE *fp; tw_lptype *t; //tw_pe *pe; //tw_kp *kp; //tw_lp *lp; //size_t size; //int max_name; int ntypes; tw_lpid nlp_grid; //int nkp_grid; //int nnodes; int i; //int j; //int k; //int m; //int kp_per_pe; /* * Open debug plotting files */ #if 0 g_rm_waves_plt_f = fopen("waves.plt", "w"); g_rm_nodes_plt_f = fopen("user_nodes.plt", "w"); g_rm_parts_plt_f = fopen("particles.plt", "w"); if(!g_rm_nodes_plt_f || !g_rm_parts_plt_f) tw_error(TW_LOC, "Unable to open plotting files!"); #endif g_rm_stats = tw_calloc(TW_LOC, "rm stats", sizeof(rm_statistics), 1); memset(g_rm_stats, 0, sizeof(rm_statistics)); // # of cells around me = 2 * # spatial_dim g_rm_spatial_dir = g_rm_spatial_dim * 2; g_rm_spatial_offset = nradios; g_rm_spatial_coeff = 2.0 / g_rm_spatial_dir; g_rm_spatial_grid_i = tw_calloc(TW_LOC, "spatial grid i", sizeof(int), g_rm_spatial_dim); g_rm_spatial_offset_ts = tw_calloc(TW_LOC, "spatial offset ts", sizeof(tw_stime), g_rm_spatial_dir); g_rm_spatial_ground_coeff = 0.75; if(0.0 > g_rm_wave_loss_coeff) { g_rm_wave_loss_coeff = 0.5; g_rm_wave_loss_coeff = 1.0 / exp(g_rm_wave_attenuation * g_rm_spatial_d[0]); if(tw_node_eq(&g_tw_mynode, &g_tw_masternode)) printf("\n\tSETTING WAVE LOSS COEFF %lf! \n\n", g_rm_wave_loss_coeff); } g_rm_wave_velocity = 3.0 * 1000.0 * 1000.0 * 1000.0; // Require NULL terminated array, plus LPs for Cells for(ntypes = 2, t = types; t->state_sz; t++) ntypes++; //printf("Creating %d lp types\n", ntypes); t = tw_calloc(TW_LOC, "lp types array", sizeof(tw_lptype), ntypes); memcpy(t, types, sizeof(tw_lptype) * (ntypes-2)); memcpy(&t[ntypes-2], rm_lps, sizeof(rm_lps)); nlp_grid = rm_grid_init(); nrmlp_per_pe = ceil(nlp_grid / (tw_nnodes() * g_tw_npe)); if(tw_nnodes() == 1) nrmlp_per_pe = nlp_grid; nlp_per_pe = nradios + nrmlp_per_pe; g_tw_events_per_pe = .1 * nlp_grid / (tw_nnodes() * g_tw_npe); g_tw_events_per_pe += optimistic_memory; rm_grid_terrain(); for(i = 0; i < g_tw_npe; i++) tw_pe_settype(g_tw_pe[i], rm_pes); tw_pe_settype(&g_rm_pe, ptypes); g_tw_rng_default = TW_FALSE; tw_define_lps(nlp_per_pe, sizeof(rm_message), 0); for(i = 0; i < g_rm_spatial_offset; i++) tw_lp_settype(i, types); for( ; i < g_tw_nlp; i++) tw_lp_settype(i, rm_lps); return 1; }