File: MatCreateAIJ.html

package info (click to toggle)
petsc 3.7.5%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 163,864 kB
  • ctags: 618,438
  • sloc: ansic: 515,133; python: 29,793; makefile: 20,458; fortran: 18,998; cpp: 6,515; f90: 3,914; sh: 1,012; xml: 621; objc: 445; csh: 240; java: 13
file content (214 lines) | stat: -rw-r--r-- 12,287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML3.2 EN">
<HTML>
<HEAD> <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateAIJ.html" />
<META NAME="GENERATOR" CONTENT="DOCTEXT">
<TITLE>MatCreateAIJ</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
   <div id="version" align=right><b>petsc-3.7.5 2017-01-01</b></div>
   <div id="bugreport" align=right><a href="mailto:petsc-maint@mcs.anl.gov?subject=Typo or Error in Documentation &body=Please describe the typo or error in the documentation: petsc-3.7.5 v3.7.5 docs/manualpages/Mat/MatCreateAIJ.html "><small>Report Typos and Errors</small></a></div>
<A NAME="MatCreateAIJ"><H1>MatCreateAIJ</H1></A>
Creates a sparse parallel matrix in AIJ format (the default parallel PETSc format).  For good matrix assembly performance the user should preallocate the matrix storage by setting the parameters d_nz (or d_nnz) and o_nz (or o_nnz).  By setting these parameters accurately, performance can be increased by more than a factor of 50. 
<H3><FONT COLOR="#CC3333">Synopsis</FONT></H3>
<PRE>
#include "petscmat.h" 
PetscErrorCode  MatCreateAIJ(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,PetscInt d_nz,const PetscInt d_nnz[],PetscInt o_nz,const PetscInt o_nnz[],Mat *A)
</PRE>
Collective on <A HREF="../Sys/MPI_Comm.html#MPI_Comm">MPI_Comm</A>
<P>
<H3><FONT COLOR="#CC3333">Input Parameters</FONT></H3>
<TABLE border="0" cellpadding="0" cellspacing="0">
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>comm </B></TD><TD>- MPI communicator
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>m </B></TD><TD>- number of local rows (or <A HREF="../Sys/PETSC_DECIDE.html#PETSC_DECIDE">PETSC_DECIDE</A> to have calculated if M is given)
This value should be the same as the local size used in creating the
y vector for the matrix-vector product y = Ax.
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>n </B></TD><TD>- This value should be the same as the local size used in creating the
x vector for the matrix-vector product y = Ax. (or <A HREF="../Sys/PETSC_DECIDE.html#PETSC_DECIDE">PETSC_DECIDE</A> to have
calculated if N is given) For square matrices n is almost always m.
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>M </B></TD><TD>- number of global rows (or <A HREF="../Sys/PETSC_DETERMINE.html#PETSC_DETERMINE">PETSC_DETERMINE</A> to have calculated if m is given)
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>N </B></TD><TD>- number of global columns (or <A HREF="../Sys/PETSC_DETERMINE.html#PETSC_DETERMINE">PETSC_DETERMINE</A> to have calculated if n is given)
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>d_nz  </B></TD><TD>- number of nonzeros per row in DIAGONAL portion of local submatrix
(same value is used for all local rows)
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>d_nnz </B></TD><TD>- array containing the number of nonzeros in the various rows of the
DIAGONAL portion of the local submatrix (possibly different for each row)
or NULL, if d_nz is used to specify the nonzero structure.
The size of this array is equal to the number of local rows, i.e 'm'.
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>o_nz  </B></TD><TD>- number of nonzeros per row in the OFF-DIAGONAL portion of local
submatrix (same value is used for all local rows).
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>o_nnz </B></TD><TD>- array containing the number of nonzeros in the various rows of the
OFF-DIAGONAL portion of the local submatrix (possibly different for
each row) or NULL, if o_nz is used to specify the nonzero
structure. The size of this array is equal to the number
of local rows, i.e 'm'.
</TD></TR></TABLE>
<P>
<H3><FONT COLOR="#CC3333">Output Parameter</FONT></H3>
<DT><B>A </B> -the matrix
<br>
<P>
It is recommended that one use the <A HREF="../Mat/MatCreate.html#MatCreate">MatCreate</A>(), <A HREF="../Mat/MatSetType.html#MatSetType">MatSetType</A>() and/or <A HREF="../Mat/MatSetFromOptions.html#MatSetFromOptions">MatSetFromOptions</A>(),
MatXXXXSetPreallocation() paradgm instead of this routine directly.
[MatXXXXSetPreallocation() is, for example, <A HREF="../Mat/MatSeqAIJSetPreallocation.html#MatSeqAIJSetPreallocation">MatSeqAIJSetPreallocation</A>]
<P>
<H3><FONT COLOR="#CC3333">Notes</FONT></H3>
If the *_nnz parameter is given then the *_nz parameter is ignored
<P>
m,n,M,N parameters specify the size of the matrix, and its partitioning across
processors, while d_nz,d_nnz,o_nz,o_nnz parameters specify the approximate
storage requirements for this matrix.
<P>
If <A HREF="../Sys/PETSC_DECIDE.html#PETSC_DECIDE">PETSC_DECIDE</A> or  <A HREF="../Sys/PETSC_DETERMINE.html#PETSC_DETERMINE">PETSC_DETERMINE</A> is used for a particular argument on one
processor than it must be used on all processors that share the object for
that argument.
<P>
The user MUST specify either the local or global matrix dimensions
(possibly both).
<P>
The parallel matrix is partitioned across processors such that the
first m0 rows belong to process 0, the next m1 rows belong to
process 1, the next m2 rows belong to process 2 etc.. where
m0,m1,m2,.. are the input parameter 'm'. i.e each processor stores
values corresponding to [m x N] submatrix.
<P>
The columns are logically partitioned with the n0 columns belonging
to 0th partition, the next n1 columns belonging to the next
partition etc.. where n0,n1,n2... are the input parameter 'n'.
<P>
The DIAGONAL portion of the local submatrix on any given processor
is the submatrix corresponding to the rows and columns m,n
corresponding to the given processor. i.e diagonal matrix on
process 0 is [m0 x n0], diagonal matrix on process 1 is [m1 x n1]
etc. The remaining portion of the local submatrix [m x (N-n)]
constitute the OFF-DIAGONAL portion. The example below better
illustrates this concept.
<P>
For a square global matrix we define each processor's diagonal portion
to be its local rows and the corresponding columns (a square submatrix);
each processor's off-diagonal portion encompasses the remainder of the
local matrix (a rectangular submatrix).
<P>
If o_nnz, d_nnz are specified, then o_nz, and d_nz are ignored.
<P>
When calling this routine with a single process communicator, a matrix of
type SEQAIJ is returned.  If a matrix of type MPIAIJ is desired for this
<H3><FONT COLOR="#CC3333">type of communicator, use the construction mechanism</FONT></H3>
<A HREF="../Mat/MatCreate.html#MatCreate">MatCreate</A>(...,&amp;A); <A HREF="../Mat/MatSetType.html#MatSetType">MatSetType</A>(A,<A HREF="../Mat/MATMPIAIJ.html#MATMPIAIJ">MATMPIAIJ</A>); <A HREF="../Mat/MatSetSizes.html#MatSetSizes">MatSetSizes</A>(A, m,n,M,N); <A HREF="../Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation">MatMPIAIJSetPreallocation</A>(A,...);
<P>
By default, this format uses inodes (identical nodes) when possible.
We search for consecutive rows with the same nonzero structure, thereby
reusing matrix information to achieve increased efficiency.
<P>
<H3><FONT COLOR="#CC3333">Options Database Keys</FONT></H3>
<TABLE border="0" cellpadding="0" cellspacing="0">
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>-mat_no_inode  </B></TD><TD>- Do not use inodes
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>-mat_inode_limit &lt;limit&gt; </B></TD><TD>- Sets inode limit (max limit=5)
</TD></TR>
<TR><TD WIDTH=40></TD><TD ALIGN=LEFT VALIGN=TOP><B>-mat_aij_oneindex </B></TD><TD>- Internally use indexing starting at 1
rather than 0.  Note that when calling <A HREF="../Mat/MatSetValues.html#MatSetValues">MatSetValues</A>(),
the user still MUST index entries starting at 0!
</TD></TR></TABLE>
<P>
<P>
<H3><FONT COLOR="#CC3333">Example usage</FONT></H3>
<P>
Consider the following 8x8 matrix with 34 non-zero values, that is
assembled across 3 processors. Lets assume that proc0 owns 3 rows,
proc1 owns 3 rows, proc2 owns 2 rows. This division can be shown
<H3><FONT COLOR="#CC3333">as follows</FONT></H3>
<P>
<PRE>
            1  2  0  |  0  3  0  |  0  4
    Proc0   0  5  6  |  7  0  0  |  8  0
            9  0 10  | 11  0  0  | 12  0
    -------------------------------------
           13  0 14  | 15 16 17  |  0  0
    Proc1   0 18  0  | 19 20 21  |  0  0
            0  0  0  | 22 23  0  | 24  0
    -------------------------------------
    Proc2  25 26 27  |  0  0 28  | 29  0
           30  0  0  | 31 32 33  |  0 34
