Actual source code: freespace.c

      1: #define PETSCMAT_DLL

     3:  #include src/mat/utils/freespace.h

      7: PetscErrorCode GetMoreSpace(PetscInt n,FreeSpaceList *list)
      8: {
      9:   FreeSpaceList  a;

     13:   PetscMalloc(sizeof(FreeSpace),&a);
     14:   PetscMalloc(n*sizeof(PetscInt),&(a->array_head));
     15:   a->array            = a->array_head;
     16:   a->local_remaining  = n;
     17:   a->local_used       = 0;
     18:   a->total_array_size = 0;
     19:   a->more_space       = NULL;

     21:   if (*list) {
     22:     (*list)->more_space = a;
     23:     a->total_array_size = (*list)->total_array_size;
     24:   }

     26:   a->total_array_size += n;
     27:   *list               =  a;
     28:   return(0);
     29: }

     33: PetscErrorCode MakeSpaceContiguous(FreeSpaceList *head,PetscInt *space)
     34: {
     35:   FreeSpaceList  a;

     39:   while ((*head)!=NULL) {
     40:     a     =  (*head)->more_space;
     41:      PetscMemcpy(space,(*head)->array_head,((*head)->local_used)*sizeof(PetscInt));
     42:     space += (*head)->local_used;
     43:      PetscFree((*head)->array_head);
     44:      PetscFree(*head);
     45:     *head =  a;
     46:   }
     47:   return(0);
     48: }

     52: PetscErrorCode DestroySpace(FreeSpaceList head)
     53: {
     54:   FreeSpaceList  a;

     58:   while ((head)!=NULL) {
     59:     a    = (head)->more_space;
     60:     PetscFree((head)->array_head);
     61:     PetscFree(head);
     62:     head = a;
     63:   }
     64:   return(0);
     65: }