File: test_cartesian_topology_init.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (88 lines) | stat: -rw-r--r-- 2,798 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//          Copyright Alain Miniussi 2014.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

// Authors: Alain Miniussi

#include <vector>
#include <list>
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <functional>

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/collectives.hpp>
#include <boost/array.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/cartesian_communicator.hpp>

#include "mpi_test_utils.hpp"

namespace mpi = boost::mpi;

int
main() {
  int failed = 0;
  // Curly brace initialization syntax not supported on (very) old gnu
  // This typedef keeps things shorter
  typedef mpi::cartesian_dimension cd;
  
  {
    // Check the basic ctor
    mpi::cartesian_dimension def;
    mpi::cartesian_topology t1(10);
    BOOST_MPI_CHECK(t1.stl() == std::vector<mpi::cartesian_dimension>(10, def), failed);
  }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  {
    // Intializer list ctor vs range based
    int dims[] = {2,3,4};
    bool per[] = {true, false, true};
    mpi::cartesian_topology t1(dims, per);
    mpi::cartesian_topology t2({{2,true},{3, false},{4, true}});
    BOOST_MPI_CHECK(t1.size() == 3, failed);
    BOOST_MPI_CHECK(t1 == t2, failed);
  }
#endif
  // Container based ctor only available as a replacement for initializer list ctor
  {
    // seq ctor vs C array ctor
    mpi::cartesian_dimension d[] = {cd(2,true),cd(3, false),cd(4, true)};
    std::list<mpi::cartesian_dimension> seq;
    std::copy(d, d+3, std::back_inserter(seq));
    mpi::cartesian_topology t1(seq);
    mpi::cartesian_topology t2(d);
    BOOST_MPI_CHECK(t1 == t2, failed);
  }
  {
    // Check range based with array based ctor.
    boost::array<mpi::cartesian_dimension, 3> d = {{cd(2,true),cd(3, false),cd(4, true)}};
    int dims[] = {2,3,4};
    bool per[] = {true, false, true};
    mpi::cartesian_topology t1(dims, per);
    mpi::cartesian_topology t2(d);
    BOOST_MPI_CHECK(t1.size() == 3, failed);
    BOOST_MPI_CHECK(t1 == t2, failed);
  }
  {
    // Iterator based ctor vs C array based ctor
    mpi::cartesian_dimension d[] = {cd(2,true),cd(3, false),cd(4, true)};
    std::vector<mpi::cartesian_dimension> vdims(d, d+3);
    mpi::cartesian_topology t1(vdims);
    mpi::cartesian_topology t2(d);
    BOOST_MPI_CHECK(t1.size() == 3, failed);
    BOOST_MPI_CHECK(t1 == t2, failed);
    BOOST_MPI_CHECK(!(t1 != t2), failed);
    t1[1].periodic = true;
    BOOST_MPI_CHECK(t1 != t2, failed);
    t1[2].periodic = false;
    t1[2].size = 0;
    vdims.push_back(mpi::cartesian_dimension(3, false));
    mpi::cartesian_topology t3(vdims);
    BOOST_MPI_CHECK(t1 != t3, failed);
  }
  return failed;
}