Exemplo n.º 1
0
Arquivo: notify.c Projeto: rolk/ug
void NotifyInit (void)
{
  /* allocate memory */
  theRouting = (int *) AllocFix(procs*sizeof(int));
  if (theRouting==NULL)
  {
    DDD_PrintError('E', 6301, STR_NOMEM " in NotifyInit");
    HARD_EXIT;
  }


  maxInfos = MAX_INFOS;                 /* TODO maximum value, just for testing */


  /* init local array for all Info records */
  allInfoBuffer = (NOTIFY_INFO *) AllocFix(maxInfos*sizeof(NOTIFY_INFO));
  if (allInfoBuffer==NULL)
  {
    DDD_PrintError('E', 6300, STR_NOMEM " in NotifyInit");
    HARD_EXIT;
  }


  /* allocate array of NOTIFY_DESCs */
  if (procs>1)
  {
    theDescs = (NOTIFY_DESC *) AllocTmp(sizeof(NOTIFY_DESC)*(procs-1));
  }
  else
  {
    theDescs = NULL;
  }
}
Exemplo n.º 2
0
Arquivo: topo.c Projeto: rolk/ug
void ddd_TopoInit (void)
{
  int i;

  /* get one channel pointer for each partner */
  theTopology = (VChannelPtr *) AllocFix(procs*sizeof(VChannelPtr));
  if (theTopology==NULL)
  {
    DDD_PrintError('E', 1500, STR_NOMEM " in TopoInit");
    return;
  }

  /* initialize channel topology */
  for(i=0; i<procs; i++)
    theTopology[i] = NULL;


  /* get proc array with maxsize = 2 * number of procs */
  theProcArray = (DDD_PROC *) AllocFix(2 * procs*sizeof(DDD_PROC));
  if (theProcArray==NULL)
  {
    DDD_PrintError('E', 1510, STR_NOMEM " in TopoInit");
    return;
  }

  theProcFlags = (int *) AllocFix(2 * procs*sizeof(int));
  if (theProcFlags==NULL)
  {
    DDD_PrintError('E', 1511, STR_NOMEM " in TopoInit");
    return;
  }
}
Exemplo n.º 3
0
Arquivo: typemgr.c Projeto: xyuan/ug
static int CheckBounds (TYPE_DESC *desc, ELEM_DESC *el, int argno)
{
  if (CPP_STRUCT(desc) CPP_AND (el->offset<0))
  {
    DDD_PrintError('E', 2400,
                   RegisterError(desc,argno, "negative offset"));
    return(ERROR);
  }
#if defined(CPP_FRONTEND)
  if (CPP_ARRAY(desc) CPP_AND (!el->array))
  {
    DDD_PrintError ('E', 2401,
                    RegisterError(desc,argno, "no array supplied"));
    return(ERROR);
  }
#endif

  if (el->size<=0)
  {
    DDD_PrintError('E', 2402,
                   RegisterError(desc,argno, "illegal element size"));
    return (ERROR);
  }

  return 0;
}
Exemplo n.º 4
0
Arquivo: jcmds.c Projeto: rolk/ug
void DDD_JoinObj (DDD_HDR hdr, DDD_PROC dest, DDD_GID new_gid)
{
    JIJoin *ji;

    if (!ddd_JoinActive())
    {
        DDD_PrintError('E', 7012, "Missing DDD_JoinBegin(). aborted");
        HARD_EXIT;
    }

    if (dest>=procs)
    {
        sprintf(cBuffer, "cannot join %08x with %08x on processor %d (procs=%d)",
                OBJ_GID(hdr), new_gid, dest, procs);
        DDD_PrintError('E', 7003, cBuffer);
        HARD_EXIT;
    }

    if (dest==me)
    {
        sprintf(cBuffer, "cannot join %08x with myself", OBJ_GID(hdr));
        DDD_PrintError('E', 7004, cBuffer);
        HARD_EXIT;
    }

    if (ObjHasCpl(hdr))
    {
        sprintf(cBuffer, "cannot join %08x, object already distributed",
                OBJ_GID(hdr));
        DDD_PrintError('E', 7005, cBuffer);
        HARD_EXIT;
    }



    ji = JIJoinSet_NewItem(joinGlobals.setJIJoin);
    ji->hdr     = hdr;
    ji->dest    = dest;
    ji->new_gid = new_gid;

    if (! JIJoinSet_ItemOK(joinGlobals.setJIJoin))
        return;

#       if DebugJoin<=2
    sprintf(cBuffer, "%4d: DDD_JoinObj %08x, dest=%d, new_gid=%08x\n",
            me, OBJ_GID(hdr), dest, new_gid);
    DDD_PrintDebug(cBuffer);
#       endif
}
Exemplo n.º 5
0
Arquivo: typemgr.c Projeto: xyuan/ug
static void ConstructEl (ELEM_DESC *elem, int t, int o, size_t s, DDD_TYPE rt)
{
  elem->type    = t;
  elem->offset  = o;
  elem->size    = s;

  /*
          for OBJPTR elements, store referenced DDD_TYPE here.
          the default is EL_DDDHDR, i.e., if this feature is
          not used, the DDD_HDR will be assumed to be at the
          beginning of each structure (offsetHeader==0).
   */
  EDESC_SET_REFTYPE(elem, rt);
  elem->reftypeHandler = NULL;

  /*
          for GBITS elements, store array of bits. 1=GDATA,
          0=LDATA.
   */
  if (t==EL_GBITS)
  {
    elem->gbits = (unsigned char *) AllocFix(s);
    if (elem->gbits==NULL)
    {
      DDD_PrintError('E', 2406, STR_NOMEM " for EL_GBITS array");
      HARD_EXIT;
    }
  }
}
Exemplo n.º 6
0
Arquivo: typemgr.c Projeto: xyuan/ug
static void ConstructEl (ELEM_DESC *elem, int t, char *a, size_t s, DDD_TYPE rt)
{
  elem->type    = t;
  elem->size    = s;

#ifdef CPP_FRONTEND
  /* in CPP, the first array entry is referenced by index 0. */
  elem->array   = a;
#else
  /* the size of one array entry (=s) is subtracted here,
     because we want to reference the first array entry
     by index 1. this is due to F77 conventions, where
     the first entry always is 1. in C, we would use 0
     as first index.
   */
  elem->array   = a - s;
#endif


  /*
          for OBJPTR elements, store referenced DDD_TYPE here.
          the default is EL_DDDHDR, i.e., if this feature is
          not used, the DDD_HDR will be assumed to be at the
          beginning of each structure (offsetHeader==0).
   */
  EDESC_SET_REFTYPE(elem, rt);
  elem->reftypeHandler = NULL;

  if (t==EL_GBITS)
  {
    /* TODO: GBITS could be supported also for CPP_FRONTEND with STORAGE_ARRAY */
    DDD_PrintError('E', 2407, "EL_GBITS currently not supported");
    HARD_EXIT;
  }
}
Exemplo n.º 7
0
Arquivo: typemgr.c Projeto: xyuan/ug
static int RecursiveRegister (TYPE_DESC *desc,
                              int i, DDD_TYPE typ, int offs, int argno)
{
  TYPE_DESC *d2 = &(theTypeDefs[typ]);
  int j;
  char       *errtxt;

  /* inherit elements of other ddd-type */
  for(j=0; j<d2->nElements && i<MAX_ELEMDESC; j++, i++)
  {
    ConstructEl(&desc->element[i],
                d2->element[j].type,
                d2->element[j].offset + offs,
                d2->element[j].size,
                EDESC_REFTYPE(&(d2->element[j])));
    if (CheckBounds(desc, &desc->element[i], argno) == ERROR)
      return(ERROR);
  }

  /* inherit other properties */
  desc->nPointers += d2->nPointers;
  if (d2->hasHeader)
  {
    if (!desc->hasHeader)
    {
      desc->hasHeader = TRUE;
      desc->offsetHeader = d2->offsetHeader + offs;
    }
    else
    {
      if (desc->offsetHeader == d2->offsetHeader+offs)
      {
        errtxt=RegisterError(desc,argno, "two DDD_HDRs, same offset");
        DDD_PrintError('W', 2408, errtxt);
      }
      else
      {
        errtxt=RegisterError(desc,argno, "only one DDD_HDR allowed");
        DDD_PrintError('E', 2409, errtxt);
        return(ERROR);
      }
    }
  }

  return i;
}
Exemplo n.º 8
0
Arquivo: ddd.c Projeto: rolk/ug
DDD_Library* DDD_Library::Instance (void)
{
  if (_instance==0)
  {
    DDD_PrintError('E', 1020, "no instance of DDD_Library exists");
    HARD_EXIT;
  }

  return _instance;
}
Exemplo n.º 9
0
Arquivo: ddd.c Projeto: rolk/ug
int DDD_GetOption (DDD_OPTION option)
{
  if (option>=OPT_END)
  {
    DDD_PrintError('E', 1091, "invalid DDD_OPTION in DDD_GetOption()");
    return 0;
  }

  return theOptions[option];
}
Exemplo n.º 10
0
Arquivo: typemgr.c Projeto: xyuan/ug
static int CheckOverlapEls (TYPE_DESC *desc)
{
  char buf[64];
  int i;
  int ok = TRUE;

  for(i=0; i<desc->nElements; i++)
  {
    ELEM_DESC *e1 = &desc->element[i];

    if (i<desc->nElements-1)
    {
      ELEM_DESC *e2 = &desc->element[i+1];

      if (CPP_STRUCT(desc) CPP_AND (e1->offset+e1->size > e2->offset))
      {
        ok = FALSE;
        sprintf(buf, "element too big (offset=%d)", e1->offset);
        DDD_PrintError('E', 2403, RegisterError(desc, 0, buf));
      }
#if defined(CPP_FRONTEND)
      if (CPP_ARRAY(desc) CPP_AND
            (e1->array+(e1->size*desc->arraySize) > e2->array))
      {
        ok = FALSE;
        sprintf(buf, "element too big (array=%d)", i);
        DDD_PrintError('E', 2404, RegisterError(desc, 0, buf));
      }
#endif
    }

    else
    {
      if (CPP_STRUCT(desc) CPP_AND (e1->offset+e1->size > desc->size))
      {
        ok = FALSE;
        sprintf(buf, "element too big (offset=%d)", e1->offset);
        DDD_PrintError('E', 2405, RegisterError(desc, 0, buf));
      }
    }
  }
  return ok;
}
Exemplo n.º 11
0
Arquivo: typemgr.c Projeto: xyuan/ug
static int RecursiveRegister (TYPE_DESC *desc,
                              int i, DDD_TYPE typ, char *adr, int argno)
{
  TYPE_DESC *d2 = &(theTypeDefs[typ]);
  char       *errtxt;

  if (CPP_ARRAY(d2))
  {
    errtxt=RegisterError(desc,argno,
                         "cannot include array-like type into array-like type");
    DDD_PrintError('W', 2410, errtxt);
    return(ERROR);
  }

  ConstructEl(&desc->element[i], typ, adr, d2->size, 0);
  if (CheckBounds(desc, &desc->element[i], argno) == ERROR)
    return(ERROR);

  desc->size += d2->size;

  /* inherit other properties */
  desc->nPointers += d2->nPointers;
  if (d2->hasHeader)
  {
    if (!desc->hasHeader)
    {
      desc->hasHeader = TRUE;
      desc->elemHeader = i;
      desc->offsetHeader = d2->offsetHeader;
    }
    else
    {
      errtxt=RegisterError(desc,argno, "only one DDD_HDR allowed");
      DDD_PrintError('E', 2411, errtxt);
      return(ERROR);
    }
  }

  return i+1;
}
Exemplo n.º 12
0
Arquivo: join.c Projeto: xyuan/ug
int JoinStepMode (int old)
{
  if (joinGlobals.joinMode!=old)
  {
    sprintf(cBuffer, "wrong join-mode (currently in %s, expected %s)",
            JoinModeName(joinGlobals.joinMode), JoinModeName(old));
    DDD_PrintError('E', 7200, cBuffer);
    return FALSE;
  }

  JoinSetMode(JoinSuccMode(joinGlobals.joinMode));
  return TRUE;
}
Exemplo n.º 13
0
Arquivo: jcmds.c Projeto: rolk/ug
void DDD_JoinBegin (void)
#endif
{
    /* step mode and check whether call to JoinBegin is valid */
    if (!JoinStepMode(JMODE_IDLE))
    {
        DDD_PrintError('E', 7010, "DDD_JoinBegin() aborted");
        HARD_EXIT;
    }


    /* set kind of TMEM alloc/free requests */
    join_SetTmpMem(TMEM_JOIN);
}
Exemplo n.º 14
0
Arquivo: notify.c Projeto: rolk/ug
NOTIFY_DESC *DDD_NotifyBegin (int n)
{
  nSendDescs = n;

  /* allocation of theDescs is done in NotifyInit() */

  if (n>procs-1)
  {
    DDD_PrintError('E', 6340,
                   "more send-messages than other processors in DDD_NotifyBegin");
    return(NULL);
  }

  return(theDescs);
}
Exemplo n.º 15
0
Arquivo: ifobjsc.c Projeto: rolk/ug
/*
        create direct link from ifHead and ifAttr to objects,
        avoid one indirect addressing step across couplings.
        each cpl-entry in an interface has one corresponding obj-entry
 */
