1 #ifndef lint 2 static char vcid[] = "$Id: stash.c,v 1.12 1996/11/19 16:31:54 bsmith Exp balay $"; 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 __FUNCTION__ 18 #define __FUNCTION__ "StashInitialize_Private" 19 int StashInitialize_Private(Stash *stash) 20 { 21 stash->nmax = 0; 22 stash->n = 0; 23 stash->array = 0; 24 stash->idx = 0; 25 stash->idy = 0; 26 return 0; 27 } 28 29 #undef __FUNCTION__ 30 #define __FUNCTION__ "StashBuild_Private" 31 int StashBuild_Private(Stash *stash) 32 { 33 stash->nmax = CHUNCKSIZE; /* completely arbitrary number */ 34 stash->n = 0; 35 stash->array = (Scalar *) PetscMalloc( stash->nmax*(2*sizeof(int) + 36 sizeof(Scalar))); CHKPTRQ(stash->array); 37 stash->idx = (int *) (stash->array + stash->nmax); CHKPTRQ(stash->idx); 38 stash->idy = (int *) (stash->idx + stash->nmax); CHKPTRQ(stash->idy); 39 return 0; 40 } 41 42 #undef __FUNCTION__ 43 #define __FUNCTION__ "StashDestroy_Private" 44 int StashDestroy_Private(Stash *stash) 45 { 46 stash->nmax = stash->n = 0; 47 if (stash->array) {PetscFree(stash->array); stash->array = 0;} 48 return 0; 49 } 50 51 #undef __FUNCTION__ 52 #define __FUNCTION__ "StashInfo_Private" 53 int StashInfo_Private(Stash *stash) 54 { 55 PLogInfo(0,"Stash size %d\n",stash->n); 56 return 0; 57 } 58 59 /* 60 Should do this properly. With a sorted array. 61 */ 62 #undef __FUNCTION__ 63 #define __FUNCTION__ "StashValues_Private" 64 int StashValues_Private(Stash *stash,int row,int n, int *idxn,Scalar *values,InsertMode addv) 65 { 66 int i, found, *n_idx, *n_idy; 67 Scalar val, *n_array; 68 69 for ( i=0; i<n; i++ ) { 70 found = 0; 71 val = *values++; 72 if (!found) { /* not found so add to end */ 73 if ( stash->n == stash->nmax ) { 74 /* allocate a larger stash */ 75 n_array = (Scalar *) PetscMalloc( (stash->nmax + CHUNCKSIZE)*( 76 2*sizeof(int)+sizeof(Scalar)));CHKPTRQ(n_array); 77 n_idx = (int *) (n_array + stash->nmax + CHUNCKSIZE); 78 n_idy = (int *) (n_idx + stash->nmax + CHUNCKSIZE); 79 PetscMemcpy(n_array,stash->array,stash->nmax*sizeof(Scalar)); 80 PetscMemcpy(n_idx,stash->idx,stash->nmax*sizeof(int)); 81 PetscMemcpy(n_idy,stash->idy,stash->nmax*sizeof(int)); 82 if (stash->array) PetscFree(stash->array); 83 stash->array = n_array; stash->idx = n_idx; stash->idy = n_idy; 84 stash->nmax += CHUNCKSIZE; 85 } 86 stash->array[stash->n] = val; 87 stash->idx[stash->n] = row; 88 stash->idy[stash->n++] = idxn[i]; 89 } 90 } 91 return 0; 92 } 93 94 95 96