</PRE>

<P>
<H3><FONT COLOR="#CC3333">This can be represented as a collection of submatrices as</FONT></H3>
<P>
<PRE>
      A B C
      D E F
      G H I
</PRE>

<P>
Where the submatrices A,B,C are owned by proc0, D,E,F are
owned by proc1, G,H,I are owned by proc2.
<P>
The 'm' parameters for proc0,proc1,proc2 are 3,3,2 respectively.
The 'n' parameters for proc0,proc1,proc2 are 3,3,2 respectively.
The 'M','N' parameters are 8,8, and have the same values on all procs.
<P>
The DIAGONAL submatrices corresponding to proc0,proc1,proc2 are
submatrices [A], [E], [I] respectively. The OFF-DIAGONAL submatrices
corresponding to proc0,proc1,proc2 are [BC], [DF], [GH] respectively.
Internally, each processor stores the DIAGONAL part, and the OFF-DIAGONAL
part as SeqAIJ matrices. for eg: proc1 will store [E] as a SeqAIJ
matrix, ans [DF] as another SeqAIJ matrix.
<P>
When d_nz, o_nz parameters are specified, d_nz storage elements are
allocated for every row of the local diagonal submatrix, and o_nz
storage locations are allocated for every row of the OFF-DIAGONAL submat.
One way to choose d_nz and o_nz is to use the max nonzerors per local
rows for each of the local DIAGONAL, and the OFF-DIAGONAL submatrices.
<H3><FONT COLOR="#CC3333">In this case, the values of d_nz,o_nz are</FONT></H3>
<PRE>
     proc0 : dnz = 2, o_nz = 2
     proc1 : dnz = 3, o_nz = 2
     proc2 : dnz = 1, o_nz = 4
