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