[Trilinos-Users] Problem inserting non-local data in Epetra_FECrsMatrix

Eric Marttila eric.marttila at thermoanalytics.com
Wed Feb 15 08:19:35 MST 2012

Dear all,

I've been using Epetra_CrsMatrix to store a linear system, but recently 
encountered a situation where I need to fill the entire matrix from the master 
process.  From reading the Epetra documentation I believe I need to switch to 
a EpetraFECrs_Matrix to do this.

I changed my code to use the EpetraFECrs_Matrix, but my call to 
InsertGlobalValues() fails on the first row of the matrix that is non-local to 
the master process.

I've attached a small section of code that reproduces the behavior.  It runs 
fine with 1 process, but fails when inserting row index 2 when run with 2 

I would appreciate any thoughts on what I'm missing with my usage of 


p.s. I'm running Trilinos 10.8.5 on linux x86_64, using mpich2.

Eric A. Marttila
ThermoAnalytics, Inc.
23440 Airpark Blvd.
Calumet, MI 49913

email: Eric.Marttila at ThermoAnalytics.com
phone: 810-636-2443
fax:   906-482-9755
web: http://www.thermoanalytics.com
-------------- next part --------------
#include "mpi.h"
#include "Epetra_FECrsMatrix.h"
#include "Epetra_Map.h"
#include "Epetra_MpiComm.h"

int main(int argCount, char **argValue)
  int ierr;
  Epetra_MpiComm Comm(MPI_COMM_WORLD);
  const int rank = Comm.MyPID();

  // Construct a Map 
  const int nGlobalElements = 4;
  Epetra_Map Map(nGlobalElements, 0, Comm);

  // Create a matrix
  Epetra_FECrsMatrix A(Copy, Map, 1);

  // Fill matrix on the master process
  if (rank == 0) {
    double values[1];
    int    indices[1];
    const int numEntries = 1;

    for (int globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
      indices[0] = globalRowIdx;
      values[0] = 3.2;

      cerr << "About to insert row " << globalRowIdx << "\n";
      ierr = A.InsertGlobalValues(globalRowIdx, numEntries,
				  &values[0], &indices[0]);

  // Finish up
  ierr = A.GlobalAssemble();

  // Print the matrix


  return 0;

More information about the Trilinos-Users mailing list