[Trilinos-Users] Epetra_CrsMatrix parallel insert! (Sunghwan Choi)

Hoemmen, Mark mhoemme at sandia.gov
Fri Mar 22 13:48:02 MDT 2013


On Mar 22, 2013, at 12:00 PM, <trilinos-users-request at software.sandia.gov>
 wrote:
> Message: 1
> Date: Fri, 22 Mar 2013 03:04:19 +0900
> From: "Sunghwan Choi" <sunghwanchoi91 at gmail.com>
> Subject: [Trilinos-Users] Epetra_CrsMatrix parallel insert!
> To: trilinos-users at software.sandia.gov
> Message-ID: <29a201ce265e$861334b0$92399e10$@gmail.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi, I am serial-version of trilinos user;
> 
> I have tried to make my code parallelized for a while; however, it wasn't
> that easy to me;;;
> 
> First of all, filling out the matrix is not easy. I made the most typical
> way to fill out the matrix.
> 
> for (int i=0; i<100;i++){
> 
>           matrix.InsertGlobalValue(10, values,indices);
> 
> }
> 
> matrix.FillComplete();
> 
> My question is that 
> 
> 1)     Here, How can I make the above code parallelized? (The most general
> case)

One way to make matrix fill parallel is for each MPI process to insert into the rows that it owns (that is, rows that are in the row Map, the Map which you used to construct the matrix).  If you want to insert into rows not owned by the calling process, as you might for example when doing the finite element method, you should use Epetra_FECrsMatrix.

> 2)     After call FillComplete(), can I still acess the values through
> global index? 

Yes.  You can even modify the values, as you might for example if solving a nonlinear system of equations.

> 3)     What is the best way to filling crsmatrix when I don't know whether
> the value is filled or not ?

You could ask the matrix if there is a stored value at that i,j location.  

Most users have some way to know the structure of their matrix well enough that they don't need to ask the matrix again.  For example, if you are doing the finite-element method with an unstructured mesh, the mesh's numbering of vertices and connectivity tell you what entries of the matrix are populated.

> 4)     If I want to construct the crsmatrix whose position of non-zero
> values is exactly same to the already constructed matrix,(but the values are
> different) then is there any special method to filling the new matrix
> easily.

In this case, you first should fill an Epetra_CrsGraph, and use the resulting graph to construct the matrices.  (Use the Epetra_CrsMatrix constructor that takes a const Epetra_CrsGraph&.)  We refer to this case as "constructing the matrix with a const graph."  This will make filling the matrices more efficient.  Multiple matrices will be able to share the same graph, which will save both memory and time.

If you create a matrix with a const graph, you may not use InsertGlobalValues to set or change the matrix's values.  Rather, you must use the Replace* or SumInto* methods.  You will also not be able to change the structure of the matrices after their construction, since their structure will depend on that of the graph (which is "const").  You will, however, be able to change their values.

mfh


More information about the Trilinos-Users mailing list