#include <petscmat.h>
#include <petscvec.h>
#include <petscksp.h>
#include <petscsys.h>
#include "./SolverEnum.h"
#include "../../toolkitsenums.h"
#include "../../../shared/io/Comm/IssmComm.h"
Go to the source code of this file.
|
Vec | NewVec (int size, ISSM_MPI_Comm comm, bool fromlocalsize=false) |
|
Mat | NewMat (int M, int N, ISSM_MPI_Comm comm) |
|
Mat | NewMat (int M, int N, double sparsity, ISSM_MPI_Comm comm) |
|
Mat | NewMat (int M, int N, int connectivity, int numberofdofspernode, ISSM_MPI_Comm comm) |
|
int | VecToMPISerial (double **pgathered_vector, Vec vector, ISSM_MPI_Comm comm, bool broadcast=true) |
|
void | MatFree (Mat *pmat) |
|
void | ISFree (IS *pis) |
|
void | VecFree (Vec *pvec) |
|
void | KSPFree (KSP *pksp) |
|
int | MatPartition (Mat *poutmatrix, Mat matrixA, double *row_partition_vector, int row_partition_vector_size, double *col_partition_vector, int col_partition_vector_size) |
|
void | PetscOptionsDetermineSolverType (int *psolver_type) |
|
void | MatMultPatch (Mat A, Vec X, Vec AX, ISSM_MPI_Comm comm) |
|
void | MatToSerial (double **poutmatrix, Mat matrix, ISSM_MPI_Comm comm) |
|
Vec | SerialToVec (double *vector, int vector_size) |
|
InsertMode | ISSMToPetscInsertMode (InsMode mode) |
|
NormType | ISSMToPetscNormMode (NormMode mode) |
|
MatType | ISSMToPetscMatrixType (MatrixType type) |
|
◆ NewVec()
Vec NewVec |
( |
int |
size, |
|
|
ISSM_MPI_Comm |
comm, |
|
|
bool |
fromlocalsize = false |
|
) |
| |
Definition at line 19 of file NewVec.cpp.
34 VecCreate(comm,&vector);
35 VecSetSizes(vector,local_size,PETSC_DECIDE);
36 VecSetFromOptions(vector);
◆ NewMat() [1/3]
Definition at line 21 of file NewMat.cpp.
27 double sparsity=0.001;
35 nnz=(int)((
double)M*(double)N*sparsity);
36 d_nz=(int)((
double)nnz/(double)M/2.0);
37 o_nz=(int)((
double)nnz/(double)M/2.0);
39 #if _PETSC_MAJOR_ == 3 && _PETSC_MINOR_ > 2
40 MatCreateAIJ(comm,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
42 MatCreateMPIAIJ(comm,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
◆ NewMat() [2/3]
Definition at line 49 of file NewMat.cpp.
63 nnz=(int)((
double)M*(double)N*sparsity);
64 d_nz=(int)((
double)nnz/(double)M/2.0);
65 o_nz=(int)((
double)nnz/(double)M/2.0);
67 #if _PETSC_MAJOR_ == 3 && _PETSC_MINOR_ > 2
69 MatCreateDense(comm,m,n,M,N,NULL,&outmatrix);
72 MatCreateAIJ(comm,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
75 MatCreateMPIAIJ(comm,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
◆ NewMat() [3/3]
Mat NewMat |
( |
int |
M, |
|
|
int |
N, |
|
|
int |
connectivity, |
|
|
int |
numberofdofspernode, |
|
|
ISSM_MPI_Comm |
comm |
|
) |
| |
Definition at line 82 of file NewMat.cpp.
91 #if _PETSC_MAJOR_ >= 3
92 #if defined(_HAVE_PETSCDEV_) || _PETSC_MINOR_ >=4
106 d_nz=(int)connectivity*numberofdofspernode/2;
107 o_nz=(int)connectivity*numberofdofspernode/2;
109 MatCreate(comm,&outmatrix);
110 MatSetSizes(outmatrix,m,n,M,N);
111 MatSetFromOptions(outmatrix);
114 MatGetType(outmatrix,&type);
116 if((strcmp(type,
"mpiaij")==0) || (strcmp(type,
"mpidense")==0)){
117 MatMPIAIJSetPreallocation(outmatrix,d_nz,NULL,o_nz,NULL);
◆ VecToMPISerial()
int VecToMPISerial |
( |
double ** |
pgathered_vector, |
|
|
Vec |
vector, |
|
|
ISSM_MPI_Comm |
comm, |
|
|
bool |
broadcast = true |
|
) |
| |
Definition at line 14 of file VecToMPISerial.cpp.
22 PetscInt lower_row,upper_row;
28 double* local_vector=NULL;
34 double* gathered_vector=NULL;
40 VecGetSize(vector,&vector_size);
42 *pgathered_vector=NULL;
47 if(broadcast || my_rank==0){
48 gathered_vector=xNew<double>(vector_size);
52 VecGetOwnershipRange(vector,&lower_row,&upper_row);
54 range=upper_row-lower_row+1;
57 idxn=xNew<int>(range);
58 for (i=0;i<range;i++){
59 *(idxn+i)=lower_row+i;
61 local_vector=xNew<double>(range);
63 VecGetValues(vector,range,idxn,local_vector);
68 for (i=1;i<num_procs;i++){
84 if (range)memcpy(gathered_vector+lower_row,local_vector,range*
sizeof(
double));
93 *pgathered_vector=gathered_vector;
97 xDelete<double>(local_vector);
◆ MatFree()
void MatFree |
( |
Mat * |
pmat | ) |
|
Definition at line 16 of file MatFree.cpp.
18 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
19 if(*pmat)MatDestroy(*pmat);
22 if(*pmat)MatDestroy(pmat);
◆ ISFree()
◆ VecFree()
void VecFree |
( |
Vec * |
pvec | ) |
|
Definition at line 16 of file VecFree.cpp.
18 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
19 if(*pvec)VecDestroy(*pvec);
21 if(*pvec)VecDestroy(pvec);
◆ KSPFree()
void KSPFree |
( |
KSP * |
pksp | ) |
|
Definition at line 16 of file KSPFree.cpp.
18 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
19 if(*pksp)KSPDestroy(*pksp);
22 if(*pksp)KSPDestroy(pksp);
◆ MatPartition()
int MatPartition |
( |
Mat * |
poutmatrix, |
|
|
Mat |
matrixA, |
|
|
double * |
row_partition_vector, |
|
|
int |
row_partition_vector_size, |
|
|
double * |
col_partition_vector, |
|
|
int |
col_partition_vector_size |
|
) |
| |
◆ PetscOptionsDetermineSolverType()
void PetscOptionsDetermineSolverType |
( |
int * |
psolver_type | ) |
|
Definition at line 20 of file PetscOptionsDetermineSolverType.cpp.
23 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
33 #if (_PETSC_MAJOR_==3) && (_PETSC_MINOR_>=7)
34 PetscOptionsGetString(NULL,PETSC_NULL,
"-mat_type",&option[0],100,&flag);
36 PetscOptionsGetString(PETSC_NULL,
"-mat_type",&option[0],100,&flag);
39 if (strcmp(option,
"aijmumps")==0){
42 if (strcmp(option,
"sbaijmumps")==0){
45 if (strcmp(option,
"aijspooles")==0){
48 if (strcmp(option,
"sbaijspooles")==0){
51 if (strcmp(option,
"superlu_dist")==0){
54 if (strcmp(option,
"")==0){
58 #if _PETSC_MAJOR_ >= 3
59 #if (_PETSC_MINOR_>=7)
60 PetscOptionsGetString(NULL,PETSC_NULL,
"-pc_factor_mat_solver_package",&option[0],100,&flag);
62 PetscOptionsGetString(PETSC_NULL,
"-pc_factor_mat_solver_package",&option[0],100,&flag);
64 if (strcmp(option,
"mumps")==0){
69 #if (_PETSC_MAJOR_==3) && (_PETSC_MINOR_>=7)
70 PetscOptionsGetString(NULL,PETSC_NULL,
"-issm_option_solver",&option[0],100,&flag);
72 PetscOptionsGetString(PETSC_NULL,
"-issm_option_solver",&option[0],100,&flag);
74 if(strcmp(option,
"FS")==0 || strcmp(option,
"stokes")==0){
78 *psolver_type=solver_type;
◆ MatMultPatch()
Definition at line 23 of file MatMultPatch.cpp.
34 MatGetLocalSize(A,&m,&n);;
36 MatMult(A,X_rel,AX); ;
37 #if _PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)
◆ MatToSerial()
void MatToSerial |
( |
double ** |
poutmatrix, |
|
|
Mat |
matrix, |
|
|
ISSM_MPI_Comm |
comm |
|
) |
| |
Definition at line 14 of file MatToSerial.cpp.
21 PetscInt lower_row,upper_row;
27 double* local_matrix=NULL;
35 double* outmatrix=NULL;
38 MatGetSize(matrix,&M,&N);
41 MatGetOwnershipRange(matrix,&lower_row,&upper_row);
43 range=upper_row-lower_row+1;
46 if (my_rank==0)outmatrix=xNew<double>(M*N);
49 local_matrix=xNew<double>(N*range);
50 idxm=xNew<int>(range);
56 for (i=0;i<range;i++){
57 *(idxm+i)=lower_row+i;
60 MatGetValues(matrix,range,idxm,N,idxn,local_matrix);
66 for (i=1;i<num_procs;i++){
81 memcpy(outmatrix,local_matrix,N*range*
sizeof(
double));
85 *poutmatrix=outmatrix;
88 xDelete<double>(local_matrix);
◆ SerialToVec()
Vec SerialToVec |
( |
double * |
vector, |
|
|
int |
vector_size |
|
) |
| |
◆ ISSMToPetscInsertMode()
InsertMode ISSMToPetscInsertMode |
( |
InsMode |
mode | ) |
|
◆ ISSMToPetscNormMode()
NormType ISSMToPetscNormMode |
( |
NormMode |
mode | ) |
|
◆ ISSMToPetscMatrixType()
int ISSM_MPI_Send(void *buf, int count, ISSM_MPI_Datatype datatype, int dest, int tag, ISSM_MPI_Comm comm)
int ISSM_MPI_Recv(void *buf, int count, ISSM_MPI_Datatype datatype, int source, int tag, ISSM_MPI_Comm comm, ISSM_MPI_Status *status)