/* * map: map LPs->KPs->PEs linearly */ void map_linear(void) { tw_pe *pe; int nlp_per_kp; int lpid; int kpid; int i; int j; // may end up wasting last KP, but guaranteed each KP has == nLPs nlp_per_kp = (int)ceil((double) g_tw_nlp / (double) g_tw_nkp); if(!nlp_per_kp) { tw_error(TW_LOC, "Not enough KPs defined: %d", g_tw_nkp); } g_tw_lp_offset = g_tw_mynode * g_tw_nlp; #if VERIFY_MAPPING printf("NODE %d: nlp %lld, offset %lld\n", g_tw_mynode, g_tw_nlp, g_tw_lp_offset); #endif for(kpid = 0, lpid = 0, pe = NULL; (pe = tw_pe_next(pe)); ) { #if VERIFY_MAPPING printf("\tPE %d\n", pe->id); #endif for(i = 0; i < nkp_per_pe; i++, kpid++) { tw_kp_onpe(kpid, pe); #if VERIFY_MAPPING printf("\t\tKP %d", kpid); #endif for(j = 0; j < nlp_per_kp && lpid < g_tw_nlp; j++, lpid++) { tw_lp_onpe(lpid, pe, g_tw_lp_offset+lpid); tw_lp_onkp(g_tw_lp[lpid], g_tw_kp[kpid]); #if VERIFY_MAPPING if(0 == j % 20) { printf("\n\t\t\t"); } printf("%lld ", lpid+g_tw_lp_offset); #endif } #if VERIFY_MAPPING printf("\n"); #endif } } if(!g_tw_lp[g_tw_nlp-1]) { tw_error(TW_LOC, "Not all LPs defined! (g_tw_nlp=%d)", g_tw_nlp); } if(g_tw_lp[g_tw_nlp-1]->gid != g_tw_lp_offset + g_tw_nlp - 1) { tw_error(TW_LOC, "LPs not sequentially enumerated!"); } }
void torus_mapping(void) { tw_lpid kpid; tw_pe * pe; int nkp_per_pe=16; for(kpid = 0; kpid < nkp_per_pe; kpid++) tw_kp_onpe(kpid, g_tw_pe[0]); int i; for(i = 0; i < nlp_nodes_per_pe; i++) { kpid = i % g_tw_nkp; pe = tw_getpe(kpid % g_tw_npe); tw_lp_onpe(i, pe, g_tw_mynode * nlp_nodes_per_pe + i + getRem() ); tw_lp_onkp(g_tw_lp[i], g_tw_kp[kpid]); tw_lp_settype(i, &nodes_lps[0]); } for(i = 0; i < nlp_mpi_procs_per_pe; i++) { kpid = i % g_tw_nkp; pe = tw_getpe(kpid % g_tw_npe); tw_lp_onpe(nlp_nodes_per_pe+i, pe, N_nodes + g_tw_mynode * nlp_mpi_procs_per_pe + i + getRem() ); tw_lp_onkp(g_tw_lp[nlp_nodes_per_pe + i], g_tw_kp[kpid]); tw_lp_settype(nlp_nodes_per_pe + i, &nodes_lps[1]); } }
int main(int argc, char * argv[]) { int NumPE = 0; int i = 0; tw_lp *lp; tw_kp *kp; g_tw_ts_end = 300; g_tw_gvt_interval = 16; printf("Please enter the number of processors: "); scanf("%d",&NumPE); if(NumPE < 1 && NumPE > 4){ printf("Invalid number of processors %d\n", NumPE); exit(0); } /* tw_lptype NumPE NumKP NumLP Message_Size*/ tw_init(airport_lps, NumPE, 3, 3, sizeof(Msg_Data)); for(i = 0; i < 3; i++){ lp = tw_getlp(i); kp = tw_getkp(i); tw_lp_settype(lp, AIR_LP); tw_lp_onkp(lp, kp); if(i >= NumPE){ tw_lp_onpe(lp, tw_getpe(NumPE - 1)); tw_kp_onpe(kp, tw_getpe(NumPE - 1)); } else { tw_lp_onpe(lp, tw_getpe(i)); tw_kp_onpe(kp, tw_getpe(i)); } } tw_run(); printf("Number of Landings: %d\n", NumLanded); return 0; }
void map_round_robin(void) { tw_pe *pe; int kpid; int i; for(i = 0; i < g_tw_nlp; i++) { kpid = i % g_tw_nkp; pe = tw_getpe(kpid % g_tw_npe); tw_lp_onpe(i, pe, g_tw_lp_offset+i); tw_kp_onpe(kpid, pe); tw_lp_onkp(g_tw_lp[i], g_tw_kp[kpid]); #if VERIFY_MAPPING printf("LP %4d KP %4d PE %4d\n", i, kp->id, pe->id); #endif } }
void traffic_grid_mapping() { tw_lpid x, y; tw_lpid lpid, kpid; tw_lpid num_cells_per_kp, vp_per_proc; tw_lpid local_lp_count; num_cells_per_kp = (NUM_CELLS_X * NUM_CELLS_Y) / (NUM_VP_X * NUM_VP_Y); vp_per_proc = (NUM_VP_X * NUM_VP_Y) / ((tw_nnodes() * g_tw_npe)) ; g_tw_nlp = nlp_per_pe; g_tw_nkp = vp_per_proc; local_lp_count=0; for (y = 0; y < NUM_CELLS_Y; y++) { for (x = 0; x < NUM_CELLS_X; x++) { lpid = (x + (y * NUM_CELLS_X)); if( g_tw_mynode == CellMapping_lp_to_pe(lpid) ) { kpid = local_lp_count/num_cells_per_kp; local_lp_count++; // MUST COME AFTER!! DO NOT PRE-INCREMENT ELSE KPID is WRONG!! if( kpid >= g_tw_nkp ) tw_error(TW_LOC, "Attempting to mapping a KPid (%llu) for Global LPid %llu that is beyond g_tw_nkp (%llu)\n", kpid, lpid, g_tw_nkp ); tw_lp_onpe(CellMapping_to_local_index(lpid), g_tw_pe[0], lpid); if( g_tw_kp[kpid] == NULL ) tw_kp_onpe(kpid, g_tw_pe[0]); tw_lp_onkp(g_tw_lp[CellMapping_to_local_index(lpid)], g_tw_kp[kpid]); tw_lp_settype( CellMapping_to_local_index(lpid), &mylps[0]); } } } }