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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ParallelSortTest)
 
 CPPUNIT_TEST (testSort)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testSort ()
 

Detailed Description

Definition at line 12 of file parallel_sort_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

ParallelSortTest::CPPUNIT_TEST ( testSort  )

◆ CPPUNIT_TEST_SUITE_END()

ParallelSortTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ParallelSortTest::LIBMESH_CPPUNIT_TEST_SUITE ( ParallelSortTest  )

◆ setUp()

void ParallelSortTest::setUp ( )
inline

Definition at line 21 of file parallel_sort_test.C.

22  {}

◆ tearDown()

void ParallelSortTest::tearDown ( )
inline

Definition at line 24 of file parallel_sort_test.C.

25  {}

◆ testSort()

void ParallelSortTest::testSort ( )
inline

Definition at line 27 of file parallel_sort_test.C.

References libMesh::Parallel::Sort< KeyType, IdxType >::bin(), libMesh::Parallel::Utils::is_sorted(), TIMPI::Communicator::max(), TIMPI::Communicator::rank(), TIMPI::Communicator::size(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), TIMPI::Communicator::sum(), and TestCommWorld.

28  {
29  LOG_UNIT_TEST;
30 
31  const int size = TestCommWorld->size(),
32  rank = TestCommWorld->rank();
33  const int n_vals = size - rank;
34  std::vector<int> vals(n_vals);
35 
36  // Put all the numbers up to a triangular number into our data,
37  // scrambled and backwards
38  int val = rank+1, stride = size;
39  for (int i=0; i != n_vals; ++i)
40  {
41  vals[n_vals-i-1] = val;
42  val += stride;
43  stride -= 1;
44  }
45 
46  Parallel::Sort<int> sorter (*TestCommWorld, vals);
47 
48  sorter.sort();
49 
50  const std::vector<int> & my_bin = sorter.bin();
51 
52  // Our bins should be roughly the same size, but with that
53  // nbins*50 stuff in Parallel::BinSorter it's hard to predict the
54  // outcome exactly. We'll just make sure they're sorted and
55  // they've got everything.
56 
57  int total_size = cast_int<int>(my_bin.size());
58  TestCommWorld->sum(total_size);
59 
60  CPPUNIT_ASSERT_EQUAL(total_size, size*(size+1)/2);
61 
62  CPPUNIT_ASSERT(std::is_sorted(my_bin.begin(), my_bin.end()));
63 
64  int rank_with_i = -1;
65  for (int i=1; i <= total_size; ++i)
66  {
67  int count_i = std::count(my_bin.begin(), my_bin.end(), i);
68  CPPUNIT_ASSERT(count_i < 2);
69 
70  if (count_i)
71  {
72  CPPUNIT_ASSERT(rank_with_i <= rank);
73  rank_with_i = rank;
74  }
75  TestCommWorld->max(rank_with_i);
76 
77  TestCommWorld->sum(count_i);
78  CPPUNIT_ASSERT_EQUAL(count_i, 1);
79  }
80  }
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void sum(T &r) const
processor_id_type rank() const
processor_id_type size() const
bool is_sorted(const std::vector< KeyType > &v)
The parallel sorting method is templated on the type of data which is to be sorted.
Definition: parallel_sort.h:55
void max(const T &r, T &o, Request &req) const

The documentation for this class was generated from the following file: