Actual source code: matstashspace.c
petsc-3.3-p7 2013-05-11
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;
11:
13: if (!n) return(0);
15: PetscMalloc(sizeof(struct _MatStashSpace),&a);
16: PetscMalloc3(n*bs2,PetscScalar,&(a->space_head),n,PetscInt,&a->idx,n,PetscInt,&a->idy);
17: a->val = a->space_head;
18: a->local_remaining = n;
19: a->local_used = 0;
20: a->total_space_size = 0;
21: a->next = PETSC_NULL;
23: if (*space){
24: (*space)->next = a;
25: a->total_space_size = (*space)->total_space_size;
26: }
27: a->total_space_size += n;
28: *space = a;
29: return(0);
30: }
32: /* Copy the values in space into arrays val, idx and idy. Then destroy space */
35: PetscErrorCode PetscMatStashSpaceContiguous(PetscInt bs2,PetscMatStashSpace *space,PetscScalar *val,PetscInt *idx,PetscInt *idy)
36: {
37: PetscMatStashSpace a;
38: PetscErrorCode ierr;
41: while ((*space) != PETSC_NULL){
42: a = (*space)->next;
43: PetscMemcpy(val,(*space)->val,((*space)->local_used*bs2)*sizeof(PetscScalar));
44: val += bs2*(*space)->local_used;
45: PetscMemcpy(idx,(*space)->idx,((*space)->local_used)*sizeof(PetscInt));
46: idx += (*space)->local_used;
47: PetscMemcpy(idy,(*space)->idy,((*space)->local_used)*sizeof(PetscInt));
48: idy += (*space)->local_used;
49:
50: PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
51: PetscFree(*space);
52: *space = a;
53: }
54: return(0);
55: }
59: PetscErrorCode PetscMatStashSpaceDestroy(PetscMatStashSpace *space)
60: {
61: PetscMatStashSpace a;
62: PetscErrorCode ierr;
65: while (*space){
66: a = (*space)->next;
67: PetscFree3((*space)->space_head,(*space)->idx,(*space)->idy);
68: PetscFree((*space));
69: *space = a;
70: }
71: *space = PETSC_NULL;
72: return(0);
73: }