8 #ifndef OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_PETSC_HPP_ 
    9 #define OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_PETSC_HPP_ 
   11 #include "util/petsc_util.hpp" 
   12 #include "Vector/map_vector.hpp" 
   13 #include <boost/mpl/int.hpp> 
   84     :row_(0),col_(0),val_(0)
 
   95 template<
typename T, 
typename id_t>
 
  122     bool m_created = 
false;
 
  158         while (i < trpl.size())
 
  160             PetscInt row = trpl.get(i).row();
 
  162             while(i < trpl.size() && row == trpl.get(i).row())
 
  164                 if ((
size_t)trpl.get(i).col() >= start_row && (size_t)trpl.get(i).col() < start_row + l_row)
 
  165                     d_nnz.get(row - start_row)++;
 
  167                     o_nnz.get(row - start_row)++;
 
  172         PETSC_SAFE_CALL(MatMPIAIJSetPreallocation(mat,0,static_cast<const PetscInt*>(d_nnz.getPointer()),0,
 
  173                                                         static_cast<const PetscInt*>(o_nnz.getPointer())));
 
  179         while (i < trpl.size())
 
  184             PetscInt row = trpl.get(i).row();
 
  186             while(i < trpl.size() && row == trpl.get(i).row())
 
  188                 vals.add(trpl.get(i).value());
 
  189                 cols.add(trpl.get(i).col());
 
  192             PETSC_SAFE_CALL(MatSetValues(mat,1,&row,cols.size(),
static_cast<const PetscInt*
>(cols.getPointer()),
 
  193                                                                 static_cast<const PetscScalar *>(vals.getPointer()),
 
  197         PETSC_SAFE_CALL(MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY));
 
  198         PETSC_SAFE_CALL(MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY));
 
  214     :g_row(N1),g_col(N2),l_row(n_row_local),l_col(n_row_local)
 
  216         PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat));
 
  217         PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ));
 
  218         PETSC_SAFE_CALL(MatSetSizes(mat,n_row_local,n_row_local,N1,N2));
 
  220         Vcluster & v_cl = create_vcluster();
 
  230             start_row += vn_row_local.get(i);
 
  237     :g_row(0),g_col(0),l_row(0l),l_col(0),start_row(0)
 
  239         PETSC_SAFE_CALL(MatCreate(PETSC_COMM_WORLD,&mat));
 
  240         PETSC_SAFE_CALL(MatSetType(mat,MATMPIAIJ));
 
  246         if (is_openfpm_init() == 
true)
 
  247         {PETSC_SAFE_CALL(MatDestroy(&mat));}
 
  271         if (m_created == 
false)
 
  284         if (m_created == 
false)
 
  298     void resize(
size_t row, 
size_t col, 
size_t l_row, 
size_t l_col)
 
  306         PETSC_SAFE_CALL(MatSetSizes(mat,l_row,l_col,g_row,g_col));
 
  308         Vcluster & v_cl = create_vcluster();
 
  318             start_row += vn_row_local.get(i);
 
  332         MatGetValues(mat,1,&i,1,&j,&v);
 
  347         for (
size_t i = 0 ; i < trpl.size() ; i++)
 
  349             if (r == (
size_t)trpl.get(i).row() && c == (size_t)trpl.get(i).col())
 
  350                 return trpl.get(i).value();
 
size_t g_row
Number of matrix row (global) 
 
boost::mpl::int_< PETSC_BASE > triplet_impl
Triplet implementation id. 
 
size_t getProcessUnitID()
Get the process unit id. 
 
void execute()
Execute all the requests. 
 
PetscScalar val_
Value of the Matrix. 
 
T getValue(size_t r, size_t c)
Get the value from triplet. 
 
It store the non zero elements of the matrix. 
 
void fill_petsc()
Fill the petsc Matrix. 
 
Mat & getMat()
Get the Petsc Matrix object. 
 
SparseMatrix()
Create an empty Matrix. 
 
PetscInt & row()
Return the row of the triplet. 
 
openfpm::vector< triplet_type > trpl
Triplets of the matrix. 
 
const Mat & getMat() const 
Get the Patsc Matrix object. 
 
Implementation of VCluster class. 
 
triplet< T, PETSC_BASE > triplet_type
Triplet type. 
 
PetscInt & col()
Return the colum of the triplet. 
 
size_t start_row
starting row for this processor 
 
Sparse Matrix implementation. 
 
T operator()(id_t i, id_t j)
Get the row i and the colum j of the Matrix. 
 
triplet(long int i, long int j, T val)
Constructor from row, colum and value. 
 
void resize(size_t row, size_t col, size_t l_row, size_t l_col)
Resize the Sparse Matrix. 
 
SparseMatrix(size_t N1, size_t N2, size_t n_row_local)
Create an empty Matrix. 
 
openfpm::vector< triplet_type > & getMatrixTriplets()
Get the Matrix triplets buffer. 
 
PetscInt col_
Colum of the sparse matrix. 
 
openfpm::vector< PetscInt > d_nnz
PETSC d_nnz. 
 
size_t l_row
Number of matrix row (local) 
 
openfpm::vector< PetscInt > o_nnz
PETSC o_nnz. 
 
openfpm::vector< PetscInt > cols
temporary list of colums 
 
It store one non-zero element in the sparse matrix. 
 
PetscInt row_
Row of the sparse matrix. 
 
PetscScalar & value()
Return the value of the triplet. 
 
size_t l_col
Number of matrix colums (local) 
 
size_t g_col
Number of matrix colums (global) 
 
Implementation of 1-D std::vector like structure. 
 
bool allGather(T &send, openfpm::vector< T, Mem, gr > &v)
Gather the data from all processors. 
 
openfpm::vector< PetscScalar > vals
temporary list of values