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

📄 brti.c

📁 基于linux环境的ns2多机并行仿真补丁
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************* ************************************************************************* *  OBJECT MANAGEMENT SERVICES ************************************************************************* ************************************************************************//* *  Data structure mapping object instance IDs to class IDs *//* index is an object instance number: map instance number to class */MCAST_Handle RTI_InstanceTable[RTI_MAX_INSTANCES_PER_PE];int RTI_NextInstance = 0;/************************************************************************* *  RTI_RegisterObjInstance: register an object instance ************************************************************************/RTI_ObjInstanceDesignator RTI_RegisterObjInstance	(RTI_ObjClassDesignator Handle){  long rtn;  if (Handle == NULL)    {printf ("TI_RegisterObjInstance: invalid class designator\n"); exit(1);}  if (RTI_NextInstance >= RTI_MAX_INSTANCES_PER_PE)  { printf ("too many object instances registered\n"); exit(1);}  /* assign ID for object instance, update table */  rtn = RTI_NextInstance;  RTI_InstanceTable[rtn] = Handle;  RTI_NextInstance++;  return ((RTI_MAX_INSTANCES_PER_PE*(long)Core_federateID())+rtn);}/*---------------------------------------------------------------------------*/EventRetractionHandle RTI_UpdateAttributeValues( RTI_ObjInstanceDesignator     Instance, struct MsgS *Msg, long MsgSize, long MsgType){  long Count;  MCAST_Handle handle;  EventRetractionHandle rh;  fdkErrorCode retCode;  if ((Instance < RTI_MAX_INSTANCES_PER_PE*Core_federateID()) ||      (Instance >= RTI_MAX_INSTANCES_PER_PE*(Core_federateID()+1)))  {printf ("illegal object instance designator specified\n"); exit(1);}  handle = RTI_InstanceTable[Instance%RTI_MAX_INSTANCES_PER_PE];  if (handle == NULL)  {printf ("illegal object instance designator specified\n"); exit(1);}  /* consistency check */  if (!Core_ValidateTimestamp (Msg->TimeStamp) )  {printf("illegal time stamp value on send\n");   printf("     TS = %.8f\n", Msg->TimeStamp);    printf("     CurrentTime = %.8f\n",Core_GetCurrentTime());   printf("     LookAhead   = %.8f\n",Core_GetLookAhead());   Core_PrintRTIState(stdout);fflush(stdout);   exit(1);}  if ((retCode = RHM_PutTag(Msg->TimeStamp,handle,&(rh))) != fdkSUCCEEDED)  {     printf("UAV Error getting Retraction Handle: %s\n",	    fdkErrorMessage(retCode));     exit(1);  }  Msg->erh.rn = rh.rn;  Msg->erh.fedID = rh.fedID;  /*  Disable initiation of new LBTS computations to avoid races */  Core_DisableLBTS();  TM_PutTag (&(Msg->TMStuff));  MCAST_Send (handle, Msg, MsgSize, MsgType, &Count);  Core_ConsiderOutgoingTSOMsg(Msg->TimeStamp, Count); /*KALYAN*/  Core_EnableLBTS();  return(rh);}/*---------------------------------------------------------------------------*//************************************************************************** * Procedure to create multicast group for the specified class name * a barrier should be used after all groups have been created to ensure * they are set up before execution begins * returns a handle, identifying the created class **************************************************************************/RTI_ObjClassDesignator RTI_CreateClass(char* ClassName){  MCAST_Handle handle;  long createStatus;  if (strlen (ClassName) > MCAST_MAX_NAME_LEN)  { printf ("Class name (%s) too long\n", ClassName); exit(1);}  printf("Registering class %s\n", ClassName);  fflush (stdout);  createStatus = MCAST_Create (ClassName, &handle, MCAST_RELIABLE);  if (createStatus != MCAST_Success && createStatus != MCAST_DuplicateName)  { printf ("Couldn't create multicast group %s\n", ClassName); exit(1);}  return ((RTI_ObjClassDesignator) handle);}/************************************************************************** ************************************************************************** *  Initialization Procedure *  Parameter is the name of the fedfile, or NULL if none defined ************************************************************************** **************************************************************************/fdkErrorCode DeliverROEvents(void){   return(fdkSUCCEEDED);}/*---------------------------------------------------------------------------*/void RTI_Retract(EventRetractionHandle rh){  CoreRetractInfo ri;  static struct MsgS MBuf[10000];  static int MBufHead = 0;  if(RHM_IsRetractable(rh,&ri) == RETRACTABLE)  {        MBuf[MBufHead].TimeStamp = ri.ts;    MBuf[MBufHead].erh.rn = rh.rn;    MBuf[MBufHead].erh.fedID = rh.fedID;    {      long Count;      Core_DisableLBTS();      TM_PutTag (&(MBuf[MBufHead].TMStuff));      MCAST_Send (ri.mh, &(MBuf[MBufHead])		   , sizeof(struct MsgS), MSG_RETRACTION, &Count);      TM_Out(MBuf[MBufHead].TimeStamp, Count);      Core_EnableLBTS();      MBufHead = (MBufHead + 1) % 10000;    }  }  else  {    printf("\nretract: unable to retract message with rid = %lu\n",rh.rn);  }}#if 0void xRTI_Retract(EventRetractionHandle rh){  struct RetractInfo ri;  static struct MsgS M, *Msg=&M; /* static for efficiency */  if(Core_IsRetractable(rh,&ri))  {    if(0) printf("\nretract: retraction message with rid = %lu, %12.6f\n",rh,ri.ts);/*SLFXXX*/        Msg->TimeStamp = ri.ts;    Msg->erh = rh;    {      long Count;      Core_DisableLBTS();      TM_PutTag (&(Msg->TMStuff));      MCAST_Send (ri.mh, Msg, sizeof(struct MsgS), MSG_RETRACTION, &Count);      TM_Out(Msg->TimeStamp, Count);      Core_EnableLBTS();    }  }  else  {    printf("\nretract: unable to retract message with rid = %lu\n",rh);  }}#endif/*---------------------------------------------------------------------------*/void TimeAdvanceGrantWrapper(TM_Time t){    TimeAdvanceGrant(t);}/*---------------------------------------------------------------------------*/void BRTI_Tick(void){    Core_tick();}/*---------------------------------------------------------------------------*/void RTI_FlushQueueRequest(TM_Time tm){    fdkErrorCode retCode;    if ((retCode = Core_FlushQueueRequest(tm)) != fdkSUCCEEDED)    {       printf("FQR Error: %s\n",fdkErrorMessage(retCode));       exit(1);    }}/*---------------------------------------------------------------------------*/void InitRTI( int ac, char *av[] ){  int i;  fdkErrorCode retCode;  FILE *FedFile;  char ClassName[MCAST_MAX_NAME_LEN];  char *FedFileName = "fedfile"; /*XXX KALYAN*/  for (i=0; i<RTI_MAX_INSTANCES_PER_PE; i++)    RTI_InstanceTable[i] = NULL;  RTI_NextInstance = 0;  Core_RegisterDeliverOneMessage(DeliverOneMessage);  Core_RegisterDeliverTSOEvents(DeliverEvents);  Core_RegisterDeliverROEvents(DeliverROEvents);  Core_RegisterTimeAdvanceGrant(TimeAdvanceGrantWrapper);  Core_RegisterTSOMin(BRTI_TSOMin);  Core_RegisterTSOPop(BRTI_TSOPop);  /*KALYAN: User controls heap initial size & increment via env vars*/  {  char *estr = 0;  int ini_sz = (estr=getenv("BRTI_HEAPSIZE"))?atoi(estr):1000;  int ini_incr = (estr=getenv("BRTI_HEAPINCR"))?atoi(estr):10000;  printf("BRTI: Using heap size %d, growth increment %d.\n",ini_sz,ini_incr);  BRTI_InitTSOQueue(ini_sz,ini_incr);  }  RTIKIT_UsingTM();  RTIKIT_UsingMCAST();  RTIKIT_Init( ac, av );  if ((retCode = Core_InitRTI()) != fdkSUCCEEDED)  {     printf("RTI Core failed to initialize: ");     printf("%s",fdkErrorMessage(retCode));     exit(1);  }  /*   * PE zero reads fed file and does initializations   * Here, fed file is a list of Object Class Names.   * A multicast group is created for each class.   */  if (Core_federateID() == 0)  {    if (FedFileName != NULL)    {      FedFile = fopen(FedFileName, "r");      if (FedFile == NULL)      {fprintf(stderr,"Couldn't open fed file %s; ignoring...\n", FedFileName);}      else while (TRUE)      {        /* create a multicast group for each class name */        if (fscanf (FedFile, "%s", ClassName) == EOF) break;        RTI_CreateClass(ClassName);      }    }  }  RTIKIT_Barrier();}/*---------------------------------------------------------------------------*/void PrintStats(void){    printf("*************************************************************\n");  printf("                RTI Stats for Federate %d                    \n",	  (int)(Core_federateID()));  printf(" Message Anihilated Internally                 %d\n",	  MessagesAnihilated);  printf("*************************************************************\n");  fflush(stdout);}/******************************* NEW FUNCTIONS *******************************/void BRTI_InitTSOQueue(int size, int incr){  BRTI.TSOQueue = HEAP_Create(size, incr); /* create TSO priority queue */}TM_Time BRTI_TSOMin(void){  return(HEAP_Min(BRTI.TSOQueue));}char *BRTI_TSOPop(TM_Time *minTS,long *MsgSize, long *MsgType){  char *Data;  Data = HEAP_DeleteWithType(BRTI.TSOQueue,minTS,MsgSize,MsgType);  return(Data);}

⌨️ 快捷键说明

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