@@ -172,11 +172,11 @@ void PetscMatrix<T>::init (const numeric_index_type m_in,
172
172
173
173
ierr = MatSetType (_mat , MATBAIJ ); // Automatically chooses seqbaij or mpibaij
174
174
LIBMESH_CHKERR (ierr );
175
- ierr = MatSeqBAIJSetPreallocation (_mat , blocksize , n_nz /blocksize , PETSC_NULL );
175
+ ierr = MatSeqBAIJSetPreallocation (_mat , blocksize , n_nz /blocksize , NULL );
176
176
LIBMESH_CHKERR (ierr );
177
177
ierr = MatMPIBAIJSetPreallocation (_mat , blocksize ,
178
- n_nz /blocksize , PETSC_NULL ,
179
- n_oz /blocksize , PETSC_NULL );
178
+ n_nz /blocksize , NULL ,
179
+ n_oz /blocksize , NULL );
180
180
LIBMESH_CHKERR (ierr );
181
181
}
182
182
else
@@ -186,17 +186,17 @@ void PetscMatrix<T>::init (const numeric_index_type m_in,
186
186
case AIJ :
187
187
ierr = MatSetType (_mat , MATAIJ ); // Automatically chooses seqaij or mpiaij
188
188
LIBMESH_CHKERR (ierr );
189
- ierr = MatSeqAIJSetPreallocation (_mat , n_nz , PETSC_NULL );
189
+ ierr = MatSeqAIJSetPreallocation (_mat , n_nz , NULL );
190
190
LIBMESH_CHKERR (ierr );
191
- ierr = MatMPIAIJSetPreallocation (_mat , n_nz , PETSC_NULL , n_oz , PETSC_NULL );
191
+ ierr = MatMPIAIJSetPreallocation (_mat , n_nz , NULL , n_oz , NULL );
192
192
LIBMESH_CHKERR (ierr );
193
193
break ;
194
194
195
195
case HYPRE :
196
196
#if !PETSC_VERSION_LESS_THAN (3 ,9 ,4 ) && LIBMESH_HAVE_PETSC_HYPRE
197
197
ierr = MatSetType (_mat , MATHYPRE );
198
198
LIBMESH_CHKERR (ierr );
199
- ierr = MatHYPRESetPreallocation (_mat , n_nz , PETSC_NULL , n_oz , PETSC_NULL );
199
+ ierr = MatHYPRESetPreallocation (_mat , n_nz , NULL , n_oz , NULL );
200
200
LIBMESH_CHKERR (ierr );
201
201
#else
202
202
libmesh_error_msg ("PETSc 3.9.4 or higher with hypre is required for MatHypre" );
@@ -470,6 +470,20 @@ void PetscMatrix<T>::update_preallocation_and_zero ()
470
470
libmesh_not_implemented ();
471
471
}
472
472
473
+ template < typename T >
474
+ void PetscMatrix < T > ::reset_preallocation ()
475
+ {
476
+ #if !PETSC_VERSION_LESS_THAN (3 ,8 ,0 )
477
+ libmesh_assert (this -> initialized ());
478
+
479
+ auto ierr = MatResetPreallocation (_mat );
480
+ LIBMESH_CHKERR (ierr );
481
+ #else
482
+ libmesh_warning ("Your version of PETSc doesn't support resetting of "
483
+ "preallocation, so we will use your most recent sparsity "
484
+ "pattern. This may result in a degradation of performance\n" );
485
+ #endif
486
+ }
473
487
474
488
template < typename T >
475
489
void PetscMatrix < T > ::zero ()
@@ -506,7 +520,7 @@ void PetscMatrix<T>::zero_rows (std::vector<numeric_index_type> & rows, T diag_v
506
520
ierr = MatZeroRows (_mat , rows .size (),
507
521
numeric_petsc_cast (rows .data ()), diag_value );
508
522
else
509
- ierr = MatZeroRows (_mat , 0 , PETSC_NULL , diag_value );
523
+ ierr = MatZeroRows (_mat , 0 , NULL , diag_value );
510
524
#else
511
525
// As of petsc-dev at the time of 3.1.0, MatZeroRows now takes two additional
512
526
// optional arguments. The optional arguments (x,b) can be used to specify the
@@ -515,10 +529,10 @@ void PetscMatrix<T>::zero_rows (std::vector<numeric_index_type> & rows, T diag_v
515
529
if (!rows .empty ())
516
530
ierr = MatZeroRows (_mat , cast_int < PetscInt > (rows .size ()),
517
531
numeric_petsc_cast (rows .data ()), diag_value ,
518
- PETSC_NULL , PETSC_NULL );
532
+ NULL , NULL );
519
533
else
520
- ierr = MatZeroRows (_mat , 0 , PETSC_NULL , diag_value , PETSC_NULL ,
521
- PETSC_NULL );
534
+ ierr = MatZeroRows (_mat , 0 , NULL , diag_value , NULL ,
535
+ NULL );
522
536
#endif
523
537
524
538
LIBMESH_CHKERR (ierr );
@@ -931,7 +945,7 @@ void PetscMatrix<T>::get_transpose (SparseMatrix<T> & dest) const
931
945
PetscErrorCode ierr ;
932
946
#if PETSC_VERSION_LESS_THAN (3 ,0 ,0 )
933
947
if (& petsc_dest == this )
934
- ierr = MatTranspose (_mat ,PETSC_NULL );
948
+ ierr = MatTranspose (_mat ,NULL );
935
949
else
936
950
ierr = MatTranspose (_mat ,& petsc_dest ._mat );
937
951
LIBMESH_CHKERR (ierr );
@@ -1002,7 +1016,18 @@ numeric_index_type PetscMatrix<T>::m () const
1002
1016
return static_cast < numeric_index_type > (petsc_m );
1003
1017
}
1004
1018
1019
+ template < typename T >
1020
+ numeric_index_type PetscMatrix < T > ::local_m () const
1021
+ {
1022
+ libmesh_assert (this -> initialized ());
1023
+
1024
+ PetscInt m = 0 ;
1005
1025
1026
+ auto ierr = MatGetLocalSize (_mat , & m , NULL );
1027
+ LIBMESH_CHKERR (ierr );
1028
+
1029
+ return static_cast < numeric_index_type > (m );
1030
+ }
1006
1031
1007
1032
template < typename T >
1008
1033
numeric_index_type PetscMatrix < T > ::n () const
@@ -1018,7 +1043,33 @@ numeric_index_type PetscMatrix<T>::n () const
1018
1043
return static_cast < numeric_index_type > (petsc_n );
1019
1044
}
1020
1045
1046
+ template < typename T >
1047
+ numeric_index_type PetscMatrix < T > ::local_n () const
1048
+ {
1049
+ libmesh_assert (this -> initialized ());
1050
+
1051
+ PetscInt n = 0 ;
1052
+
1053
+ auto ierr = MatGetLocalSize (_mat , NULL , & n );
1054
+ LIBMESH_CHKERR (ierr );
1055
+
1056
+ return static_cast < numeric_index_type > (n );
1057
+ }
1021
1058
1059
+ template < typename T >
1060
+ void PetscMatrix < T > ::get_local_size (numeric_index_type & m ,
1061
+ numeric_index_type & n ) const
1062
+ {
1063
+ libmesh_assert (this -> initialized ());
1064
+
1065
+ PetscInt petsc_m = 0 , petsc_n = 0 ;
1066
+
1067
+ auto ierr = MatGetLocalSize (_mat , & petsc_m , & petsc_n );
1068
+ LIBMESH_CHKERR (ierr );
1069
+
1070
+ m = static_cast < numeric_index_type > (petsc_m );
1071
+ n = static_cast < numeric_index_type > (petsc_n );
1072
+ }
1022
1073
1023
1074
template < typename T >
1024
1075
numeric_index_type PetscMatrix < T > ::row_start () const
0 commit comments