Changeset 5890 for issm/trunk
- Timestamp:
- 09/19/10 09:29:19 (15 years ago)
- Location:
- issm/trunk/src/c/toolkits/petsc/patches
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/toolkits/petsc/patches/NewMat.cpp
r3775 r5890 19 19 #include "../../../include/include.h" 20 20 21 Mat NewMat(int M,int N,double* psparsity,int* pconnectivity,int* pnumberofdofspernode){ 21 /*NewMat(int M,int N){{{1*/ 22 Mat NewMat(int M,int N){ 22 23 23 24 /*output:*/ 24 25 Mat outmatrix=NULL; 25 26 26 /* Recoverparameters: */27 /*parameters: */ 27 28 double sparsity=.001; //default 29 int m,n; 30 int d_nz,o_nz,nnz; 28 31 29 int connectivity=10; //default 30 int numberofdofspernode=2; //default 32 /*Determine local sizes: */ 33 m=PetscDetermineLocalSize(M); 34 n=PetscDetermineLocalSize(N); 35 36 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros. 37 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 38 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 31 39 32 /*local sizes: */ 40 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 41 42 return outmatrix; 43 } 44 /*}}}*/ 45 /*NewMat(int M,int N,double sparsity){{{1*/ 46 Mat NewMat(int M,int N,double sparsity){ 47 48 /*output:*/ 49 Mat outmatrix=NULL; 50 51 /*parameters: */ 33 52 int m,n; 34 35 /*row and col distribution: */36 53 int d_nz,o_nz; 37 54 int nnz; … … 41 58 n=PetscDetermineLocalSize(N); 42 59 43 /*Branch on what was provided: */ 60 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros. 61 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 62 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 44 63 45 if(!psparsity && !pconnectivity && !pnumberofdofspernode){ 46 47 /*Ok, we have our default sparsity, create matrix using this info: */ 48 49 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros. 50 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 51 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 52 53 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 54 55 } 56 else if(psparsity){ 57 58 /*Same as above, except we bypass the default sparsity: */ 59 if(pconnectivity || pnumberofdofspernode) 60 ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode); 61 62 sparsity=*psparsity; 63 64 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros. 65 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 66 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2 67 68 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 69 70 } 71 else if(pconnectivity && pnumberofdofspernode){ 72 73 /*entirely different logic. We use the connectivity and numberofdofspernode to figure out how many non-zeros are 74 *present per row: */ 75 76 if(psparsity) ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode); 77 78 connectivity=*pconnectivity; 79 numberofdofspernode=*pnumberofdofspernode; 80 81 /*Figure out number of non zeros per row: */ 82 d_nz=(int)connectivity*numberofdofspernode/2; 83 o_nz=(int)connectivity*numberofdofspernode/2; 84 85 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 86 87 } 88 else{ 89 ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode); 90 } 64 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 91 65 92 66 return outmatrix; 93 67 } 68 /*}}}*/ 69 /*NewMat(int M,int N,int connectivity,int numberofdofspernode){{{1*/ 70 Mat NewMat(int M,int N,int connectivity,int numberofdofspernode){ 71 72 /*output:*/ 73 Mat outmatrix=NULL; 74 75 /*parameters: */ 76 int m,n; 77 int d_nz,o_nz; 78 int nnz; 79 80 /*Determine local sizes: */ 81 m=PetscDetermineLocalSize(M); 82 n=PetscDetermineLocalSize(N); 83 84 /*Figure out number of non zeros per row: */ 85 d_nz=(int)connectivity*numberofdofspernode/2; 86 o_nz=(int)connectivity*numberofdofspernode/2; 87 88 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 89 90 return outmatrix; 91 } 92 /*}}}*/ -
issm/trunk/src/c/toolkits/petsc/patches/NewVec.cpp
r1 r5890 16 16 #include "./petscpatches.h" 17 17 18 Vec NewVec(int size ){18 Vec NewVec(int size,bool fromlocalsize){ 19 19 20 20 int ierr; … … 25 25 26 26 /*determine local size of vector: */ 27 local_size=PetscDetermineLocalSize(size); 27 if(fromlocalsize){ 28 local_size=size; 29 } 30 else{ 31 local_size=PetscDetermineLocalSize(size); 32 } 33 28 34 VecCreate(PETSC_COMM_WORLD,&vector); 29 35 … … 36 42 return vector; 37 43 } 38 39 40 41 -
issm/trunk/src/c/toolkits/petsc/patches/petscpatches.h
r5787 r5890 22 22 23 23 int PetscDetermineLocalSize(int global_size); 24 Vec NewVec(int size); 25 Vec NewVecFromLocalSize(int local_size); 26 Mat NewMat(int M,int N,double* psparsity,int* pconnectivity,int* pnumberofdofspernode); 24 Vec NewVec(int size,bool fromlocalsize); 25 Mat NewMat(int M,int N); 26 Mat NewMat(int M,int N,double sparsity); 27 Mat NewMat(int M,int N,int connectivity,int numberofdofspernode); 28 27 29 int VecTranspose(Vec* tvector,Vec vector); 28 30 int VecToMPISerial(double** pgathered_vector, Vec vector);
Note:
See TracChangeset
for help on using the changeset viewer.