Actual source code: matstashspace.c
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;
9: if (!n) return 0;
11: PetscMalloc(sizeof(struct _MatStashSpace), &a);
12: PetscMalloc3(n * bs2, &(a->space_head), n, &a->idx, n, &a->idy);
14: a->val = a->space_head;
15: a->local_remaining = n;
16: a->local_used = 0;
17: a->total_space_size = 0;
18: a->next = NULL;
20: if (*space) {
21: (*space)->next = a;
22: a->total_space_size = (*space)->total_space_size;
23: }
24: a->total_space_size += n;
25: *space = a;
26: return 0;
27: }
29: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
30: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2, PetscMatStashSpace *space, PetscScalar *val, PetscInt *idx, PetscInt *idy)
31: {
32: PetscMatStashSpace a;
34: while ((*space)) {
35: a = (*space)->next;
36: PetscArraycpy(val, (*space)->val, (*space)->local_used * bs2);
37: val += bs2 * (*space)->local_used;
38: PetscArraycpy(idx, (*space)->idx, (*space)->local_used);
39: idx += (*space)->local_used;
40: PetscArraycpy(idy, (*space)->idy, (*space)->local_used);
41: idy += (*space)->local_used;
43: PetscFree3((*space)->space_head, (*space)->idx, (*space)->idy);
44: PetscFree(*space);
45: *space = a;
46: }
47: return 0;
48: }
50: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace *space)
51: {
52: PetscMatStashSpace a;
54: while (*space) {
55: a = (*space)->next;
56: PetscFree3((*space)->space_head, (*space)->idx, (*space)->idy);
57: PetscFree((*space));
58: *space = a;
59: }
60: *space = NULL;
61: return 0;
62: }