Actual source code: matstashspace.c

petsc-3.11.4 2019-09-28
Report Typos and Errors

  2:  #include <petsc/private/matimpl.h>

  4: /* Get new PetscMatStashSpace into the existing space */
  5: PetscErrorCode PetscMatStashSpaceGet(PetscInt bs2,PetscInt n,PetscMatStashSpace *space)
  6: {
  7:   PetscMatStashSpace a;
  8:   PetscErrorCode     ierr;

 11:   if (!n) return(0);

 13:   PetscMalloc(sizeof(struct _MatStashSpace),&a);
 14:   PetscMalloc3(n*bs2,&(a->space_head),n,&a->idx,n,&a->idy);

 16:   a->val              = a->space_head;
 17:   a->local_remaining  = n;
 18:   a->local_used       = 0;
 19:   a->total_space_size = 0;
 20:   a->next             = NULL;

 22:   if (*space) {
 23:     (*space)->next      = a;
 24:     a->total_space_size = (*space)->total_space_size;
 25:   }
 26:   a->total_space_size += n;
 27:   *space               = a;
 28:   return(0);
 29: }

 31: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
 32: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2,PetscMatStashSpace *space,PetscScalar *val,PetscInt *idx,PetscInt *idy)
 33: {
 34:   PetscMatStashSpace a;
 35:   PetscErrorCode     ierr;

 38:   while ((*space)) {
 39:     a    = (*space)->next;
 40:     PetscMemcpy(val,(*space)->val,((*space)->local_used*bs2)*sizeof(PetscScalar));
 41:     val += bs2*(*space)->local_used;
 42:     PetscMemcpy(idx,(*space)->idx,((*space)->local_used)*sizeof(PetscInt));
 43:     idx += (*space)->local_used;
 44:     PetscMemcpy(idy,(*space)->idy,((*space)->local_used)*sizeof(PetscInt));
 45:     idy += (*space)->local_used;

 47:      PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
 48:      PetscFree(*space);
 49:     *space = a;
 50:   }
 51:   return(0);
 52: }

 54: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace *space)
 55: {
 56:   PetscMatStashSpace a;
 57:   PetscErrorCode     ierr;

 60:   while (*space) {
 61:     a      = (*space)->next;
 62:     PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
 63:     PetscFree((*space));
 64:     *space = a;
 65:   }
 66:   *space = NULL;
 67:   return(0);
 68: }