void IFCreateObjShortcut (DDD_IF ifId)
{
  COUPLING    **cplarray = theIF[ifId].cpl;
  IFObjPtr     *objarray;
  IF_PROC     *ifHead;

  /* dont create shortcuts for STD_INTERFACE */
  if (ifId==STD_INTERFACE)
    return;

  /* are there any items? */
  if (theIF[ifId].nItems == 0)
    return;

  /* get memory for addresses of objects inside IF */
  objarray = (IFObjPtr *) AllocIF(sizeof(IFObjPtr)*theIF[ifId].nItems);
  if (objarray==NULL) {
    DDD_PrintError('E', 4000, STR_NOMEM " in IFCreateObjShortcut");
    HARD_EXIT;
  }
  theIF[ifId].obj = objarray;

  IFComputeShortcutTable(ifId);


  ForIF(ifId,ifHead)
  {
    IF_ATTR  *ifAttr;

    /* compute pointers to subarrays */
    ifHead->obj    = objarray + (ifHead->cpl    - cplarray);
    ifHead->objAB  = objarray + (ifHead->cplAB  - cplarray);
    ifHead->objBA  = objarray + (ifHead->cplBA  - cplarray);
    ifHead->objABA = objarray + (ifHead->cplABA - cplarray);


    /* compute pointers from ifAttrs to subarrays */
    for(ifAttr=ifHead->ifAttr; ifAttr!=0; ifAttr=ifAttr->next)
    {
      ifAttr->objAB  = objarray + (ifAttr->cplAB  - cplarray);
      ifAttr->objBA  = objarray + (ifAttr->cplBA  - cplarray);
      ifAttr->objABA = objarray + (ifAttr->cplABA - cplarray);
    }
  }
Exemplo n.º 16
0
Arquivo: ddd.c Projeto: rolk/ug
void DDD_SetOption (DDD_OPTION option, int value)
{
#endif
#ifdef CPP_FRONTEND
void DDD_Library::SetOption (DDD_OPTION option, int value)
{
#endif
#ifdef F_FRONTEND
void DDD_SetOption (DDD_OPTION *_option, int *_value)
{
  DDD_OPTION option = *_option;
  int value = *_value;
#endif
if (option>=OPT_END)
{
  DDD_PrintError('E', 1090, "invalid DDD_OPTION in DDD_SetOption()");
  return;
}

ddd_SetOption(option, value);
}
Exemplo n.º 17
0
Arquivo: typemgr.c Projeto: xyuan/ug
void DDD_Library::TypeDefine (DDD_TYPE typ, ...)
#endif

{
  TYPE_DESC *desc;
  size_t argsize;
  char      *argp;
  int argtyp, argno;
  DDD_TYPE argrefs;
  int i, nPtr;
  char      *errtxt;
  va_list ap;
  char      *adr;
  char      *gbits;
#if defined(CPP_FRONTEND)
  int size;
  int offset;
#endif

  /* TODO: only master should be able to define types, other
          procs should receive the correct definition from master.
          (with the current implementation inconsistencies might occur)
   */

  /* test whether typ is valid */
  if (typ>=nDescr)
  {
    DDD_PrintError('E', 2414,
                   "invalid DDD_TYPE in DDD_TypeDefine");
    HARD_EXIT;             /*return;*/
  }

  /* get object description */
  desc = &(theTypeDefs[typ]);
  desc->currTypeDefCall++;

  if (desc->mode!=DDD_TYPE_DECLARED && desc->mode!=DDD_TYPE_CONTDEF)
  {
    if (desc->mode==DDD_TYPE_DEFINED)
    {
      DDD_PrintError('E', 2415,
                     RegisterError(desc, 0, "DDD_TYPE already defined"));
    }
    else
    {
      DDD_PrintError('E', 2416,
                     RegisterError(desc, 0, "undeclared DDD_TYPE"));
    }
    HARD_EXIT;             /*return;*/
  }


  /* initialize TYPE_DESC struct, only on first call */
  if (desc->currTypeDefCall==1)
    ConstructDesc(desc);


  if (typ==0)        /* i.e. typ==EL_DDDHDR */
  {
    /* DDD_HDR also contains a DDD_HDR (sic!) */
    desc->hasHeader = TRUE;
  }

#       ifdef DebugTypeDefine
  sprintf(cBuffer,"   DDD_TypeDefine(%s/%d)\n",
          desc->name, desc->currTypeDefCall);
  DDD_PrintDebug(cBuffer);
#       endif


  /* start variable arguments after "typ"-parameter */
  va_start(ap, typ);

#ifdef C_FRONTEND
  adr = va_arg(ap, char *);
  argno = 2;
#endif

#ifdef CPP_FRONTEND
  if (CPP_STRUCT(desc))
  {
    adr = va_arg(ap, char *);
    argno = 2;
  }
  else
  {
Exemplo n.º 18
0
Arquivo: typemgr.c Projeto: xyuan/ug
static void AttachMask (TYPE_DESC *desc)
{
  int i, k;
  ELEM_DESC *e;
  unsigned char  *mp;
  unsigned char mask;

  /* get storage for mask */
  desc->cmask = (unsigned char *)AllocFix(desc->size);
  if (desc->cmask==0)
  {
    DDD_PrintError('E', 2413,
                   RegisterError(desc,0, STR_NOMEM));
    HARD_EXIT;             /*return;*/
  }

  /* set default: EL_LDATA for unspecified regions (gaps) */
  for(i=0; i<desc->size; i++)
  {
    desc->cmask[i] = 0x00;                    /* dont-copy-flag */
  }

  /* create mask from element list */
  for(i=0; i<desc->nElements; i++)
  {
    e = &desc->element[i];
    mp = desc->cmask + e->offset;

    switch (e->type)
    {
    case EL_LDATA :
    case EL_OBJPTR :                        /* OBJPTR are LDATA!!! */
      mask = 0x00;                              /* dont-copy-flag */
      break;

    case EL_GDATA :
    case EL_DATAPTR :
      mask = 0xff;                              /* copy-flag */
      break;
    }

    for(k=0; k<e->size; k++)
    {
      if (e->type==EL_GBITS)
      {
        mp[k] = e->gbits[k];                           /* copy bitwise */
      }
      else
      {
        mp[k] = mask;
      }
    }
  }

#       ifdef DebugCopyMask
  if (me==master)
  {
    char buf[8];

    sprintf(cBuffer, "%4d: AttachMask for %s:", me, desc->name);
    for(i=0; i<desc->size; i++)
    {
      if (i%8==0)
      {
        strcat(cBuffer,"\n");
        DDD_PrintLine(cBuffer);
        sprintf(cBuffer,"  %4d:  ", i);
      }
      sprintf(buf, "%02x ", desc->cmask[i]);
      strcat(cBuffer, buf);
    }
    strcat(cBuffer,"\n");
    DDD_PrintLine(cBuffer);
  }
#       endif
}
Exemplo n.º 19
0
Arquivo: jcmds.c Projeto: rolk/ug
static int PreparePhase1Msgs (JIJoinPtrArray *arrayJoin,
                              JOINMSG1 **theMsgs, size_t *memUsage)
{
    int i, last_i, nMsgs;
    JIJoin   **itemsJ = JIJoinPtrArray_GetData(arrayJoin);
    int nJ       = JIJoinPtrArray_GetSize(arrayJoin);

#       if DebugJoin<=3
    printf("%4d: PreparePhase1Msgs, nJoins=%d\n",
           me, nJ);
    fflush(stdout);
#       endif

    /* init return parameters */
    *theMsgs = NULL;
    *memUsage = 0;


    if (nJ==0)
        /* no messages */
        return(0);


    /* check whether Join objects are really local (without copies) */
    /* and set local GID to invalid (will be set to new value lateron) */
    for(i=0; i<nJ; i++)
    {
        if (ObjHasCpl(itemsJ[i]->hdr))
        {
            sprintf(cBuffer, "cannot join %08x, object already distributed",
                    OBJ_GID(itemsJ[i]->hdr));
            DDD_PrintError('E', 7006, cBuffer);
            HARD_EXIT;
        }

        OBJ_GID(itemsJ[i]->hdr) = GID_INVALID;
    }


    /* set local GID to new value */
    for(i=0; i<nJ; i++)
    {
        DDD_GID local_gid = OBJ_GID(itemsJ[i]->hdr);

        /* check for double Joins with different new_gid */
        if (local_gid!=GID_INVALID && local_gid!=itemsJ[i]->new_gid)
        {
            sprintf(cBuffer,
                    "several (inconsistent) DDD_JoinObj-commands for local object %08x",
                    local_gid);
            DDD_PrintError('E', 7007, cBuffer);
            HARD_EXIT;
        }

        OBJ_GID(itemsJ[i]->hdr) = itemsJ[i]->new_gid;
    }


    nMsgs = 0;
    last_i = i = 0;
    do
    {
        JOINMSG1  *jm;
        size_t bufSize;

        /* skip until dest-processor is different */
        while (i<nJ && (itemsJ[i]->dest == itemsJ[last_i]->dest))
            i++;

        /* create new message */
        jm = (JOINMSG1 *) AllocTmp(sizeof(JOINMSG1));
        if (jm==NULL)
        {
            DDD_PrintError('E', 7900, STR_NOMEM " in PreparePhase1Msgs");
            HARD_EXIT;
        }
        jm->nJoins = i-last_i;
        jm->arrayJoin = &(itemsJ[last_i]);
        jm->dest = itemsJ[last_i]->dest;
        jm->next = *theMsgs;
        *theMsgs = jm;
        nMsgs++;

        /* create new send message */
        jm->msg_h = LC_NewSendMsg(joinGlobals.phase1msg_t, jm->dest);

        /* init table inside message */
        LC_SetTableSize(jm->msg_h, joinGlobals.jointab_id, jm->nJoins);

        /* prepare message for sending away */
        bufSize = LC_MsgPrepareSend(jm->msg_h);
        *memUsage += bufSize;

        if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MEMUSAGE)
        {
            sprintf(cBuffer,
                    "DDD MESG [%03d]: SHOW_MEM "
                    "send msg phase1   dest=%04d size=%010ld\n",
                    me, jm->dest, (long)bufSize);
            DDD_PrintLine(cBuffer);
        }

        last_i = i;

    } while (last_i < nJ);

    return(nMsgs);
}
Exemplo n.º 20
0
Arquivo: jcmds.c Projeto: rolk/ug
static void UnpackPhase1Msgs (LC_MSGHANDLE *theMsgs, int nRecvMsgs,
                              DDD_HDR *localCplObjs, int nLCO,
                              JIPartner **p_joinObjs, int *p_nJoinObjs)
{
    JIPartner *joinObjs;
    int nJoinObjs = 0;
    int m, jo;

    /* init return values */
    *p_joinObjs  = NULL;
    *p_nJoinObjs = 0;


    for(m=0; m<nRecvMsgs; m++)
    {
        LC_MSGHANDLE jm = theMsgs[m];
        TEJoin *theJoin = (TEJoin *) LC_GetPtr(jm, joinGlobals.jointab_id);
        int nJ       = (int) LC_GetTableLen(jm, joinGlobals.jointab_id);
        int i, j;

        nJoinObjs += nJ;

        for(i=0, j=0; i<nJ; i++)
        {
            while ((j<nLCO) && (OBJ_GID(localCplObjs[j]) < theJoin[i].gid))
                j++;

            if ((j<nLCO) && (OBJ_GID(localCplObjs[j])==theJoin[i].gid))
            {
                COUPLING *cpl;

                /* found local object which is join target */
                /* store shortcut to local object */
                theJoin[i].hdr = localCplObjs[j];

                /* generate phase2-JIAddCpl for this object */
                for(cpl=ObjCplList(localCplObjs[j]); cpl!=NULL; cpl=CPL_NEXT(cpl))
                {
                    JIAddCpl *ji = JIAddCplSet_NewItem(joinGlobals.setJIAddCpl2);
                    ji->dest    = CPL_PROC(cpl);
                    ji->te.gid  = theJoin[i].gid;
                    ji->te.proc = LC_MsgGetProc(jm);
                    ji->te.prio = theJoin[i].prio;

                    if (! JIAddCplSet_ItemOK(joinGlobals.setJIAddCpl2))
                        continue;

#                                       if DebugJoin<=1
                    printf("%4d: Phase1 Join for %08x from %d, "
                           "send AddCpl to %d.\n",
                           me, theJoin[i].gid, ji->te.proc, ji->dest);
#                                       endif

                }

                /* send phase3-JIAddCpl back to Join-proc */
                for(cpl=ObjCplList(localCplObjs[j]); cpl!=NULL; cpl=CPL_NEXT(cpl))
                {
                    JIAddCpl *ji = JIAddCplSet_NewItem(joinGlobals.setJIAddCpl3);
                    ji->dest    = LC_MsgGetProc(jm);
                    ji->te.gid  = OBJ_GID(localCplObjs[j]);
                    ji->te.proc = CPL_PROC(cpl);
                    ji->te.prio = cpl->prio;

                    if (! JIAddCplSet_ItemOK(joinGlobals.setJIAddCpl3))
                        continue;
                }
            }
            else
            {
                sprintf(cBuffer, "no object %08x for join from %d",
                        theJoin[i].gid, LC_MsgGetProc(jm));
                DDD_PrintError('E', 7300, cBuffer);
                HARD_EXIT;
            }
        }
    }


    /* return immediately if no join-objects have been found */
    if (nJoinObjs==0)
        return;


    /* allocate array of objects, which has been contacted by a join */
    joinObjs = (JIPartner *) AllocTmp(sizeof(JIPartner) * nJoinObjs);
    if (joinObjs==NULL)
    {
        DDD_PrintError('E', 7903, STR_NOMEM " in UnpackPhase1Msgs");
        HARD_EXIT;
    }

    /* set return values */
    *p_joinObjs  = joinObjs;
    *p_nJoinObjs = nJoinObjs;


    /* add one local coupling for each Join */
    for(m=0, jo=0; m<nRecvMsgs; m++)
    {
        LC_MSGHANDLE jm = theMsgs[m];
        TEJoin *theJoin = (TEJoin *) LC_GetPtr(jm, joinGlobals.jointab_id);
        int nJ       = (int) LC_GetTableLen(jm, joinGlobals.jointab_id);
        int i;

        for(i=0; i<nJ; i++)
        {
            AddCoupling(theJoin[i].hdr, LC_MsgGetProc(jm), theJoin[i].prio);

            /* send one phase3-JIAddCpl for symmetric connection */
            {
                JIAddCpl *ji = JIAddCplSet_NewItem(joinGlobals.setJIAddCpl3);
                ji->dest    = LC_MsgGetProc(jm);
                ji->te.gid  = OBJ_GID(theJoin[i].hdr);
                ji->te.proc = me;
                ji->te.prio = OBJ_PRIO(theJoin[i].hdr);

                JIAddCplSet_ItemOK(joinGlobals.setJIAddCpl3);
            }

            joinObjs[jo].hdr  = theJoin[i].hdr;
            joinObjs[jo].proc = LC_MsgGetProc(jm);
            jo++;
        }
    }


    /* sort joinObjs-array according to gid */
    if (nJoinObjs>1)
        qsort(joinObjs, nJoinObjs, sizeof(JIPartner), sort_Gid);
}
Exemplo n.º 21
0
Arquivo: jcmds.c Projeto: rolk/ug
static int PreparePhase3Msgs (JIAddCplPtrArray *arrayAddCpl,
                              JOINMSG3 **theMsgs, size_t *memUsage)
{
    int i, last_i, nMsgs;
    JIAddCpl **itemsAC = JIAddCplPtrArray_GetData(arrayAddCpl);
    int nAC       = JIAddCplPtrArray_GetSize(arrayAddCpl);

#       if DebugJoin<=3
    printf("%4d: PreparePhase3Msgs, nAddCpls=%d\n",
           me, nAC);
    fflush(stdout);
#       endif

    /* init return parameters */
    *theMsgs = NULL;
    *memUsage = 0;


    if (nAC==0)
        /* no messages */
        return(0);


    nMsgs = 0;
    last_i = i = 0;
    do
    {
        JOINMSG3  *jm;
        size_t bufSize;

        /* skip until dest-processor is different */
        while (i<nAC && (itemsAC[i]->dest == itemsAC[last_i]->dest))
            i++;

        /* create new message */
        jm = (JOINMSG3 *) AllocTmp(sizeof(JOINMSG3));
        if (jm==NULL)
        {
            DDD_PrintError('E', 7902, STR_NOMEM " in PreparePhase3Msgs");
            HARD_EXIT;
        }
        jm->nAddCpls = i-last_i;
        jm->arrayAddCpl = &(itemsAC[last_i]);
        jm->dest = itemsAC[last_i]->dest;
        jm->next = *theMsgs;
        *theMsgs = jm;
        nMsgs++;

        /* create new send message */
        jm->msg_h = LC_NewSendMsg(joinGlobals.phase3msg_t, jm->dest);

        /* init table inside message */
        LC_SetTableSize(jm->msg_h, joinGlobals.cpltab_id, jm->nAddCpls);

        /* prepare message for sending away */
        bufSize = LC_MsgPrepareSend(jm->msg_h);
        *memUsage += bufSize;

        if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MEMUSAGE)
        {
            sprintf(cBuffer,
                    "DDD MESG [%03d]: SHOW_MEM "
                    "send msg phase3   dest=%04d size=%010ld\n",
                    me, jm->dest, (long)bufSize);
            DDD_PrintLine(cBuffer);
        }

        last_i = i;

    } while (last_i < nAC);

    return(nMsgs);
}
Exemplo n.º 22
0
Arquivo: jcmds.c Projeto: rolk/ug
DDD_RET DDD_JoinEnd (void)
#endif
{
    JIJoinPtrArray   *arrayJIJoin    = NULL;
    JIAddCplPtrArray *arrayJIAddCpl2 = NULL;
    JIAddCplPtrArray *arrayJIAddCpl3 = NULL;
    int obsolete, nRecvMsgs1, nRecvMsgs2, nRecvMsgs3, nSendMsgs;
    JOINMSG1    *sendMsgs1=NULL, *sm1=NULL;
    JOINMSG2    *sendMsgs2=NULL, *sm2=NULL;
    JOINMSG3    *sendMsgs3=NULL, *sm3=NULL;
    LC_MSGHANDLE *recvMsgs1=NULL, *recvMsgs2=NULL, *recvMsgs3=NULL;
    DDD_HDR     *localCplObjs=NULL;
    size_t sendMem=0, recvMem=0;
    JIPartner   *joinObjs = NULL;
    int nJoinObjs;



#ifdef JoinMemFromHeap
    MarkHeap();
    LC_SetMemMgr(memmgr_AllocTMEM, memmgr_FreeTMEM,
                 memmgr_AllocHMEM, NULL);
#endif

    STAT_SET_MODULE(DDD_MODULE_JOIN);
    STAT_ZEROALL;

    /* step mode and check whether call to JoinEnd is valid */
    if (!JoinStepMode(JMODE_CMDS))
    {
        DDD_PrintError('E', 7011, "DDD_JoinEnd() aborted");
        HARD_EXIT;
    }


    /*
            PREPARATION PHASE
     */
    /* get sorted array of JIJoin-items */
    arrayJIJoin = JIJoinSet_GetArray(joinGlobals.setJIJoin);
    obsolete = JIJoinSet_GetNDiscarded(joinGlobals.setJIJoin);


    /*
            COMMUNICATION PHASE 1
            all processors, where JoinObj-commands have been issued,
            send information about these commands to the target
            processors together with the GID of the objects on the
            target procs and the local priority.
     */
    STAT_RESET;
    /* prepare msgs for JIJoin-items */
    nSendMsgs = PreparePhase1Msgs(arrayJIJoin, &sendMsgs1, &sendMem);
    /* DisplayMemResources(); */

    /* init communication topology */
    nRecvMsgs1 = LC_Connect(joinGlobals.phase1msg_t);
    STAT_TIMER(T_JOIN_PREP_MSGS);

    STAT_RESET;
    /* build phase1 msgs on sender side and start send */
    PackPhase1Msgs(sendMsgs1);
    STAT_TIMER(T_JOIN_PACK_SEND);


    /*
            now messages are in the net, use spare time
     */
    STAT_RESET;
    /* get sorted list of local objects with couplings */
    localCplObjs = LocalCoupledObjectsList();
    if (localCplObjs==NULL && ddd_nCpls>0)
    {
        DDD_PrintError('E', 7020,
                       "Cannot get list of coupled objects in DDD_JoinEnd(). Aborted");
        HARD_EXIT;
    }


    if (obsolete>0)
    {
        if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_OBSOLETE)
        {
            int all = JIJoinSet_GetNItems(joinGlobals.setJIJoin);

            sprintf(cBuffer, "DDD MESG [%03d]: %4d from %4d join-cmds obsolete.\n",
                    me, obsolete, all);
            DDD_PrintLine(cBuffer);
        }
    }
    STAT_TIMER(T_JOIN);


    /*
            nothing more to do until incoming messages arrive
     */

    /* display information about send-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase1Msg.Send\n");
        LC_PrintSendMsgs();
    }


    /* wait for communication-completion (send AND receive) */
    STAT_RESET;
    recvMsgs1 = LC_Communicate();
    STAT_TIMER(T_JOIN_WAIT_RECV);


    /* display information about message buffer sizes */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MEMUSAGE)
    {
        int k;

        /* sum up sizes of receive mesg buffers */
        for(k=0; k<nRecvMsgs1; k++)
        {
            recvMem += LC_GetBufferSize(recvMsgs1[k]);
        }

        sprintf(cBuffer,
                "DDD MESG [%03d]: SHOW_MEM "
                "msgs  send=%010ld recv=%010ld all=%010ld\n",
                me, (long)sendMem, (long)recvMem, (long)(sendMem+recvMem));
        DDD_PrintLine(cBuffer);
    }

    /* display information about recv-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase1Msg.Recv\n");
        LC_PrintRecvMsgs();
    }

    /* unpack messages */
    STAT_RESET;
    UnpackPhase1Msgs(recvMsgs1, nRecvMsgs1, localCplObjs, NCpl_Get,
                     &joinObjs, &nJoinObjs);
    LC_Cleanup();
    STAT_TIMER(T_JOIN_UNPACK);





    /*
            COMMUNICATION PHASE 2
            all processors which received notification of JoinObj-commands
            during phase 1 send AddCpl-requests to all copies of DDD objects,
            for which Joins had been issued remotely.
     */
    /* get sorted array of JIAddCpl-items */
    arrayJIAddCpl2 = JIAddCplSet_GetArray(joinGlobals.setJIAddCpl2);

    STAT_RESET;
    /* prepare msgs for JIAddCpl-items */
    nSendMsgs = PreparePhase2Msgs(arrayJIAddCpl2, &sendMsgs2, &sendMem);
    /* DisplayMemResources(); */

    /* init communication topology */
    nRecvMsgs2 = LC_Connect(joinGlobals.phase2msg_t);
    STAT_TIMER(T_JOIN_PREP_MSGS);

    STAT_RESET;
    /* build phase2 msgs on sender side and start send */
    PackPhase2Msgs(sendMsgs2);
    STAT_TIMER(T_JOIN_PACK_SEND);

    /*
            now messages are in the net, use spare time
     */

    /* reorder Join-commands according to new_gid */
    /* this ordering is needed in UnpackPhase3 */
    if (JIJoinPtrArray_GetSize(arrayJIJoin) > 1)
    {
        qsort(
            JIJoinPtrArray_GetData(arrayJIJoin),
            JIJoinPtrArray_GetSize(arrayJIJoin),
            sizeof(JIJoin *), sort_NewGid);
    }


    /*
            nothing more to do until incoming messages arrive
     */

    /* display information about send-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase2Msg.Send\n");
        LC_PrintSendMsgs();
    }


    /* wait for communication-completion (send AND receive) */
    STAT_RESET;
    recvMsgs2 = LC_Communicate();
    STAT_TIMER(T_JOIN_WAIT_RECV);


    /* display information about message buffer sizes */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MEMUSAGE)
    {
        int k;

        /* sum up sizes of receive mesg buffers */
        for(k=0; k<nRecvMsgs2; k++)
        {
            recvMem += LC_GetBufferSize(recvMsgs2[k]);
        }

        sprintf(cBuffer,
                "DDD MESG [%03d]: SHOW_MEM "
                "msgs  send=%010ld recv=%010ld all=%010ld\n",
                me, (long)sendMem, (long)recvMem, (long)(sendMem+recvMem));
        DDD_PrintLine(cBuffer);
    }

    /* display information about recv-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase2Msg.Recv\n");
        LC_PrintRecvMsgs();
    }

    /* unpack messages */
    STAT_RESET;
    UnpackPhase2Msgs(recvMsgs2, nRecvMsgs2, joinObjs, nJoinObjs,
                     localCplObjs, NCpl_Get);

    LC_Cleanup();
    STAT_TIMER(T_JOIN_UNPACK);

    for(; sendMsgs2!=NULL; sendMsgs2=sm2)
    {
        sm2 = sendMsgs2->next;
        FreeTmp(sendMsgs2, 0);
    }






    /*
            COMMUNICATION PHASE 3
            all processors which received notification of JoinObj-commands
            during phase 1 send AddCpl-requests to the procs where the
            JoinObj-commands have been issued. One AddCpl-request is sent
            for each cpl in the local objects coupling list. One AddCpl-request
            is sent for each AddCpl-request received during phase 2.
            (i.e., two kinds of AddCpl-requests are send to the processors
            on which the JoinObj-commands have been issued.
     */
    /* get sorted array of JIAddCpl-items */
    arrayJIAddCpl3 = JIAddCplSet_GetArray(joinGlobals.setJIAddCpl3);

    STAT_RESET;
    /* prepare msgs for JIAddCpl-items */
    nSendMsgs = PreparePhase3Msgs(arrayJIAddCpl3, &sendMsgs3, &sendMem);
    /* DisplayMemResources(); */

    /* init communication topology */
    nRecvMsgs3 = LC_Connect(joinGlobals.phase3msg_t);
    STAT_TIMER(T_JOIN_PREP_MSGS);

    STAT_RESET;
    /* build phase3 msgs on sender side and start send */
    PackPhase3Msgs(sendMsgs3);
    STAT_TIMER(T_JOIN_PACK_SEND);

    /*
            now messages are in the net, use spare time
     */
    /* ... */

    /*
            nothing more to do until incoming messages arrive
     */

    /* display information about send-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase3Msg.Send\n");
        LC_PrintSendMsgs();
    }


    /* wait for communication-completion (send AND receive) */
    STAT_RESET;
    recvMsgs3 = LC_Communicate();
    STAT_TIMER(T_JOIN_WAIT_RECV);


    /* display information about message buffer sizes */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MEMUSAGE)
    {
        int k;

        /* sum up sizes of receive mesg buffers */
        for(k=0; k<nRecvMsgs3; k++)
        {
            recvMem += LC_GetBufferSize(recvMsgs3[k]);
        }

        sprintf(cBuffer,
                "DDD MESG [%03d]: SHOW_MEM "
                "msgs  send=%010ld recv=%010ld all=%010ld\n",
                me, (long)sendMem, (long)recvMem, (long)(sendMem+recvMem));
        DDD_PrintLine(cBuffer);
    }

    /* display information about recv-messages on lowcomm-level */
    if (DDD_GetOption(OPT_INFO_JOIN) & JOIN_SHOW_MSGSALL)
    {
        DDD_SyncAll();
        if (me==master)
            DDD_PrintLine("DDD JOIN_SHOW_MSGSALL: Phase3Msg.Recv\n");
        LC_PrintRecvMsgs();
    }

    /* unpack messages */
    STAT_RESET;
    UnpackPhase3Msgs(recvMsgs3, nRecvMsgs3, arrayJIJoin);
    LC_Cleanup();
    STAT_TIMER(T_JOIN_UNPACK);

    for(; sendMsgs3!=NULL; sendMsgs3=sm3)
    {
        sm3 = sendMsgs3->next;
        FreeTmp(sendMsgs3, 0);
    }






    /*
            free temporary storage
     */
    JIJoinPtrArray_Free(arrayJIJoin);
    JIJoinSet_Reset(joinGlobals.setJIJoin);

    JIAddCplPtrArray_Free(arrayJIAddCpl2);
    JIAddCplSet_Reset(joinGlobals.setJIAddCpl2);

    JIAddCplPtrArray_Free(arrayJIAddCpl3);
    JIAddCplSet_Reset(joinGlobals.setJIAddCpl3);

    if (localCplObjs!=NULL) FreeTmp(localCplObjs, 0);

    if (joinObjs!=NULL) FreeTmp(joinObjs, 0);

    for(; sendMsgs1!=NULL; sendMsgs1=sm1)
    {
        sm1 = sendMsgs1->next;
        FreeTmp(sendMsgs1, 0);
    }



#ifdef JoinMemFromHeap
    ReleaseHeap();
    LC_SetMemMgr(memmgr_AllocTMEM, memmgr_FreeTMEM,
                 memmgr_AllocTMEM, memmgr_FreeTMEM);
#endif

#       if DebugJoin<=4
    sprintf(cBuffer,"%4d: JoinEnd, before IFAllFromScratch().\n", me);
    DDD_PrintDebug(cBuffer);
#       endif

    /* re-create all interfaces and step JMODE */
    STAT_RESET;
    IFAllFromScratch();
    STAT_TIMER(T_JOIN_BUILD_IF);


    JoinStepMode(JMODE_BUSY);

    return(DDD_RET_OK);
}
Exemplo n.º 23
0
Arquivo: ddd.c Projeto: rolk/ug
DDD_Library::DDD_Library (int *argcp, char ***argvp)
#endif

{
#ifdef CPP_FRONTEND
  // check existence of another instance of DDD_Library
  if (_instance!=0)
  {
    DDD_PrintError('E', 1021,
                   "construction of two instances of DDD_Library is not allowed");
    HARD_EXIT;
  }
#endif

  int buffsize;

  /* init lineout-interface to stdout */
  DDD_UserLineOutFunction = NULL;

  /* if first arg is NULL, we assume that PPIF has been initialized elsewhere */
  if (argcp!=NULL)
  {
    /* init PPIF */
    if (InitPPIF(argcp, argvp) != PPIF_SUCCESS)
    {
      DDD_PrintError('E', 1005, "PPIF initialization failed");
      HARD_EXIT;
    }
  }


  /*
     printf("%4d: process_id=%d\n", me, getpid());
   */


  /* check max. number of procs (limited by GID construction) */
  if (procs>MAX_PROCS) {
    DDD_PrintError('E', 1010,
                   "too many processors, cannot construct global IDs in DDD_Init");
    HARD_EXIT;
  }

  /* compute size for general buffer */
  buffsize = (procs+1)*(sizeof(int)*BUFFER_SIZE_FACTOR);
  if (buffsize<MIN_BUFFER_SIZE)
  {
    buffsize = MIN_BUFFER_SIZE;
  }

  /* get bufferspace */
  iBuffer = (int *)AllocFix(buffsize);
  if (iBuffer==NULL) {
    DDD_PrintError('E', 1000, "not enough memory in DDD_Init");
    HARD_EXIT;
  }
  /* overlay with other buffers */
  cBuffer = (char *)iBuffer;

  /* init all DDD components */
  NotifyInit();
  LC_Init(LowComm_DefaultAlloc, LowComm_DefaultFree);
  ddd_StatInit();
  ddd_TypeMgrInit();
  ddd_ObjMgrInit();
  ddd_CplMgrInit();
  ddd_TopoInit();
  ddd_IdentInit();
  ddd_IFInit();
  ddd_XferInit();
  ddd_PrioInit();
  ddd_JoinInit();
  ddd_ConsInit();

  /* reset all global counters */
  ddd_nObjs  = 0;
  NCpl_Init;
  nCplItems  = 0;

  /* set options on default values */
  ddd_SetOption(OPT_WARNING_VARSIZE_OBJ,   OPT_ON);
  ddd_SetOption(OPT_WARNING_SMALLSIZE,     OPT_ON);
  ddd_SetOption(OPT_WARNING_PRIOCHANGE,    OPT_ON);
  ddd_SetOption(OPT_WARNING_DESTRUCT_HDR,  OPT_ON);
  ddd_SetOption(OPT_DEBUG_XFERMESGS,       OPT_OFF);
  ddd_SetOption(OPT_QUIET_CONSCHECK,       OPT_OFF);
  ddd_SetOption(OPT_IDENTIFY_MODE,         IDMODE_LISTS);
  ddd_SetOption(OPT_WARNING_REF_COLLISION, OPT_ON);
  ddd_SetOption(OPT_INFO_XFER,             XFER_SHOW_NONE);
  ddd_SetOption(OPT_INFO_JOIN,             JOIN_SHOW_NONE);
  ddd_SetOption(OPT_WARNING_OLDSTYLE,      OPT_ON);
  ddd_SetOption(OPT_INFO_IF_WITH_ATTR,     OPT_OFF);
  ddd_SetOption(OPT_XFER_PRUNE_DELETE,     OPT_OFF);
  ddd_SetOption(OPT_IF_REUSE_BUFFERS,      OPT_OFF);
  ddd_SetOption(OPT_IF_CREATE_EXPLICIT,    OPT_OFF);
  ddd_SetOption(OPT_CPLMGR_USE_FREELIST,   OPT_ON);

#ifdef CPP_FRONTEND
  // remember pointer to singleton
  _instance = this;
#endif
}
Exemplo n.º 24
0
Arquivo: topo.c Projeto: rolk/ug
RETCODE DDD_GetChannels (int nPartners)
{
  int i, nConn;

  if (nPartners>2*(procs-1))
  {
    DDD_PrintError('E', 1520, "topology error in DDD_GetChannels");
    RET_ON_ERROR;
  }

  nConn = 0;
  for(i=0; i<nPartners; i++)
  {
    if (theTopology[theProcArray[i]]==NULL)
    {
      VChannelPtr vc = ConnASync(theProcArray[i], VC_TOPO);

      if (vc==NULL)
      {
        sprintf(cBuffer,
                "can't connect to proc=%d in DDD_GetChannels",
                theProcArray[i]);
        DDD_PrintError('E', 1521, cBuffer);
        RET_ON_ERROR;
      }

      theTopology[theProcArray[i]] = vc;
      nConn++;

      theProcFlags[i] = TRUE;
    }
    else
    {
      theProcFlags[i] = FALSE;
    }
  }


  while (nConn>0)
  {
    for(i=0; i<nPartners; i++)
    {
      if (theProcFlags[i])
      {
        int ret = InfoAConn(theTopology[theProcArray[i]]);
        if (ret==-1)
        {
          sprintf(cBuffer,
                  "PPIF's InfoAConn() failed for connect to proc=%d"
                  " in DDD_GetChannels",
                  theProcArray[i]);
          DDD_PrintError('E', 1530, cBuffer);
          RET_ON_ERROR;
        }


        if (ret==1)
        {
          theProcFlags[i] = FALSE;
          nConn--;
        }
      }
    }
  }
  /* TODO free unused channels? */

  RET_ON_OK;
}
Exemplo n.º 25
0
Arquivo: notify.c Projeto: rolk/ug
int NotifyTwoWave (NOTIFY_INFO *allInfos, int lastInfo, int exception)
{
  NOTIFY_INFO  *newInfos;
  int l, i, j, n, unknownInfos, myInfos;
  int local_exception = exception;

#if     DebugNotify<=4
  printf("%4d:    NotifyTwoWave, lastInfo=%d\n", me, lastInfo);
  fflush(stdout);
#endif

  /* BOTTOM->TOP WAVE */
  /* get local Info lists from downtree */
  for(l=degree-1; l>=0; l--)
  {
    GetConcentrate(l, &n, sizeof(int));

    if (n<0)
    {
      /* exception from downtree, propagate */
      if (-n > local_exception)
        local_exception = -n;
    }

    if (lastInfo+n >= maxInfos) {
      DDD_PrintError('E', 6321, "msg-info array overflow in NotifyTwoWave");
      local_exception = EXCEPTION_NOTIFY;

      /* receive data, but put it onto dummy position */
      GetConcentrate(l, allInfos, n*sizeof(NOTIFY_INFO));
    }
    else
    {
      if (n>0)
        GetConcentrate(l, &(allInfos[lastInfo]), n*sizeof(NOTIFY_INFO));
    }

    /* construct routing table */
    for(i=0; i<n; i++)
      theRouting[allInfos[lastInfo+i].from] = l;

    if (n>0)
      lastInfo += n;
  }


  if (! local_exception)
  {
    /* determine target direction in tree */
    /* TODO: eventually extra solution for root node!
                     (it knows all flags are MYSELF or KNOWN!)  */
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferInfos);
    i = j = 0;
    unknownInfos = lastInfo;
    myInfos = 0;
    while (i<lastInfo && allInfos[j].to==PROC_INVALID_TEMP)
    {
      if (allInfos[j].from==allInfos[i].to)
      {
        allInfos[i].flag = (allInfos[i].to==me) ? MYSELF : KNOWN;
        unknownInfos--;
        if (allInfos[i].to==me)
          myInfos++;
        i++;
      } else {
        if (allInfos[j].from<allInfos[i].to)
          j++;
        else
          i++;
      }
    }
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferFlags);


    /* send local Info list uptree, but only unknown Infos */
    newInfos = &allInfos[lastInfo-unknownInfos];
    Concentrate(&unknownInfos, sizeof(int));
    Concentrate(newInfos, unknownInfos*sizeof(NOTIFY_INFO));
    lastInfo -= unknownInfos;

                #if     DebugNotify<=1
    for(i=0; i<unknownInfos; i++)
    {
      printf("%4d:    NotifyTwoWave, "
             "send uptree unknown %d/%d (%d|%d;%d)\n",
             me, i, unknownInfos,
             newInfos[i].to, newInfos[i].from, newInfos[i].size);
    }
                #endif

  }
  else
  {
    /* we have an exception somewhere in the processor tree */
    /* propagate it */
    int neg_exception = -local_exception;
    Concentrate(&neg_exception, sizeof(int));
    /* don't need to send data now */
  }

