Actual source code: matimpl.h
1: /* $Id: matimpl.h,v 1.126 2001/08/21 21:02:01 bsmith Exp $ */
6: #include petscmat.h
8: /*
9: This file defines the parts of the matrix data structure that are
10: shared by all matrix types.
11: */
13: /*
14: If you add entries here also add them to the MATOP enum
15: in include/petscmat.h and include/finclude/petscmat.h
16: */
17: typedef struct _MatOps *MatOps;
18: struct _MatOps {
19: int (*setvalues)(Mat,int,int *,int,int *,PetscScalar *,InsertMode),
20: (*getrow)(Mat,int,int *,int **,PetscScalar **),
21: (*restorerow)(Mat,int,int *,int **,PetscScalar **),
22: (*mult)(Mat,Vec,Vec),
23: /* 4*/ (*multadd)(Mat,Vec,Vec,Vec),
24: (*multtranspose)(Mat,Vec,Vec),
25: (*multtransposeadd)(Mat,Vec,Vec,Vec),
26: (*solve)(Mat,Vec,Vec),
27: (*solveadd)(Mat,Vec,Vec,Vec),
28: (*solvetranspose)(Mat,Vec,Vec),
29: /*10*/ (*solvetransposeadd)(Mat,Vec,Vec,Vec),
30: (*lufactor)(Mat,IS,IS,MatLUInfo*),
31: (*choleskyfactor)(Mat,IS,PetscReal),
32: (*relax)(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec),
33: (*transpose)(Mat,Mat *),
34: /*15*/ (*getinfo)(Mat,MatInfoType,MatInfo*),
35: (*equal)(Mat,Mat,PetscTruth *),
36: (*getdiagonal)(Mat,Vec),
37: (*diagonalscale)(Mat,Vec,Vec),
38: (*norm)(Mat,NormType,PetscReal *),
39: /*20*/ (*assemblybegin)(Mat,MatAssemblyType),
40: (*assemblyend)(Mat,MatAssemblyType),
41: (*compress)(Mat),
42: (*setoption)(Mat,MatOption),
43: (*zeroentries)(Mat),
44: /*25*/ (*zerorows)(Mat,IS,PetscScalar *),
45: (*lufactorsymbolic)(Mat,IS,IS,MatLUInfo*,Mat *),
46: (*lufactornumeric)(Mat,Mat *),
47: (*choleskyfactorsymbolic)(Mat,IS,PetscReal,Mat *),
48: (*choleskyfactornumeric)(Mat,Mat *),
49: /*30*/ (*setuppreallocation)(Mat),
50: (*ilufactorsymbolic)(Mat,IS,IS,MatILUInfo*,Mat *),
51: (*iccfactorsymbolic)(Mat,IS,PetscReal,int,Mat *),
52: (*getarray)(Mat,PetscScalar **),
53: (*restorearray)(Mat,PetscScalar **),
54: /*35*/ (*duplicate)(Mat,MatDuplicateOption,Mat *),
55: (*forwardsolve)(Mat,Vec,Vec),
56: (*backwardsolve)(Mat,Vec,Vec),
57: (*ilufactor)(Mat,IS,IS,MatILUInfo*),
58: (*iccfactor)(Mat,IS,PetscReal,int),
59: /*40*/ (*axpy)(PetscScalar *,Mat,Mat,MatStructure),
60: (*getsubmatrices)(Mat,int,IS *,IS *,MatReuse,Mat **),
61: (*increaseoverlap)(Mat,int,IS *,int),
62: (*getvalues)(Mat,int,int *,int,int *,PetscScalar *),
63: (*copy)(Mat,Mat,MatStructure),
64: /*45*/ (*printhelp)(Mat),
65: (*scale)(PetscScalar *,Mat),
66: (*shift)(PetscScalar *,Mat),
67: (*diagonalset)(Mat,Vec,InsertMode),
68: (*iludtfactor)(Mat,MatILUInfo*,IS,IS,Mat *),
69: /*50*/ (*getblocksize)(Mat,int *),
70: (*getrowij)(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *),
71: (*restorerowij)(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *),
72: (*getcolumnij)(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *),
73: (*restorecolumnij)(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *),
74: /*55*/ (*fdcoloringcreate)(Mat,ISColoring,MatFDColoring),
75: (*coloringpatch)(Mat,int,int,int *,ISColoring*),
76: (*setunfactored)(Mat),
77: (*permute)(Mat,IS,IS,Mat*),
78: (*setvaluesblocked)(Mat,int,int *,int,int *,PetscScalar *,InsertMode),
79: /*60*/ (*getsubmatrix)(Mat,IS,IS,int,MatReuse,Mat*),
80: (*destroy)(Mat),
81: (*view)(Mat,PetscViewer),
82: (*getmaps)(Mat,PetscMap*,PetscMap*),
83: (*usescaledform)(Mat,PetscTruth),
84: /*65*/ (*scalesystem)(Mat,Vec,Vec),
85: (*unscalesystem)(Mat,Vec,Vec),
86: (*setlocaltoglobalmapping)(Mat,ISLocalToGlobalMapping),
87: (*setvalueslocal)(Mat,int,int *,int,int *,PetscScalar *,InsertMode),
88: (*zerorowslocal)(Mat,IS,PetscScalar *),
89: /*70*/ (*getrowmax)(Mat,Vec),
90: (*convert)(Mat,MatType,Mat*),
91: (*setcoloring)(Mat,ISColoring),
92: (*setvaluesadic)(Mat,void*),
93: (*setvaluesadifor)(Mat,int,void*),
94: /*75*/ (*fdcoloringapply)(Mat,MatFDColoring,Vec,MatStructure*,void*),
95: (*setfromoptions)(Mat),
96: (*multconstrained)(Mat,Vec,Vec),
97: (*multtransposeconstrained)(Mat,Vec,Vec),
98: (*ilufactorsymbolicconstrained)(Mat,IS,IS,double,int,int,Mat *),
99: (*serialize)(MPI_Comm, Mat *, PetscViewer, PetscTruth),
100: /*80*/ (*permutesparsify)(Mat, int, double, double, IS, IS, Mat *),
101: (*mults)(Mat, Vecs, Vecs),
102: (*solves)(Mat, Vecs, Vecs),
103: (*getinertia)(Mat,int*,int*,int*);
104: };
106: /*
107: Utility private matrix routines
108: */
109: EXTERN int MatConvert_Basic(Mat,MatType,Mat*);
110: EXTERN int MatCopy_Basic(Mat,Mat,MatStructure);
111: EXTERN int MatView_Private(Mat);
112: EXTERN int MatGetPetscMaps_Petsc(Mat,PetscMap *,PetscMap *);
113: EXTERN int MatHeaderCopy(Mat,Mat);
115: /*
116: The stash is used to temporarily store inserted matrix values that
117: belong to another processor. During the assembly phase the stashed
118: values are moved to the correct processor and
119: */
121: typedef struct {
122: int nmax; /* maximum stash size */
123: int umax; /* user specified max-size */
124: int oldnmax; /* the nmax value used previously */
125: int n; /* stash size */
126: int bs; /* block size of the stash */
127: int reallocs; /* preserve the no of mallocs invoked */
128: int *idx; /* global row numbers in stash */
129: int *idy; /* global column numbers in stash */
130: MatScalar *array; /* array to hold stashed values */
131: /* The following variables are used for communication */
132: MPI_Comm comm;
133: int size,rank;
134: int tag1,tag2;
135: MPI_Request *send_waits; /* array of send requests */
136: MPI_Request *recv_waits; /* array of receive requests */
137: MPI_Status *send_status; /* array of send status */
138: int nsends,nrecvs; /* numbers of sends and receives */
139: MatScalar *svalues,*rvalues; /* sending and receiving data */
140: int rmax; /* maximum message length */
141: int *nprocs; /* tmp data used both duiring scatterbegin and end */
142: int nprocessed; /* number of messages already processed */
143: } MatStash;
145: EXTERN int MatStashCreate_Private(MPI_Comm,int,MatStash*);
146: EXTERN int MatStashDestroy_Private(MatStash*);
147: EXTERN int MatStashScatterEnd_Private(MatStash*);
148: EXTERN int MatStashSetInitialSize_Private(MatStash*,int);
149: EXTERN int MatStashGetInfo_Private(MatStash*,int*,int*);
150: EXTERN int MatStashValuesRow_Private(MatStash*,int,int,int*,MatScalar*);
151: EXTERN int MatStashValuesCol_Private(MatStash*,int,int,int*,MatScalar*,int);
152: EXTERN int MatStashValuesRowBlocked_Private(MatStash*,int,int,int*,MatScalar*,int,int,int);
153: EXTERN int MatStashValuesColBlocked_Private(MatStash*,int,int,int*,MatScalar*,int,int,int);
154: EXTERN int MatStashScatterBegin_Private(MatStash*,int*);
155: EXTERN int MatStashScatterGetMesg_Private(MatStash*,int*,int**,int**,MatScalar**,int*);
157: #define FACTOR_LU 1
158: #define FACTOR_CHOLESKY 2
160: typedef struct {
161: int dim;
162: int dims[4];
163: int starts[4];
164: PetscTruth noc; /* this is a single component problem, hence user will not set MatStencil.c */
165: } MatStencilInfo;
167: struct _p_Mat {
168: PETSCHEADER(struct _MatOps)
169: PetscMap rmap,cmap;
170: void *data; /* implementation-specific data */
171: int factor; /* 0, FACTOR_LU, or FACTOR_CHOLESKY */
172: PetscReal lupivotthreshold; /* threshold for pivoting */
173: PetscTruth assembled; /* is the matrix assembled? */
174: PetscTruth was_assembled; /* new values inserted into assembled mat */
175: int num_ass; /* number of times matrix has been assembled */
176: PetscTruth same_nonzero; /* matrix has same nonzero pattern as previous */
177: int M,N; /* global numbers of rows, columns */
178: int m,n; /* local numbers of rows, columns */
179: MatInfo info; /* matrix information */
180: ISLocalToGlobalMapping mapping; /* mapping used in MatSetValuesLocal() */
181: ISLocalToGlobalMapping bmapping; /* mapping used in MatSetValuesBlockedLocal() */
182: InsertMode insertmode; /* have values been inserted in matrix or added? */
183: MatStash stash,bstash; /* used for assembling off-proc mat emements */
184: MatNullSpace nullsp;
185: PetscTruth preallocated;
186: MatStencilInfo stencil; /* information for structured grid */
187: PetscTruth symmetric,structurally_symmetric;
188: void *spptr; /* pointer for special library like SuperLU */
189: void *esimat;
190: };
192: #define MatPreallocated(A) {int _e;if (!(A)->preallocated) {_e = MatSetUpPreallocation(A);CHKERRQ(_e);}}
193: extern int MatAXPY_Basic(PetscScalar*,Mat,Mat,MatStructure);
195: /*
196: Object for partitioning graphs
197: */
199: typedef struct _MatPartitioningOps *MatPartitioningOps;
200: struct _MatPartitioningOps {
201: int (*apply)(MatPartitioning,IS*);
202: int (*setfromoptions)(MatPartitioning);
203: int (*destroy)(MatPartitioning);
204: int (*view)(MatPartitioning,PetscViewer);
205: };
207: struct _p_MatPartitioning {
208: PETSCHEADER(struct _MatPartitioningOps)
209: Mat adj;
210: int *vertex_weights;
211: int n; /* number of partitions */
212: void *data;
213: int setupcalled;
214: };
216: /*
217: MatFDColoring is used to compute Jacobian matrices efficiently
218: via coloring. The data structure is explained below in an example.
220: Color = 0 1 0 2 | 2 3 0
221: ---------------------------------------------------
222: 00 01 | 05
223: 10 11 | 14 15 Processor 0
224: 22 23 | 25
225: 32 33 |
226: ===================================================
227: | 44 45 46
228: 50 | 55 Processor 1
229: | 64 66
230: ---------------------------------------------------
232: ncolors = 4;
234: ncolumns = {2,1,1,0}
235: columns = {{0,2},{1},{3},{}}
236: nrows = {4,2,3,3}
237: rows = {{0,1,2,3},{0,1},{1,2,3},{0,1,2}}
238: columnsforrow = {{0,0,2,2},{1,1},{4,3,3},{5,5,5}}
239: vscaleforrow = {{,,,},{,},{,,},{,,}}
240: vwscale = {dx(0),dx(1),dx(2),dx(3)} MPI Vec
241: vscale = {dx(0),dx(1),dx(2),dx(3),dx(4),dx(5)} Seq Vec
243: ncolumns = {1,0,1,1}
244: columns = {{6},{},{4},{5}}
245: nrows = {3,0,2,2}
246: rows = {{0,1,2},{},{1,2},{1,2}}
247: columnsforrow = {{6,0,6},{},{4,4},{5,5}}
248: vscaleforrow = {{,,},{},{,},{,}}
249: vwscale = {dx(4),dx(5),dx(6)} MPI Vec
250: vscale = {dx(0),dx(4),dx(5),dx(6)} Seq Vec
252: See the routine MatFDColoringApply() for how this data is used
253: to compute the Jacobian.
255: */
257: struct _p_MatFDColoring{
258: PETSCHEADER(int)
259: int M,N,m; /* total rows, columns; local rows */
260: int rstart; /* first row owned by local processor */
261: int ncolors; /* number of colors */
262: int *ncolumns; /* number of local columns for a color */
263: int **columns; /* lists the local columns of each color (using global column numbering) */
264: int *nrows; /* number of local rows for each color */
265: int **rows; /* lists the local rows for each color (using the local row numbering) */
266: int **columnsforrow; /* lists the corresponding columns for those rows (using the global column) */
267: PetscReal error_rel; /* square root of relative error in computing function */
268: PetscReal umin; /* minimum allowable u'dx value */
269: int freq; /* frequency at which new Jacobian is computed */
270: Vec w1,w2,w3; /* work vectors used in computing Jacobian */
271: int (*f)(void); /* function that defines Jacobian */
272: void *fctx; /* optional user-defined context for use by the function f */
273: int **vscaleforrow; /* location in vscale for each columnsforrow[] entry */
274: Vec vscale; /* holds FD scaling, i.e. 1/dx for each perturbed column */
275: PetscTruth usersetsrecompute;/* user determines when Jacobian is recomputed, via MatFDColoringSetRecompute() */
276: PetscTruth recompute; /* used with usersetrecompute to determine if Jacobian should be recomputed */
277: Vec F; /* current value of user provided function; can set with MatFDColoringSetF() */
278: int currentcolor; /* color for which function evaluation is being done now */
279: };
281: /*
282: Null space context for preconditioner/operators
283: */
284: struct _p_MatNullSpace {
285: PETSCHEADER(int)
286: int has_cnst;
287: int n;
288: Vec* vecs;
289: Vec vec; /* for out of place removals */
290: };
293: #endif