1 #include <libmesh/petsc_matrix.h>
3 #ifdef LIBMESH_HAVE_PETSC
5 #include <libmesh/parallel.h>
6 #include <libmesh/dense_matrix.h>
12 #ifdef LIBMESH_HAVE_CXX11_THREAD
24 CPPUNIT_TEST(testGetAndSet);
26 CPPUNIT_TEST_SUITE_END();
32 _matrix = libmesh_make_unique<PetscMatrix<Number>>(*_comm);
35 _local_size = root_block_size + static_cast<numeric_index_type>(_comm->rank());
42 _global_size += block_size;
43 _i.push_back(_global_size);
46 _matrix->init(_global_size,
58 std::vector<numeric_index_type> rows(_local_size);
59 std::vector<numeric_index_type> cols(_local_size);
63 for (; count < _local_size; ++count, ++index)
68 local(count, j) = (count + 1) * (j + 1) * (_comm->rank() + 1);
71 _matrix->add_matrix(local, rows, cols);
74 index = _i[_comm->rank()], count = 0;
76 auto functor = [
this]()
78 std::vector<numeric_index_type> cols_to_get;
79 std::vector<Number> values;
81 for (; local_count < _local_size; ++local_count, ++local_index)
83 _matrix->get_row(local_index, cols_to_get, values);
87 (local_count + 1) * (j + 1) * (_comm->rank() + 1),
89 CPPUNIT_ASSERT_EQUAL(cols_to_get[local_count], local_index);
94 #ifdef LIBMESH_HAVE_CXX11_THREAD
95 auto num_threads = std::min(
unsigned(2),
97 std::thread::hardware_concurrency(),
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();});
114 std::vector<numeric_index_type>
_i;