📄 tm.c
字号:
printf("NWINS= %ld TOT= %ld\n", mod->nwins, lbts->epoch_id); mod = mod->next; }}/*----------------------------------------------------------------------------*/void TM_PrintState( void ){ int i = 0; TMModuleState *mod = modlist->mods; printf("------------ TM STATE START ------------\n"); printf("myid=%d, N=%d\n", st->myid, st->N); printf("LBTS={LBTS=%f (%s) sproc=%p, max_dproc=%d, n_dproc=%d, dproc=[", TM_TS(lbts->LBTS), TM_TIME_QUAL_STR(lbts->qual), lbts->sproc, lbts->max_dproc, lbts->n_dproc); for(i=0; i<lbts->n_dproc; i++) printf("%s%p", (i>0?",":"!"),lbts->dproc[i]); printf("]}\n"); printf("Stats={nlbts=%ld}\n", stats->nlbts); printf("\n"); while( mod ) { if(!mod->inited)TM_InitMod( mod ); mod->cl.printstate(mod->cl.closure); mod = mod->next; } printf("------------ TM STATE END ------------\n");}/*----------------------------------------------------------------------------*/void TM_Tick( void ){ TMModuleState *mod = modlist->mods; MYASSERT( modlist->nmods > 0, ("At least one TM module required") ); while( mod ) { modlist->activemod = mod->index; if(!mod->inited)TM_InitMod( mod ); mod->cl.tick(mod->cl.closure); modlist->activemod = -1; mod = mod->next; }}/*----------------------------------------------------------------------------*//* TM Communication topology: *//* All2All by default. If the user adds at least one sender/receiver, then *//* specified topology will be used. *//*----------------------------------------------------------------------------*/typedef struct{ int all2all; /*Is it an all-to-all topology?*/ /*Minimum among lookaheads to all receivers*/ TM_Time min_external_la; /*Internal lookahead from an input PE to output PE*/ TM_Time internal_la[MAX_PE][MAX_PE]; /*If NOT all2all, use the following*/ /*Senders of TSO messages to this PE*/ int nsenders; struct { int pe; } sender[MAX_PE]; int sindex[MAX_PE]; /*Mapping from spe to i*/ /*Receivers of TSO messages from this PE*/ int nrecvrs; struct { int pe; TM_Time external_la; } recvr[MAX_PE]; int rindex[MAX_PE]; /*Mapping from rpe to i*/} TMTopology;/*----------------------------------------------------------------------------*/static TMTopology *topo;/*----------------------------------------------------------------------------*/void TM_TopoPrint( void ){ int i = 0; FILE *fp = stdout;/*XXX*/ if( !topo ) return; fprintf( fp, "***** TM Topology Begin *****\n" ); fprintf( fp, "\tAll-to-all= %s\n", topo->all2all ? "yes" : "no" ); fprintf( fp, "\tmin_external_la= %lf\n", TM_TS(topo->min_external_la) ); fprintf( fp, "\tnsenders= %d\n", topo->nsenders ); for(i=0;i<topo->nsenders;i++) fprintf(fp,"\t\tsender[%d]: PE= %d\n", i, topo->sender[i].pe); fprintf( fp, "\tnrecvrs= %d\n", topo->nrecvrs ); for(i=0;i<topo->nrecvrs;i++) fprintf(fp,"\t\trecvr[%d]: PE= %d LA= %lf\n", i, topo->recvr[i].pe, TM_TS(topo->recvr[i].external_la)); fprintf( fp, "***** TM Topology End *****\n" );}/*----------------------------------------------------------------------------*/static void turnon_all2all( void ){ int i = 0, j = 0; for( i = 0; i < MAX_PE; i++ ) { for( j = 0; j < MAX_PE; j++ ) { topo->internal_la[i][j] = TM_ZERO; } } topo->nsenders = 0; topo->nrecvrs = 0; topo->min_external_la = TM_IDENT; topo->all2all = TRUE;}/*----------------------------------------------------------------------------*/static void turnoff_all2all( void ){ int i = 0, j = 0; for( i = 0; i < MAX_PE; i++ ) { for( j = 0; j < MAX_PE; j++ ) { topo->internal_la[i][j] = TM_IDENT; } topo->sindex[i] = -1; topo->rindex[i] = -1; } topo->nsenders = 0; topo->nrecvrs = 0; topo->min_external_la = TM_IDENT; topo->all2all = FALSE; TM_TopoAddSender( st->myid ); /*I am a sender to myself by default*/}/*----------------------------------------------------------------------------*/void TM_TopoInit( void ){ topo = (TMTopology *)calloc(1, sizeof(TMTopology)); turnon_all2all();}/*----------------------------------------------------------------------------*/int TM_TopoIsAllToAll( void ){ return topo->all2all;}/*----------------------------------------------------------------------------*/void TM_TopoSetAllToAll( void ){ turnon_all2all();}/*----------------------------------------------------------------------------*/static int TM_TopoFindSenderIndex( int spe ){ int i=0; for(i=0;i<topo->nsenders;i++)if(topo->sender[i].pe==spe)return i; return -1;}/*----------------------------------------------------------------------------*/static int TM_TopoFindReceiverIndex( int rpe ){ int i=0; for(i=0;i<topo->nrecvrs;i++)if(topo->recvr[i].pe==rpe)return i; return -1;}/*----------------------------------------------------------------------------*/void TM_TopoAddSender( int spe ){ int pei = 0; if( topo->all2all ) { turnoff_all2all(); } if( (pei = TM_TopoFindSenderIndex( spe )) < 0 ) { /*spe doesn't exist*/ int *i = &topo->nsenders, j = 0; MYASSERT( *i < MAX_PE, ("%d %d", *i, MAX_PE) ); topo->sender[*i].pe = spe; topo->sindex[spe] = *i; for( j = 0; j < MAX_PE; j++ ) { TM_Time *ila = &topo->internal_la[*i][j]; if(TM_GE(*ila, TM_IDENT)) *ila=TM_ZERO; } pei = (*i)++; } else { /*spe already exists*/ pei = pei; /*Dummy*/ }}/*----------------------------------------------------------------------------*/void TM_TopoAddReceiver( int rpe, TM_Time la ){ int pej = 0; if( topo->all2all ) { turnoff_all2all(); } if( (pej = TM_TopoFindReceiverIndex( rpe )) < 0 ) { /*rpe doesn't exist*/ int i = 0, *j = &topo->nrecvrs; MYASSERT( *j < MAX_PE, ("%d %d", *j, MAX_PE) ); topo->recvr[*j].pe = rpe; topo->rindex[rpe] = *j; topo->recvr[*j].external_la = la; for( i = 0; i < MAX_PE; i++ ) { TM_Time *jla = &topo->internal_la[i][*j]; if(TM_GE(*jla, TM_IDENT)) *jla=TM_ZERO; } pej = (*j)++; } else { /*rpe already exists; simply update la*/ TM_Time *pla = &topo->recvr[pej].external_la; *pla = TM_Min(*pla, la); } topo->min_external_la = TM_Min(topo->min_external_la, la);}/*----------------------------------------------------------------------------*/int TM_TopoGetNumSenders( void ) { return topo->all2all ? st->N : topo->nsenders; }/*----------------------------------------------------------------------------*/int TM_TopoGetNumReceivers( void ) { return topo->all2all ? st->N-1 : topo->nrecvrs; }/*----------------------------------------------------------------------------*/int TM_TopoGetSender( int i ) { return topo->all2all ? ( i==0 ? st->myid : (st->myid==0 ? i : (i<=st->myid ? i-1 : i)) ): topo->sender[i].pe; }/*----------------------------------------------------------------------------*/int TM_TopoGetReceiver( int i ) { return topo->all2all ? (i < st->myid ? i : i+1) : topo->recvr[i].pe; }/*----------------------------------------------------------------------------*/void TM_TopoSetMinExternalLA( TM_Time t ) { topo->min_external_la = TM_Min(topo->min_external_la, t);printf("TM_TopoSetMinExternalLA() min_external_la = %lf\n",TM_TS(topo->min_external_la));}/*----------------------------------------------------------------------------*/TM_Time TM_TopoGetMinExternalLA( void ) { return topo->min_external_la; }/*----------------------------------------------------------------------------*/TM_Time TM_TopoGetReceiverLAByIndex(int i) { return topo->all2all ? topo->min_external_la :topo->recvr[i].external_la;}/*----------------------------------------------------------------------------*/TM_Time TM_TopoGetReceiverLAByPE(int rpe){ int i = 0; if( topo->all2all ) return TM_TopoGetReceiverLAByIndex(0); for( i = 0; i < topo->nrecvrs; i++ ) {if( topo->recvr[i].pe == rpe ) break;} return (i >= topo->nrecvrs ? TM_NEG1 : topo->recvr[i].external_la);}/*----------------------------------------------------------------------------*/void TM_TopoSetInternalLA( int spe, int rpe, TM_Time la ){ TM_Time old_la = TM_ZERO; int i = topo->sindex[spe], j = topo->rindex[rpe]; if( i < 0 ) { TM_TopoAddSender( spe ); i = topo->sindex[spe]; } if( j < 0 ) { TM_TopoAddReceiver( rpe, TM_ZERO ); j = topo->rindex[rpe]; } MYASSERT( !topo->all2all, ("Sender %d & receiver %d should be added first", spe, rpe) ); MYASSERT( spe == topo->sender[i].pe, ("%d %d", spe, topo->sender[i].pe) ); MYASSERT( rpe == topo->recvr[j].pe, ("%d %d", rpe, topo->recvr[j].pe) ); old_la = topo->internal_la[spe][rpe]; topo->internal_la[spe][rpe] = TM_Min(old_la, la);}/*----------------------------------------------------------------------------*/int TM_TopoGetInternalLA( int spe, int rpe, TM_Time *la ){ int returned = 0; if( topo->all2all ) { *la = TM_ZERO; returned = 1; } else { int i = topo->sindex[spe], j = topo->rindex[rpe]; MYASSERT(i<0||spe==topo->sender[i].pe,("%d %d",spe,topo->sender[i].pe)); MYASSERT(j<0||rpe==topo->recvr[j].pe, ("%d %d", rpe,topo->recvr[j].pe)); if( i >= 0 && j >= 0 ) { *la = topo->internal_la[spe][rpe]; returned = 1; } } return returned;}/*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*/void TM_htond( double* pd ) \{ \ int little_endian = (htonl(0x1L) != 0x1L); \if(1){static int x;if(!x){x=1;printf("This host is %s-endian!\n",little_endian?"little":"big");}} \ \little_endian = FALSE; /*XXX*/ \ \ if( little_endian ) \ { \ if( sizeof(double) == sizeof(long) ) \ { \ long *l = (long *)pd; \ *l = htonl(*l); \ } \ else if( sizeof(double) == 2*sizeof(long) ) \ { \ double d = *pd; \ long *pd = (long *)&d; \ long *pl = (long *)pd; \ pl[0] = pd[1]; \ pl[1] = pd[0]; \ } \ else \ { \ MYASSERT(FALSE,("Unknown network-host converion for TM_Time!")); \ } \ } \}/*----------------------------------------------------------------------------*/#if !COMPOSITETIMEvoid hton_TM_Time( TM_Time *pt ) { TM_htond( pt ); }#elsevoid hton_TM_Time( TM_Time *pt ) { TM_htond( &pt->ts ); TM_htond( &pt->tie ); }#endifvoid ntoh_TM_Time( TM_Time *pt ) { hton_TM_Time( pt ); }/*----------------------------------------------------------------------------*/#if COMPOSITETIME TM_Time TM_ZERO = { 0, 0 }; TM_Time TM_NEG1 = { -1, 0 }; TM_Time TM_IDENT = {MAX_DOUBLE,MAX_DOUBLE};#endif/*----------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -