コード例 #1
0
ファイル: DD_Find.c プロジェクト: 00liujj/trilinos
static int DD_Find_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid,         /* incoming GID to locate (in)            */
 ZOLTAN_ID_PTR lid,         /* gid's LID (out)                        */
 char *user,                /* gid's user data (out)                  */
 int *partition,            /* gid's partition number (out)           */
 int *owner)                /* gid's owner (processor number) (out)   */
{
   DD_Node *ptr;
   DD_NodeIdx nodeidx;
   int      index;
   char    *yo = "DD_Find_Local";

   /* input sanity check */
   if (dd == NULL || owner == NULL || gid == NULL)  {
      ZOLTAN_PRINT_ERROR ((dd == NULL) ? 0 : dd->my_proc, yo, "Invalid input");
      return ZOLTAN_FATAL;
   }
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL);

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length,
                            dd->hashdata, NULL);
   /* walk link list until end looking for matching global ID */
   for (nodeidx = dd->table[index]; nodeidx != -1;
        nodeidx = dd->nodelist[nodeidx].next) {
      ptr = dd->nodelist + nodeidx;
      if (ZOLTAN_EQ_ID (dd->gid_length, gid, ptr->gid) == TRUE)  {
         /* matching global ID found! Return gid's information */
         if (lid) ZOLTAN_SET_ID(dd->lid_length, lid, ptr->gid + dd->gid_length);
         if (user) memcpy(user, ptr->gid + (dd->gid_length + dd->lid_length),
                          dd->user_data_length);

         if (owner)     *owner     = ptr->owner;
         if (partition) *partition = ptr->partition;

         if (dd->debug_level > 5)
            ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
         return ZOLTAN_OK;
      }
   }


   if (owner != NULL)
      *owner = -1;    /* JDT Added -1 owner not found */
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);

   if (dd->debug_level > 0)  {
      ZOLTAN_PRINT_INFO(dd->my_proc, yo, "GID not found");
      return ZOLTAN_WARN;
   }
   return ZOLTAN_WARN;
}
コード例 #2
0
ファイル: DD_Find.c プロジェクト: xunzhang/ESMF_Regridding
static int DD_Find_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid,         /* incoming GID to locate (in)            */
 ZOLTAN_ID_PTR lid,         /* gid's LID (out)                        */
 ZOLTAN_ID_PTR user,        /* gid's user data (out)                  */
 int *partition,        /* gid's partition number (out)           */
 int *owner)            /* gid's owner (processor number) (out)   */
   {
   DD_Node *ptr ;
   int      index ;
   char    *yo = "DD_Find_Local" ;

   /* input sanity check */
   if (dd == NULL || owner == NULL || gid == NULL)
      {
      ZOLTAN_PRINT_ERROR ((dd == NULL) ? 0 : dd->my_proc, yo,
       "Invalid input argument.") ;
      return ZOLTAN_DD_INPUT_ERROR ;
      }
   if (dd->debug_level > 2)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL) ;

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length) ;

   /* walk link list until end looking for matching global ID */
   for (ptr = dd->table[index] ; ptr != NULL ; ptr = ptr->next)
      if (ZOLTAN_EQ_ID (dd->gid_length, gid, ptr->gid) == TRUE)
         { 
         /* matching global ID found! Return gid's information */
         if (lid) ZOLTAN_SET_ID(dd->lid_length, lid, 
                                ptr->gid + dd->gid_length);
         if (user) ZOLTAN_SET_ID(dd->user_data_length, user,
                                 ptr->gid + (dd->gid_length + dd->lid_length));

         if (owner     != NULL)   *owner     = ptr->owner ;
         if (partition != NULL)   *partition = ptr->partition ;

         if (dd->debug_level > 2)
            ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL) ;

         return ZOLTAN_DD_NORMAL_RETURN ;
         }

   if (dd->debug_level > 0) 
      ZOLTAN_PRINT_INFO(dd->my_proc, yo, "GID not found.");
   if (dd->debug_level > 2) 
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL) ;

   return ZOLTAN_DD_GID_NOT_FOUND_ERROR ;
   }
コード例 #3
0
ファイル: DD_Remove.c プロジェクト: agrippa/Trilinos
static int DD_Remove_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid)                /* GID to be removed (in)  */
{
   DD_Node *ptr;
   DD_NodeIdx nodeidx, prevnodeidx;
   int index;
   char *yo = "DD_Remove_Local";

   /* input sanity checking */
   if (dd == NULL || gid == NULL)  {
      ZOLTAN_PRINT_ERROR ((dd == NULL) ? ZOLTAN_DD_NO_PROC : dd->my_proc,
       yo, "Invalid input argument");
      return ZOLTAN_FATAL;
   }
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL);

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length,
                            dd->hashdata, NULL);

   /* walk linked list until end looking for matching gid (key) */
   prevnodeidx = -1;
   for (nodeidx = dd->table[index]; nodeidx != -1;
      nodeidx = dd->nodelist[nodeidx].next) {
      ptr = dd->nodelist + nodeidx;
      if (ZOLTAN_EQ_ID(dd->gid_length, gid, ptr->gid) == TRUE)  {
         /* found node to remove, need to preserve its next ptr */
         if (prevnodeidx != -1)
            dd->nodelist[prevnodeidx].next = ptr->next;
         else
            dd->table[index] = ptr->next;
         DD_Memory_Free_Node(dd, nodeidx);       /* now OK to delete node */

         if (dd->debug_level > 5)
            ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
         return ZOLTAN_OK;
      }
      prevnodeidx = nodeidx;
   }

   /* We get here only if the global ID has not been found */
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
   return ZOLTAN_WARN;
}
コード例 #4
0
ファイル: DD_Remove.c プロジェクト: abhishek4747/pv-zoltan
static int DD_Remove_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid)                /* GID to be removed (in)  */
{
   DD_Node **ptr;
   DD_Node  *old;
   int index;
   char *yo = "DD_Remove_Local";

   /* input sanity checking */
   if (dd == NULL || gid == NULL)  {
      ZOLTAN_PRINT_ERROR ((dd == NULL) ? ZOLTAN_DD_NO_PROC : dd->my_proc,
       yo, "Invalid input argument");
      return ZOLTAN_FATAL;
   }
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL);

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length,
                            dd->hashdata, NULL);

   /* walk linked list until end looking for matching gid (key) */
   for (ptr = dd->table + index; *ptr != NULL; ptr = &((*ptr)->next))
      if (ZOLTAN_EQ_ID(dd->gid_length, gid, (*ptr)->gid) == TRUE)  {
         /* found node to remove, need to preserve its next ptr */
          old =  *ptr;
         *ptr = (*ptr)->next;
         ZOLTAN_FREE (&old);       /* now OK to delete node */

         if (dd->debug_level > 5)
            ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
         return ZOLTAN_OK;
      }

   /* We get here only if the global ID has not been found */
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
   return ZOLTAN_WARN;
}
コード例 #5
0
ファイル: DD_Update.c プロジェクト: agrippa/Trilinos
static int DD_Update_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid,         /* GID to update (in)                        */
 ZOLTAN_ID_PTR lid,         /* gid's LID (in), NULL if not needed        */
 char *user,                /* gid's user data (in), NULL if not needed  */
 int partition,             /* gid's partition (in), -1 if not used      */
 int owner)                 /* gid's current owner (proc number) (in)    */
{
   int index;
   char *yo = "DD_Update_Local";
   DD_NodeIdx nodeidx;
   DD_Node *ptr;

   /* input sanity checking */
   if (dd == NULL || owner  < 0 || owner >= dd->nproc || gid == NULL)  {
      ZOLTAN_PRINT_ERROR (dd ? dd->my_proc : ZOLTAN_DD_NO_PROC, yo,
       "Invalid input parameter");
      return ZOLTAN_FATAL;
   }
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL);

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length,
                            dd->hashdata, NULL);

   /* walk linked list until end looking for matching gid */
   for (nodeidx = dd->table[index]; nodeidx != -1;
        nodeidx = dd->nodelist[nodeidx].next) {
       ptr = dd->nodelist + nodeidx;
       if (ZOLTAN_EQ_ID (dd->gid_length, gid, ptr->gid) == TRUE)  {
          /* found match, update directory information */
          if (lid)
             ZOLTAN_SET_ID (dd->lid_length,ptr->gid + dd->gid_length, lid);
          if (user)
             memcpy(ptr->gid + (dd->gid_length + dd->lid_length), user,
                    dd->user_data_length);

          ptr->owner = owner;
          if (partition != -1)
             ptr->partition = partition;

          /* Response to multiple updates to a gid in 1 update cycle */
          if (dd->debug_level > 0 && ptr->errcheck != owner)  {
             ZOLTAN_PRINT_INFO (dd->my_proc, yo, "Multiply defined GID");
             if (dd->debug_level > 4)
                ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
             return ZOLTAN_WARN;
          }

          ptr->errcheck = owner;
          if (dd->debug_level > 5)
             ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
          return ZOLTAN_OK;          /* ignore all errors */
       }
   }

   /* gid not found. Create new DD_Node and fill it in */
   nodeidx = DD_Memory_Alloc_Node(dd);
   ptr = dd->nodelist + nodeidx;

   ZOLTAN_SET_ID (dd->gid_length, ptr->gid, gid);

   if (lid) {
      ZOLTAN_SET_ID(dd->lid_length,ptr->gid + dd->gid_length, lid);
   }
   else  {
      memset(ptr->gid + dd->gid_length, 0,
             dd->lid_length*sizeof(ZOLTAN_ID_TYPE));
   }
   if (user) {
      memcpy(ptr->gid + (dd->gid_length + dd->lid_length), user,
             dd->user_data_length);
   }
   else {
      memset(ptr->gid + (dd->gid_length+dd->lid_length), 0,
             dd->user_data_length);
   }
   ptr->partition = partition;
   ptr->owner = owner;
   ptr->errcheck = owner;

   /* Add node to the linked list */
   ptr->next = dd->table[index];
   dd->table[index] = nodeidx;

   if (dd->debug_level > 6)
      ZOLTAN_PRINT_INFO (dd->my_proc, yo, "Created new directory item");
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);

   return ZOLTAN_OK;
}
コード例 #6
0
static int DD_Update_Local (Zoltan_DD_Directory *dd,
 ZOLTAN_ID_PTR gid,         /* GID to update (in)                        */
 ZOLTAN_ID_PTR lid,         /* gid's LID (in), NULL if not needed        */
 ZOLTAN_ID_PTR user,        /* gid's user data (in), NULL if not needed  */
 int partition,             /* gid's partition (in), -1 if not used      */
 int owner)                 /* gid's current owner (proc number) (in)    */
   {
   DD_Node **ptr;
   int index;
   char *yo = "DD_Update_Local";


   /* input sanity checking */
   if (dd == NULL || owner  < 0 || owner >= dd->nproc || gid == NULL)  {
      ZOLTAN_PRINT_ERROR (dd ? dd->my_proc : ZOLTAN_DD_NO_PROC, yo,
       "Invalid input parameter");
      return ZOLTAN_FATAL;
   }
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_IN (dd->my_proc, yo, NULL);

   /* compute offset into hash table to find head of linked list */
   index = Zoltan_DD_Hash2 (gid, dd->gid_length, dd->table_length, dd->hashdata);

   /* walk linked list until end looking for matching gid */
   for (ptr = dd->table+index; *ptr != NULL; ptr = &((*ptr)->next))
       if (ZOLTAN_EQ_ID (dd->gid_length, gid, (*ptr)->gid) == TRUE)  {
          /* found match, update directory information */
          if (lid)
             ZOLTAN_SET_ID (dd->lid_length,(*ptr)->gid + dd->gid_length, lid);
          if (user)
             ZOLTAN_SET_ID (dd->user_data_length, (*ptr)->gid + (dd->gid_length
              + dd->lid_length), user);

          (*ptr)->owner = owner;
          if (partition != -1)
             (*ptr)->partition = partition;

          /* Response to multiple updates to a gid in 1 update cycle */
          if (dd->debug_level > 0 && (*ptr)->errcheck != owner)  {
             ZOLTAN_PRINT_INFO (dd->my_proc, yo, "Multiply defined GID");
             if (dd->debug_level > 4)
                ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
             return ZOLTAN_WARN;
          }

          (*ptr)->errcheck = owner;
          if (dd->debug_level > 5)
             ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
          return ZOLTAN_OK;          /* ignore all errors */
       }

   /* gid not found. Create new DD_Node and fill it in */
   *ptr = (DD_Node*) ZOLTAN_MALLOC (dd->node_size);
   if (*ptr == NULL)  {
      ZOLTAN_PRINT_ERROR (dd->my_proc, yo, "Unable to malloc new Node");
      if (dd->debug_level > 5)
         ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);
      return ZOLTAN_MEMERR;
   }
   ZOLTAN_SET_ID (dd->gid_length, (*ptr)->gid, gid);

   if (lid) {
      ZOLTAN_SET_ID(dd->lid_length,(*ptr)->gid + dd->gid_length, lid);
   }
   else  {
      memset((*ptr)->gid + dd->gid_length, 0,
             dd->lid_length*sizeof(ZOLTAN_ID_TYPE));
   }
   if (user) {
      ZOLTAN_SET_ID(dd->user_data_length,
                    (*ptr)->gid + (dd->gid_length + dd->lid_length), user);
   }
   else {
      memset((*ptr)->gid + (dd->gid_length+dd->lid_length), 0,
             dd->user_data_length*sizeof(ZOLTAN_ID_TYPE));
   }
   (*ptr)->partition = partition ;

   (*ptr)->next     = NULL;
   (*ptr)->owner    = owner;
   (*ptr)->errcheck = owner;

   if (dd->debug_level > 6)
      ZOLTAN_PRINT_INFO (dd->my_proc, yo, "Created new directory item");
   if (dd->debug_level > 5)
      ZOLTAN_TRACE_OUT (dd->my_proc, yo, NULL);

   return ZOLTAN_OK;
   }