cartesian_topology_init_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright Alain Miniussi 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Alain Miniussi
  6. #include <vector>
  7. #include <list>
  8. #include <iostream>
  9. #include <sstream>
  10. #include <iterator>
  11. #include <algorithm>
  12. #include <functional>
  13. #include <boost/mpi/communicator.hpp>
  14. #include <boost/mpi/collectives.hpp>
  15. #include <boost/array.hpp>
  16. #include <boost/mpi/environment.hpp>
  17. #include <boost/mpi/cartesian_communicator.hpp>
  18. #define BOOST_TEST_MODULE mpi_cartesian_topology_init
  19. #include <boost/test/included/unit_test.hpp>
  20. namespace mpi = boost::mpi;
  21. BOOST_AUTO_TEST_CASE(cartesian_dimension_init)
  22. {
  23. // Curly brace initialization syntax not supported on (very) old gnu
  24. // This typedef keeps things shorter
  25. typedef mpi::cartesian_dimension cd;
  26. {
  27. // Check the basic ctor
  28. mpi::cartesian_dimension def;
  29. mpi::cartesian_topology t1(10);
  30. BOOST_CHECK(t1.stl() == std::vector<mpi::cartesian_dimension>(10, def));
  31. }
  32. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  33. {
  34. // Intializer list ctor vs range based
  35. int dims[] = {2,3,4};
  36. bool per[] = {true, false, true};
  37. mpi::cartesian_topology t1(dims, per);
  38. mpi::cartesian_topology t2({{2,true},{3, false},{4, true}});
  39. BOOST_CHECK(t1.size() == 3);
  40. BOOST_CHECK(t1 == t2);
  41. }
  42. #endif
  43. // Container based ctor only available as a replacement for initializer list ctor
  44. {
  45. // seq ctor vs C array ctor
  46. mpi::cartesian_dimension d[] = {cd(2,true),cd(3, false),cd(4, true)};
  47. std::list<mpi::cartesian_dimension> seq;
  48. std::copy(d, d+3, std::back_inserter(seq));
  49. mpi::cartesian_topology t1(seq);
  50. mpi::cartesian_topology t2(d);
  51. BOOST_CHECK(t1 == t2);
  52. }
  53. {
  54. // Check range based with array based ctor.
  55. boost::array<mpi::cartesian_dimension, 3> d = {{cd(2,true),cd(3, false),cd(4, true)}};
  56. int dims[] = {2,3,4};
  57. bool per[] = {true, false, true};
  58. mpi::cartesian_topology t1(dims, per);
  59. mpi::cartesian_topology t2(d);
  60. BOOST_CHECK(t1.size() == 3);
  61. BOOST_CHECK(t1 == t2);
  62. }
  63. {
  64. // Iterator based ctor vs C array based ctor
  65. mpi::cartesian_dimension d[] = {cd(2,true),cd(3, false),cd(4, true)};
  66. std::vector<mpi::cartesian_dimension> vdims(d, d+3);
  67. mpi::cartesian_topology t1(vdims);
  68. mpi::cartesian_topology t2(d);
  69. BOOST_CHECK(t1.size() == 3);
  70. BOOST_CHECK(t1 == t2);
  71. BOOST_CHECK(!(t1 != t2));
  72. t1[1].periodic = true;
  73. BOOST_CHECK(t1 != t2);
  74. t1[2].periodic = false;
  75. t1[2].size = 0;
  76. vdims.push_back(mpi::cartesian_dimension(3, false));
  77. mpi::cartesian_topology t3(vdims);
  78. BOOST_CHECK(t1 != t3);
  79. }
  80. }