1 2 #define PETSCMAT_DLL 3 4 #include "private/matimpl.h" 5 6 /* Get new PetscMatStashSpace into the existing space */ 7 #undef __FUNCT__ 8 #define __FUNCT__ "PetscMatStashSpaceGet" 9 PetscErrorCode PetscMatStashSpaceGet(PetscInt bs2,PetscInt n,PetscMatStashSpace *space) 10 { 11 PetscMatStashSpace a; 12 PetscErrorCode ierr; 13 14 PetscFunctionBegin; 15 if (!n) PetscFunctionReturn(0); 16 17 ierr = PetscMalloc(sizeof(struct _MatStashSpace),&a);CHKERRQ(ierr); 18 ierr = PetscMalloc3(n*bs2,PetscScalar,&(a->space_head),n,PetscInt,&a->idx,n,PetscInt,&a->idy);CHKERRQ(ierr); 19 a->val = a->space_head; 20 a->local_remaining = n; 21 a->local_used = 0; 22 a->total_space_size = 0; 23 a->next = PETSC_NULL; 24 25 if (*space){ 26 (*space)->next = a; 27 a->total_space_size = (*space)->total_space_size; 28 } 29 a->total_space_size += n; 30 *space = a; 31 PetscFunctionReturn(0); 32 } 33 34 /* Copy the values in space into arrays val, idx and idy. Then destroy space */ 35 #undef __FUNCT__ 36 #define __FUNCT__ "PetscMatStashSpaceContiguous" 37 PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2,PetscMatStashSpace *space,PetscScalar *val,PetscInt *idx,PetscInt *idy) 38 { 39 PetscMatStashSpace a; 40 PetscErrorCode ierr; 41 42 PetscFunctionBegin; 43 while ((*space) != PETSC_NULL){ 44 a = (*space)->next; 45 ierr = PetscMemcpy(val,(*space)->val,((*space)->local_used*bs2)*sizeof(PetscScalar));CHKERRQ(ierr); 46 val += bs2*(*space)->local_used; 47 ierr = PetscMemcpy(idx,(*space)->idx,((*space)->local_used)*sizeof(PetscInt));CHKERRQ(ierr); 48 idx += (*space)->local_used; 49 ierr = PetscMemcpy(idy,(*space)->idy,((*space)->local_used)*sizeof(PetscInt));CHKERRQ(ierr); 50 idy += (*space)->local_used; 51 52 ierr = PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);CHKERRQ(ierr); 53 ierr = PetscFree(*space);CHKERRQ(ierr); 54 *space = a; 55 } 56 PetscFunctionReturn(0); 57 } 58 59 #undef __FUNCT__ 60 #define __FUNCT__ "PetscMatStashSpaceDestroy" 61 PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace space) 62 { 63 PetscMatStashSpace a; 64 PetscErrorCode ierr; 65 66 PetscFunctionBegin; 67 while (space != PETSC_NULL){ 68 a = space->next; 69 ierr = PetscFree3(space->space_head,space->idx,space->idy);CHKERRQ(ierr); 70 ierr = PetscFree(space);CHKERRQ(ierr); 71 space = a; 72 } 73 PetscFunctionReturn(0); 74 } 75