#if     DebugNotify<=3
  printf("%4d:    NotifyTwoWave, wave 1 ready\n", me);
  fflush(stdout);
#endif



  /* TOP->BOTTOM WAVE */

  /* get Infos local to my subtree from uptree */
  unknownInfos = 0;
  GetSpread(&unknownInfos, sizeof(int));
  if (unknownInfos<0)
  {
    /* exception from downtree, propagate */
    if (-unknownInfos > local_exception)
      local_exception = -unknownInfos;
  }

  if (unknownInfos>0)
  {
    GetSpread(newInfos, unknownInfos*sizeof(NOTIFY_INFO));
    lastInfo += unknownInfos;
  }

  if (! local_exception)
  {
    /* sort Infos according to routing */
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferRouting);

                #if     DebugNotify<=1
    for(i=0; i<lastInfo; i++)
    {
      printf("%4d:    NotifyTwoWave, "
             "sorted for routing  %d/%d (%d|%d;%d)\n",
             me, i, lastInfo,
             allInfos[i].to, allInfos[i].from, allInfos[i].size);
    }
                #endif

    /* send relevant Infos downtree */
    i = 0;
    unknownInfos = lastInfo;
    while ((i<unknownInfos)&&(allInfos[i].to==me)) i++;
    lastInfo = i;
    for(l=0; l<degree; l++)
    {
      j = i;
      while ((i<unknownInfos)&&(theRouting[allInfos[i].to]==l)) i++;
      j = i-j;

      Spread(l, &j, sizeof(int));
      if (j>0)
        Spread(l, &allInfos[i-j], j*sizeof(NOTIFY_INFO));
    }


    /* reuse theDescs-array for registering messages to be received */
    for(i=0; i<lastInfo; i++)
    {
      theDescs[i].proc = allInfos[i].from;
      theDescs[i].size = allInfos[i].size;
    }

                #if     DebugNotify<=3
    printf("%4d:    NotifyTwoWave, "
           "wave 2 ready, nRecv=%d\n", me, lastInfo);
    fflush(stdout);
                #endif
  }
  else
  {
    /* we received an exception from uptree, propagate it */
    for(l=0; l<degree; l++)
    {
      int neg_exception = -local_exception;
      Spread(l, &neg_exception, sizeof(int));
      /* dont send any data */
    }

                #if     DebugNotify<=3
    printf("%4d:    NotifyTwoWave, "
           "wave 2 ready, Exception=%d\n", me, local_exception);
    fflush(stdout);
                #endif

    return(-local_exception);
  }

  return(lastInfo);
}
Exemplo n.º 26
0
Arquivo: pack.c Projeto: rolk/ug
static int BuildSymTab (TYPE_DESC *desc,
                        DDD_OBJ obj,
                        char *copy,
                        SYMTAB_ENTRY *theSymTab)
{
  ELEM_DESC   *theElem;
  int e, actSym;

  /*STAT_RESET4;*/

  /* reset local portion of SymTab */
  actSym = 0;

  /* prepare map of structure elements */
  theElem = desc->element;

  /* loop over all pointers inside of object obj */
  for(e=0; e<desc->nElements; e++, theElem++)
  {
    if (theElem->type==EL_OBJPTR)
    {
      TYPE_DESC *refdesc;
      int l;
      int rt_on_the_fly = (EDESC_REFTYPE(theElem)==DDD_TYPE_BY_HANDLER);

      /* determine reftype of this elem */
      if (! rt_on_the_fly)
      {
        /* we know the reftype of this element in advance */
        refdesc = &theTypeDefs[EDESC_REFTYPE(theElem)];
      }
      /* else: determine reftype on the fly by calling handler */


      /* loop over single pointer array */
#if defined(C_FRONTEND) || defined(CPP_FRONTEND)
      for(l=0; l<theElem->size; l+=sizeof(void *))
      {
        /* get address of outside reference */
        DDD_OBJ *ref = (DDD_OBJ *)(copy+theElem->offset+l);
#else
      for(l=0; l<theElem->size; l+=sizeof(DDD_OBJ))
      {
        /* F77TODO: DDD_OBJ* must be replaced by local objindex */
        /* get the index of the referenced object */
        DDD_OBJ *ref = (DDD_OBJ *)(copy+theElem->msgoffset);
#endif

        /* create symbol table entry */
        if (*ref!=NULL)
        {
          DDD_HDR refhdr;

          if (rt_on_the_fly)
          {
            DDD_TYPE rt;

            /* determine reftype on the fly by calling handler */
            assert(obj!=NULL);                                       /* we need a real object here */

            rt = theElem->reftypeHandler(obj, *ref);
            if (rt>=MAX_TYPEDESC)
            {
              DDD_PrintError('E', 6520,
                             "invalid referenced DDD_TYPE "
                             "returned by handler");
              HARD_EXIT;
            }
            refdesc = &theTypeDefs[rt];
          }

          /* get header of referenced object */
          refhdr = OBJ2HDR(*ref,refdesc);

          /* remember the GID of the referenced object */
          theSymTab[actSym].gid = OBJ_GID(refhdr);

          /* remember the address of the reference (in obj-copy) */
          theSymTab[actSym].adr.ref = ref;
          actSym++;
        }
      }
    }
  }

  /*STAT_INCTIMER4(33);*/

  /* return SymTab increment */
  return(actSym);
}



/****************************************************************************/
/*                                                                          */
/* Function:  GetDepData                                                    */
/*                                                                          */
/* Purpose:   fill object-dependent data into message. an appl. routine     */
/*            will be called to fill in the data actually. pointers are     */
/*            localized and the message SymTab is actualized.               */
/*                                                                          */
/* Input:     data: portion of message buffer reserved for dependent data   */
/*            desc: descriptor of object                                    */
/*            obj:  current ddd-object                                      */
/*            theSymTab: actual portion of message SymTab                   */
/*            xi:   single xferinfo for current ddd-object                  */
/*                                                                          */
/* Output:    number of new entries into SymTab                             */
/*                                                                          */
/****************************************************************************/

static int GetDepData (char *data,
                       TYPE_DESC *desc,
                       DDD_OBJ obj,
                       SYMTAB_ENTRY *theSymTab,
                       XICopyObj *xi)
{
  XFERADDDATA  *xa;
  TYPE_DESC    *descDep;
  char         *chunk, *adr, **table1, *next_chunk;
  int chunks, i, actSym, *table2;


  if (xi->addLen==0) return(0);

  chunks = 0;
  actSym = 0;


  /* first entry will be number of dependency chunks */
  chunk = data + CEIL(sizeof(int));


  /* loop through whole dependency data descriptor */
  for(xa=xi->add; xa!=NULL; xa=xa->next)
  {
    /* first entries of chunk are addCnt and addTyp */
    ((int *)chunk)[0]      = xa->addCnt;
    ((DDD_TYPE *)chunk)[1] = xa->addTyp;

    if (xa->sizes==NULL)
    {
      chunk += CEIL(sizeof(int)+sizeof(DDD_TYPE));

      /* then all records should be gathered via handler */
      if (desc->handlerXFERGATHER)
      {
                                #if defined(C_FRONTEND) || defined(F_FRONTEND)
        desc->handlerXFERGATHER(_FADR obj,
                                _FADR xa->addCnt, _FADR xa->addTyp, (void *)chunk);
                                #endif
                                #ifdef CPP_FRONTEND
        CallHandler(desc,XFERGATHER) (HParam(obj)
                                      xa->addCnt, xa->addTyp, (void *)chunk);
                                #endif
      }

      if (xa->addTyp<DDD_USER_DATA || xa->addTyp>DDD_USER_DATA_MAX)
      {
        /* insert pointers into symtab */
        descDep = &theTypeDefs[xa->addTyp];
        for(i=0; i<xa->addCnt; i++)
        {
          actSym += BuildSymTab(descDep, NULL,
                                chunk, &(theSymTab[actSym]));
          chunk += CEIL(descDep->size);
        }
      }
      else
      {
        /* no regular type -> send byte stream with length addCnt */
        chunk += CEIL(xa->addCnt);
      }
    }
    else
    {
      /* var-sized AddData items */
      ((int *)chunk)[0] *= -1;
      chunk += CEIL(sizeof(int)+sizeof(DDD_TYPE));

      /* create pointer array inside message */
      table1 = (char **)chunk;
      chunk += CEIL(sizeof(int)*xa->addCnt);
      for(i=0, adr=chunk; i<xa->addCnt; i++)
      {
        table1[i] = adr;
        adr += CEIL(xa->sizes[i]);
      }
      next_chunk = adr;

      /* then all records should be gathered via handler */
      if (desc->handlerXFERGATHERX)
      {
                                #if defined(C_FRONTEND) || defined(F_FRONTEND)
        desc->handlerXFERGATHERX(_FADR obj,
                                 _FADR xa->addCnt, _FADR xa->addTyp, table1);
                                #endif
                                #ifdef CPP_FRONTEND
        CallHandler(desc,XFERGATHERX) (HParam(obj)
                                       xa->addCnt, xa->addTyp, table1);
                                #endif
      }

      /* convert pointer table into offset table */
      table2 = (int *)table1;
      descDep = &theTypeDefs[xa->addTyp];
      adr = chunk;
      for(i=0; i<xa->addCnt; i++)
      {
        /* insert pointers into symtab */
        if (xa->addTyp<DDD_USER_DATA || xa->addTyp>DDD_USER_DATA_MAX)
        {
          actSym += BuildSymTab(descDep, NULL,
                                table1[i], &(theSymTab[actSym]));
        }

        table2[i] = (int)(table1[i]-adr);
      }

      chunk = next_chunk;
    }

    /* count chunks */
    chunks++;
  }


  /* remember number of chunks at the beginning of the deplist */
  ((int *)data)[0] = chunks;


  return(actSym);
}
Exemplo n.º 27
0
Arquivo: pack.c Projeto: rolk/ug
RETCODE XferPackMsgs (XFERMSG *theMsgs)
{
  XFERMSG      *xm;

#if     DebugPack<=3
  sprintf(cBuffer, "%d: XferPackMsgs\n", me);
  DDD_PrintDebug(cBuffer);
  fflush(stdout);
#endif

  /* sort messages according to decreasing size. i.e., send
     biggest message first. LowComm will use this to handle
     situations with little memory ressources. */
  {
    int i, n;
    XFERMSG **xm_array;

    /* count number of messages */
    for(n=0, xm=theMsgs; xm!=NULL; xm=xm->next) n++;

    if (n>0)
    {
      /* alloc array of pointers to messages */
      xm_array = (XFERMSG **) OO_Allocate (sizeof(XFERMSG *) * n);
      if (xm_array!=NULL)
      {
        for(i=0, xm=theMsgs; i<n; xm=xm->next, i++) xm_array[i] = xm;

        /* sort array and relink list */
        qsort(xm_array, n, sizeof(XFERMSG *), sort_MsgSize);
        theMsgs = xm_array[0];
        for(i=0; i<n-1; i++) xm_array[i]->next = xm_array[i+1];
        if (n>1) xm_array[n-1]->next = NULL;

        /* free array */
        OO_Free (xm_array /*,0*/);
      }
      /* else
         {
              resorting msg-list is not possible due to memory shortage.
              simply don't do it.
         }
       */
    }
  }



  /* allocate buffer, pack messages and send away */
  for(xm=theMsgs; xm!=NULL; xm=xm->next)
  {
    if (! LC_MsgAlloc(xm->msg_h))
    {
      sprintf(cBuffer, STR_NOMEM " in XferPackMsgs (size=%ld)",
              (unsigned long) LC_GetBufferSize(xm->msg_h));
      DDD_PrintError('E', 6522, cBuffer);
      RET_ON_ERROR;
    }
    XferPackSingleMsg(xm);
    LC_MsgSend(xm->msg_h);
  }

  RET_ON_OK;
}
Exemplo n.º 28
0
Arquivo: notify.c Projeto: rolk/ug
int DDD_Notify (void)
{
  NOTIFY_INFO  *allInfos;
  int i, nRecvMsgs;

  /* get storage for local info list */
  allInfos = NotifyPrepare();
  if (allInfos==NULL) return(ERROR);

  if (nSendDescs<0)
  {
    /* this processor is trying to send a global notification
       message. this is necessary for communicating fatal error
       conditions to all other processors. */

    sprintf(cBuffer, "proc %d is sending global exception #%d"
            " in DDD_Notify()", me, -nSendDescs);
    DDD_PrintError('W', 6312, cBuffer);

    /* notify partners */
    nRecvMsgs = NotifyTwoWave(allInfos, lastInfo, -nSendDescs);
  }
  else
  {
    /* convert message list to local Info list */
    for(i=0; i<nSendDescs; i++)
    {
                        #if     DebugNotify<=4
      printf("%4d:    Notify send msg #%02d to %3d size=%d\n", me,
             lastInfo, theDescs[i].proc, theDescs[i].size);
                        #endif

      if (theDescs[i].proc==me) {
        sprintf(cBuffer, "proc %d is trying to send message to itself"
                " in DDD_Notify()", me);
        DDD_PrintError('E', 6310, cBuffer);
        return(ERROR);
      }
      if (theDescs[i].proc>=procs) {
        sprintf(cBuffer, "proc %d is trying to send message to proc %d"
                " in DDD_Notify()", me, theDescs[i].proc);
        DDD_PrintError('E', 6311, cBuffer);
        return(ERROR);
      }

      allInfos[lastInfo].from = me;
      allInfos[lastInfo].to   = theDescs[i].proc;
      allInfos[lastInfo].size = theDescs[i].size;
      allInfos[lastInfo].flag = UNKNOWN;
      lastInfo++;
    }

    /* notify partners */
    nRecvMsgs = NotifyTwoWave(allInfos, lastInfo, 0);
  }


#       if      DebugNotify<=4
  for(i=0; i<nRecvMsgs; i++)
  {
    printf("%4d:    Notify recv msg #%02d from %3d size=%d\n", me,
           lastInfo, theDescs[i].proc, theDescs[i].size);
  }
#       endif


  return(nRecvMsgs);
}