Actual source code: matstashspace.c
petsc-3.7.7 2017-09-25
2: #include <petsc/private/matimpl.h>
4: /* Get new PetscMatStashSpace into the existing space */
7: PetscErrorCode PetscMatStashSpaceGet(PetscInt bs2,PetscInt n,PetscMatStashSpace *space)
8: {
9: PetscMatStashSpace a;
10: PetscErrorCode ierr;
13: if (!n) return(0);
15: PetscMalloc(sizeof(struct _MatStashSpace),&a);
16: PetscMalloc3(n*bs2,&(a->space_head),n,&a->idx,n,&a->idy);
18: a->val = a->space_head;
19: a->local_remaining = n;
20: a->local_used = 0;
21: a->total_space_size = 0;
22: a->next = NULL;
24: if (*space) {
25: (*space)->next = a;
26: a->total_space_size = (*space)->total_space_size;
27: }
28: a->total_space_size += n;
29: *space = a;
30: return(0);
31: }
33: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
36: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2,PetscMatStashSpace *space,PetscScalar *val,PetscInt *idx,PetscInt *idy)
37: {
38: PetscMatStashSpace a;
39: PetscErrorCode ierr;
42: while ((*space)) {
43: a = (*space)->next;
44: PetscMemcpy(val,(*space)->val,((*space)->local_used*bs2)*sizeof(PetscScalar));
45: val += bs2*(*space)->local_used;
46: PetscMemcpy(idx,(*space)->idx,((*space)->local_used)*sizeof(PetscInt));
47: idx += (*space)->local_used;
48: PetscMemcpy(idy,(*space)->idy,((*space)->local_used)*sizeof(PetscInt));
49: idy += (*space)->local_used;
51: PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
52: PetscFree(*space);
53: *space = a;
54: }
55: return(0);
56: }
60: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace *space)
61: {
62: PetscMatStashSpace a;
63: PetscErrorCode ierr;
66: while (*space) {
67: a = (*space)->next;
68: PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
69: PetscFree((*space));
70: *space = a;
71: }
72: *space = NULL;
73: return(0);
74: }