libMesh
Public Member Functions | Private Attributes | List of all members
PetscMatrixTest Class Reference
Inheritance diagram for PetscMatrixTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (PetscMatrixTest)
 
 CPPUNIT_TEST (testGetAndSet)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testGetAndSet ()
 

Private Attributes

Parallel::Communicator * _comm
 
std::unique_ptr< PetscMatrix< Number > > _matrix
 
numeric_index_type _local_size
 
numeric_index_type _global_size
 
std::vector< numeric_index_type_i
 
const Real _tolerance = TOLERANCE * TOLERANCE
 

Detailed Description

Definition at line 19 of file petsc_matrix_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

PetscMatrixTest::CPPUNIT_TEST ( testGetAndSet  )

◆ CPPUNIT_TEST_SUITE()

PetscMatrixTest::CPPUNIT_TEST_SUITE ( PetscMatrixTest  )

◆ CPPUNIT_TEST_SUITE_END()

PetscMatrixTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void PetscMatrixTest::setUp ( )
inline

Definition at line 29 of file petsc_matrix_test.C.

30  {
32  _matrix = libmesh_make_unique<PetscMatrix<Number>>(*_comm);
33 
34  numeric_index_type root_block_size = 2;
35  _local_size = root_block_size + static_cast<numeric_index_type>(_comm->rank());
36  _global_size = 0;
37  _i.push_back(0);
38 
39  for (processor_id_type p = 0; p < _comm->size(); ++p)
40  {
41  numeric_index_type block_size = root_block_size + static_cast<numeric_index_type>(p);
42  _global_size += block_size;
43  _i.push_back(_global_size);
44  }
45 
46  _matrix->init(_global_size,
50  /*nnz=*/_local_size,
51  /*noz=*/0);
52  }

References TestCommWorld.

◆ tearDown()

void PetscMatrixTest::tearDown ( )
inline

Definition at line 54 of file petsc_matrix_test.C.

54 {}

◆ testGetAndSet()

void PetscMatrixTest::testGetAndSet ( )
inline

Definition at line 56 of file petsc_matrix_test.C.

57  {
58  std::vector<numeric_index_type> rows(_local_size);
59  std::vector<numeric_index_type> cols(_local_size);
61 
62  numeric_index_type index = _i[_comm->rank()], count = 0;
63  for (; count < _local_size; ++count, ++index)
64  {
65  rows[count] = index;
66  cols[count] = index;
67  for (numeric_index_type j = 0; j < _local_size; ++j)
68  local(count, j) = (count + 1) * (j + 1) * (_comm->rank() + 1);
69  }
70 
71  _matrix->add_matrix(local, rows, cols);
72  _matrix->close();
73 
74  index = _i[_comm->rank()], count = 0;
75 
76  auto functor = [this]()
77  {
78  std::vector<numeric_index_type> cols_to_get;
79  std::vector<Number> values;
80  numeric_index_type local_index = _i[_comm->rank()], local_count = 0;
81  for (; local_count < _local_size; ++local_count, ++local_index)
82  {
83  _matrix->get_row(local_index, cols_to_get, values);
84  for (numeric_index_type j = 0; j < _local_size; ++j)
85  {
86  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(values[j]),
87  (local_count + 1) * (j + 1) * (_comm->rank() + 1),
88  _tolerance);
89  CPPUNIT_ASSERT_EQUAL(cols_to_get[local_count], local_index);
90  }
91  }
92  };
93 
94 #ifdef LIBMESH_HAVE_CXX11_THREAD
95  auto num_threads = std::min(unsigned(2),
96  std::max(
97  std::thread::hardware_concurrency(),
98  unsigned(1)));
99  std::vector<std::thread> threads(num_threads);
100  for (unsigned int thread = 0; thread < num_threads; ++thread)
101  threads[thread] = std::thread(functor);
102  std::for_each(threads.begin(), threads.end(),
103  [](std::thread & x){x.join();});
104 #else
105  functor();
106 #endif
107  }

References libMesh::libmesh_real().

Member Data Documentation

◆ _comm

Parallel::Communicator* PetscMatrixTest::_comm
private

Definition at line 111 of file petsc_matrix_test.C.

◆ _global_size

numeric_index_type PetscMatrixTest::_global_size
private

Definition at line 113 of file petsc_matrix_test.C.

◆ _i

std::vector<numeric_index_type> PetscMatrixTest::_i
private

Definition at line 114 of file petsc_matrix_test.C.

◆ _local_size

numeric_index_type PetscMatrixTest::_local_size
private

Definition at line 113 of file petsc_matrix_test.C.

◆ _matrix

std::unique_ptr<PetscMatrix<Number> > PetscMatrixTest::_matrix
private

Definition at line 112 of file petsc_matrix_test.C.

◆ _tolerance

const Real PetscMatrixTest::_tolerance = TOLERANCE * TOLERANCE
private

Definition at line 115 of file petsc_matrix_test.C.


The documentation for this class was generated from the following file:
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::DenseMatrix< Number >
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
PetscMatrixTest::_global_size
numeric_index_type _global_size
Definition: petsc_matrix_test.C:113
libMesh::numeric_index_type
dof_id_type numeric_index_type
Definition: id_types.h:99
PetscMatrixTest::_tolerance
const Real _tolerance
Definition: petsc_matrix_test.C:115
PetscMatrixTest::_matrix
std::unique_ptr< PetscMatrix< Number > > _matrix
Definition: petsc_matrix_test.C:112
PetscMatrixTest::_comm
Parallel::Communicator * _comm
Definition: petsc_matrix_test.C:111
PetscMatrixTest::_local_size
numeric_index_type _local_size
Definition: petsc_matrix_test.C:113
PetscMatrixTest::_i
std::vector< numeric_index_type > _i
Definition: petsc_matrix_test.C:114