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

Public Member Functions

 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()

ParallelSortTest::CPPUNIT_TEST_SUITE ( ParallelSortTest  )

◆ CPPUNIT_TEST_SUITE_END()

ParallelSortTest::CPPUNIT_TEST_SUITE_END ( )

◆ 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.

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

References libMesh::Parallel::Sort< KeyType, IdxType >::bin(), libMesh::Parallel::Utils::is_sorted(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), and TestCommWorld.


The documentation for this class was generated from the following file:
libMesh::Parallel::Sort
The parallel sorting method is templated on the type of data which is to be sorted.
Definition: parallel_sort.h:55
libMesh::Parallel::Utils::is_sorted
bool is_sorted(const std::vector< KeyType > &v)
Definition: parallel_conversion_utils.h:52
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111