1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: stash.c,v 1.18 1997/10/19 03:27:05 bsmith Exp bsmith $"; 3 #endif 4 5 #include "src/vec/vecimpl.h" 6 #include "src/mat/matimpl.h" 7 8 #define CHUNCKSIZE 5000 9 /* 10 This stash is currently used for all the parallel matrix implementations. 11 The stash is where elements of a matrix destined to be stored on other 12 processors are kept until matrix assembly is done. 13 14 This is a simple minded stash. Simply add entry to end of stash. 15 */ 16 17 #undef __FUNC__ 18 #define __FUNC__ "StashInitialize_Private" 19 int StashInitialize_Private(Stash *stash) 20 { 21 PetscFunctionBegin; 22 stash->nmax = 0; 23 stash->n = 0; 24 stash->array = 0; 25 stash->idx = 0; 26 stash->idy = 0; 27 PetscFunctionReturn(0); 28 } 29 30 #undef __FUNC__ 31 #define __FUNC__ "StashBuild_Private" 32 int StashBuild_Private(Stash *stash) 33 { 34 PetscFunctionBegin; 35 stash->nmax = CHUNCKSIZE; /* completely arbitrary number */ 36 stash->n = 0; 37 stash->array = (Scalar *) PetscMalloc( stash->nmax*(2*sizeof(int) + 38 sizeof(Scalar))); CHKPTRQ(stash->array); 39 stash->idx = (int *) (stash->array + stash->nmax); CHKPTRQ(stash->idx); 40 stash->idy = (int *) (stash->idx + stash->nmax); CHKPTRQ(stash->idy); 41 PetscFunctionReturn(0); 42 } 43 44 #undef __FUNC__ 45 #define __FUNC__ "StashDestroy_Private" 46 int StashDestroy_Private(Stash *stash) 47 { 48 PetscFunctionBegin; 49 stash->nmax = stash->n = 0; 50 if (stash->array) {PetscFree(stash->array); stash->array = 0;} 51 PetscFunctionReturn(0); 52 } 53 54 #undef __FUNC__ 55 #define __FUNC__ "StashInfo_Private" 56 int StashInfo_Private(Stash *stash) 57 { 58 PetscFunctionBegin; 59 PLogInfo(0,"StashInfo_Private:Stash size %d\n",stash->n); 60 PetscFunctionReturn(0); 61 } 62 63 /* 64 Should do this properly. With a sorted array. 65 */ 66 #undef __FUNC__ 67 #define __FUNC__ "StashValues_Private" 68 int StashValues_Private(Stash *stash,int row,int n, int *idxn,Scalar *values,InsertMode addv) 69 { 70 int i, found, *n_idx, *n_idy; 71 Scalar val, *n_array; 72 73 PetscFunctionBegin; 74 for ( i=0; i<n; i++ ) { 75 found = 0; 76 val = *values++; 77 if (!found) { /* not found so add to end */ 78 if ( stash->n == stash->nmax ) { 79 /* allocate a larger stash */ 80 n_array = (Scalar *) PetscMalloc( (stash->nmax + CHUNCKSIZE)*( 81 2*sizeof(int)+sizeof(Scalar)));CHKPTRQ(n_array); 82 n_idx = (int *) (n_array + stash->nmax + CHUNCKSIZE); 83 n_idy = (int *) (n_idx + stash->nmax + CHUNCKSIZE); 84 PetscMemcpy(n_array,stash->array,stash->nmax*sizeof(Scalar)); 85 PetscMemcpy(n_idx,stash->idx,stash->nmax*sizeof(int)); 86 PetscMemcpy(n_idy,stash->idy,stash->nmax*sizeof(int)); 87 if (stash->array) PetscFree(stash->array); 88 stash->array = n_array; stash->idx = n_idx; stash->idy = n_idy; 89 stash->nmax += CHUNCKSIZE; 90 } 91 stash->array[stash->n] = val; 92 stash->idx[stash->n] = row; 93 stash->idy[stash->n++] = idxn[i]; 94 } 95 } 96 PetscFunctionReturn(0); 97 } 98 99 100 101