</PRE>

We are allocating m*(d_nz+o_nz) storage locations for every proc. This
translates to 3*(2+2)=12 for proc0, 3*(3+2)=15 for proc1, 2*(1+4)=10
for proc3. i.e we are using 12+15+10=37 storage locations to store
34 values.
<P>
When d_nnz, o_nnz parameters are specified, the storage is specified
for every row, coresponding to both DIAGONAL and OFF-DIAGONAL submatrices.
<H3><FONT COLOR="#CC3333">In the above case the values for d_nnz,o_nnz are</FONT></H3>
<PRE>
     proc0: d_nnz = [2,2,2] and o_nnz = [2,2,2]
     proc1: d_nnz = [3,3,2] and o_nnz = [2,1,1]
     proc2: d_nnz = [1,1]   and o_nnz = [4,4]
</PRE>

Here the space allocated is sum of all the above values i.e 34, and
hence pre-allocation is perfect.
<P>

<P>
<H3><FONT COLOR="#CC3333">Keywords</FONT></H3>
 matrix, aij, compressed row, sparse, parallel
<BR>
<P>
<H3><FONT COLOR="#CC3333">See Also</FONT></H3>
 <A HREF="../Mat/MatCreate.html#MatCreate">MatCreate</A>(), <A HREF="../Mat/MatCreateSeqAIJ.html#MatCreateSeqAIJ">MatCreateSeqAIJ</A>(), <A HREF="../Mat/MatSetValues.html#MatSetValues">MatSetValues</A>(), <A HREF="../Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation">MatMPIAIJSetPreallocation</A>(), <A HREF="../Mat/MatMPIAIJSetPreallocationCSR.html#MatMPIAIJSetPreallocationCSR">MatMPIAIJSetPreallocationCSR</A>(),
<BR>MPIAIJ, <A HREF="../Mat/MatCreateMPIAIJWithArrays.html#MatCreateMPIAIJWithArrays">MatCreateMPIAIJWithArrays</A>()
<P><B><P><B><FONT COLOR="#CC3333">Level:</FONT></B>intermediate
<BR><FONT COLOR="#CC3333">Location:</FONT></B><A HREF="../../../src/mat/impls/aij/mpi/mpiaij.c.html#MatCreateAIJ">src/mat/impls/aij/mpi/mpiaij.c</A>
<BR><A HREF="./index.html">Index of all Mat routines</A>
<BR><A HREF="../../index.html">Table of Contents for all manual pages</A>
<BR><A HREF="../singleindex.html">Index of all manual pages</A>
<P><H3><FONT COLOR="#CC3333">Examples</FONT></H3>
<A HREF="../../../src/ksp/ksp/examples/tutorials/ex54.c.html">src/ksp/ksp/examples/tutorials/ex54.c.html</A><BR>
<A HREF="../../../src/ksp/ksp/examples/tutorials/ex14f.F.html">src/ksp/ksp/examples/tutorials/ex14f.F.html</A><BR>
<A HREF="../../../src/snes/examples/tutorials/ex5s.c.html">src/snes/examples/tutorials/ex5s.c.html</A><BR>
<A HREF="../../../src/tao/bound/examples/tutorials/plate2.c.html">src/tao/bound/examples/tutorials/plate2.c.html</A><BR>
<A HREF="../../../src/tao/bound/examples/tutorials/plate2f.F.html">src/tao/bound/examples/tutorials/plate2f.F.html</A><BR>
</BODY></HTML>