⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brtiping.c

📁 基于linux环境的ns2多机并行仿真补丁
💻 C
字号:
/*---------------------------------------------------------------------------*//* BRTI ping test application.                                               *//* Author(s): Richard Fujimoto, Steve Ferenci, Thom McLean, Kalyan Perumalla.*//* $Revision: 1.3 $ $Name: v26apr05 $ $Date: 2003/12/10 22:39:59 $ *//*---------------------------------------------------------------------------*/#include <stdlib.h>#include <string.h>#include <stdio.h>#include "bufpool.h"#include "brti.h"char *MyWhereProc (long , void *, long );/***************************************************************************  Procedure called when PE detects LBTS computation started by another PE*/struct FedState	/* state for federate */{  BOOLEAN WaitingOnNER;		/* true if waiting for NER to complete */  int Count;			/* count number of messages */  TM_Time Now;			/* current time */  TM_Time LastTS;		/* time stamp of last TSO message received */  TM_Time TargetTime;		/* print message when passing this time */  MB_BufferPool FreePool;       /* pool of usused event buffers */  int TagCount;			/* number of time advance grants */} FED;/* Lookahead value */static double LOOKAHEAD = 0.1;/* end of simulation time */static TM_Time ENDTIME = 2000.0;/* print message every UPDATE_INTERVAL time units */static double UPDATE_INTERVAL = 10000.0;int main (int argc, char *argv[]){  TIMER_TYPE t1, t2;  double TSeconds;  int j = 0;  int appl_argc = 0;  char **appl_argv = 0;  RTI_Init(argc, argv);  RTI_SetLookAhead (LOOKAHEAD);  appl_argc = argc;  appl_argv = argv;  printf( "--- %d Application Arguments: ", appl_argc );  for( j = 0; j < appl_argc; j++ ) printf( " %s", appl_argv[j] );  printf( "\n" );  if( argc > 1 ) ENDTIME = atoi( argv[1] );  printf( "--- Simulating upto %f simulation time units.\n", ENDTIME );  fflush( stdout );  FED.WaitingOnNER = FALSE;  FED.Count = 0;  FED.Now = 0.0;  FED.TargetTime = UPDATE_INTERVAL;  FED.LastTS = 0.0;  FED.TagCount = 0;  FED.FreePool = MB_MakePool (1000, sizeof (struct MsgS));  if (! FED.FreePool) {printf("Couldn't create buffer pool\n"); exit(1);}  /* wait until everyone subscribed before sending messages */  RTIKIT_Barrier();  TIMER_NOW(t1);    /* start clock */  printf( "Entering Simulation Loop...\n" ); fflush(stdout);  /* main event processing loop */  while (TM_LE(FED.Now, ENDTIME))  {    FED.WaitingOnNER = TRUE;    RTI_TimeAdvanceRequest(TM_Add(FED.Now,1.0));    if( FED.Now>=ENDTIME ) {break;}    /* wait for time advance grant */    while (FED.WaitingOnNER)    {	BRTI_Tick();    }  }  printf( "*** Exited the simulation loop at now=%f ***\n", FED.Now );  fflush( stdout );  TIMER_NOW(t2);    /* stop clock */  TSeconds = TIMER_DIFF(t2,t1);  printf ("PE %d: Count=%d\n", (int) RTIKIT_nodeid, (int) FED.Count);  TM_PrintStats();  printf ("Elapsed time :  %8.2f sec (%d TAGs, %.2f /sec)\n", TSeconds,		FED.TagCount, (double) FED.TagCount / TSeconds);  printf ("Waiting for other processors to finish...");fflush(stdout);  RTIKIT_Barrier();  printf ("Done.");fflush(stdout);  fflush(stdout);  return (0);}/************************************************************************* ************************************************************************* *   FEDERATE DEFINED MESSAGE HANDLERS ************************************************************************* *************************************************************************/void TimeAdvanceGrant (TM_Time GrantTime){  if (TM_LT(GrantTime, FED.Now))  { printf ("Error: logical time decreases\n"); exit(1); }  if (TM_LT(GrantTime, FED.LastTS))  { printf ("Error: time advance < prior update\n"); exit(1); }  if (TM_GT(GrantTime, FED.TargetTime))  {    printf ("%d:%f\n", (int)RTIKIT_nodeid, GrantTime);    fflush(stdout);    FED.TargetTime += UPDATE_INTERVAL;  }  FED.TagCount++;  FED.Now = GrantTime;  FED.WaitingOnNER = FALSE;}void ReflectAttributeValues (TM_Time TimeStamp, struct MsgS *Msg,			long MsgSize, long MsgType){  if (TM_LT(TimeStamp, FED.Now))  { printf ("Error: attribute update occurs in past\n"); exit(1); }  if (TM_LT(TimeStamp, FED.LastTS))  { printf ("Error: attribute updates out of order\n"); exit(1); }  FED.LastTS = TimeStamp;  MB_FreeBuffer (FED.FreePool, Msg);}/***************************************************************************  WhereProc procedure to indicate where incoming messages are written*/ char *MyWhereProc (long MsgSize, void *Context, long MsgType){  char * buf;   /* consistency checks */  if (MsgSize != sizeof (struct MsgS))  {printf ("WhereProc: unexpected message size\n"); fflush(stdout); exit (1);}  if (MsgType != 0)  {printf ("WhereProc: unexpected msg type\n"); fflush(stdout); exit (1);}   /* allocate a message buffer and return a pointer to it */  if ((buf=MB_GetBuffer(FED.FreePool)) ==  NULL)  { printf ("Error: queue overflow, quiting\n"); exit(1);}   return ((char *) buf);}/**************************************************************************/void RequestRetraction(EventRetractionHandle erh){}/**************************************************************************/void MyHereProc (long MsgSize, struct MsgS *Msg){  MB_FreeBuffer (FED.FreePool, Msg);} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -