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: PetscFunctionBegin;
10: if (!n) PetscFunctionReturn(PETSC_SUCCESS);
12: PetscCall(PetscMalloc(sizeof(struct _MatStashSpace), &a));
13: PetscCall(PetscMalloc3(n * bs2, &(a->space_head), n, &a->idx, n, &a->idy));
15: a->val = a->space_head;
16: a->local_remaining = n;
17: a->local_used = 0;
18: a->total_space_size = 0;
19: a->next = NULL;
21: if (*space) {
22: (*space)->next = a;
23: a->total_space_size = (*space)->total_space_size;
24: }
25: a->total_space_size += n;
26: *space = a;
27: PetscFunctionReturn(PETSC_SUCCESS);
28: }
30: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
31: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2, PetscMatStashSpace *space, PetscScalar *val, PetscInt *idx, PetscInt *idy)
32: {
33: PetscMatStashSpace a;
35: PetscFunctionBegin;
36: while ((*space)) {
37: a = (*space)->next;
38: PetscCall(PetscArraycpy(val, (*space)->val, (*space)->local_used * bs2));
39: val += bs2 * (*space)->local_used;
40: PetscCall(PetscArraycpy(idx, (*space)->idx, (*space)->local_used));
41: idx += (*space)->local_used;
42: PetscCall(PetscArraycpy(idy, (*space)->idy, (*space)->local_used));
43: idy += (*space)->local_used;
45: PetscCall(PetscFree3((*space)->space_head, (*space)->idx, (*space)->idy));
46: PetscCall(PetscFree(*space));
47: *space = a;
48: }
49: PetscFunctionReturn(PETSC_SUCCESS);
50: }
52: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace *space)
53: {
54: PetscMatStashSpace a;
56: PetscFunctionBegin;
57: while (*space) {
58: a = (*space)->next;
59: PetscCall(PetscFree3((*space)->space_head, (*space)->idx, (*space)->idy));
60: PetscCall(PetscFree((*space)));
61: *space = a;
62: }
63: *space = NULL;
64: PetscFunctionReturn(PETSC_SUCCESS);
65: }