Actual source code: matstashspace.c

  2: #define PETSCMAT_DLL

 4:  #include src/mat/matimpl.h
 5:  #include src/mat/utils/matstashspace.h

  7: /* Get new PetscMatStashSpace into the existing space */
 10: PetscErrorCode PetscMatStashSpaceGet(PetscInt bs2,PetscInt n,PetscMatStashSpace *space)
 11: {
 12:   PetscMatStashSpace a;
 13:   PetscErrorCode     ierr;
 14: 
 16:   if (!n) return(0);

 18:   PetscMalloc(sizeof(struct _MatStashSpace),&a);
 19:   PetscMalloc(n*(bs2*sizeof(MatScalar)+2*sizeof(PetscInt)),&(a->space_head));
 20:   a->val              = a->space_head;
 21:   a->idx              = (PetscInt*)(a->val + bs2*n);
 22:   a->idy              = (PetscInt*)(a->idx + n);
 23:   a->local_remaining  = n;
 24:   a->local_used       = 0;
 25:   a->total_space_size = 0;
 26:   a->next             = PETSC_NULL;

 28:   if (*space){
 29:     (*space)->next      = a;
 30:     a->total_space_size = (*space)->total_space_size;
 31:   }
 32:   a->total_space_size += n;
 33:   *space               = a;
 34:   return(0);
 35: }

 37: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
 40: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2,PetscMatStashSpace *space,PetscScalar *val,PetscInt *idx,PetscInt *idy)
 41: {
 42:   PetscMatStashSpace a;
 43:   PetscErrorCode     ierr;

 46:   while ((*space) != PETSC_NULL){
 47:     a    = (*space)->next;
 48:     PetscMemcpy(val,(*space)->val,((*space)->local_used*bs2)*sizeof(MatScalar));
 49:     val += bs2*(*space)->local_used;
 50:     PetscMemcpy(idx,(*space)->idx,((*space)->local_used)*sizeof(PetscInt));
 51:     idx += (*space)->local_used;
 52:     PetscMemcpy(idy,(*space)->idy,((*space)->local_used)*sizeof(PetscInt));
 53:     idy += (*space)->local_used;
 54: 
 55:      PetscFree((*space)->space_head);
 56:      PetscFree(*space);
 57:     *space = a;
 58:   }
 59:   return(0);
 60: }

 64: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace space)
 65: {
 66:   PetscMatStashSpace a;
 67:   PetscErrorCode     ierr;

 70:   while (space != PETSC_NULL){
 71:     a     = space->next;
 72:     PetscFree(space->space_head);
 73:     PetscFree(space);
 74:     space = a;
 75:   }
 76:   return(0);
 77: }