Actual source code: freespace.c

  1: #define PETSCMAT_DLL

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

  7: PetscErrorCode PetscFreeSpaceGet(PetscInt n,PetscFreeSpaceList *list)
  8: {
  9:   PetscFreeSpaceList a;
 10:   PetscErrorCode     ierr;

 13:   PetscMalloc(sizeof(struct _Space),&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 PetscFreeSpaceContiguous(PetscFreeSpaceList *head,PetscInt *space)
 34: {
 35:   PetscFreeSpaceList a;
 36:   PetscErrorCode     ierr;

 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 PetscFreeSpaceDestroy(PetscFreeSpaceList head)
 53: {
 54:   PetscFreeSpaceList a;
 55:   PetscErrorCode     ierr;

 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: }