test_redist_collection_static.c 5.31 KB
Newer Older
1
2
3
/**
 * @file test_redist_collection_static.c
 *
4
5
 * @copyright Copyright  (C)  2016 Jörg Behrens <behrens@dkrz.de>
 *                                 Moritz Hanke <hanke@dkrz.de>
6
7
 *                                 Thomas Jahns <jahns@dkrz.de>
 *
8
9
 * @author Jörg Behrens <behrens@dkrz.de>
 *         Moritz Hanke <hanke@dkrz.de>
10
11
12
13
 *         Thomas Jahns <jahns@dkrz.de>
 */
/*
 * Keywords:
14
15
 * Maintainer: Jörg Behrens <behrens@dkrz.de>
 *             Moritz Hanke <hanke@dkrz.de>
16
 *             Thomas Jahns <jahns@dkrz.de>
Moritz Hanke's avatar
Moritz Hanke committed
17
 * URL: https://doc.redmine.dkrz.de/yaxt/html/
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
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are  permitted provided that the following conditions are
 * met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * Neither the name of the DKRZ GmbH nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
Thomas Jahns's avatar
Thomas Jahns committed
46
47
48
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
49

50
51
52
53
#include <string.h>

#include <mpi.h>

54
#include <yaxt.h>
55

56
#include "tests.h"
57
#include "test_redist_common.h"
58

59
60
61
62
63
64
static void
simple_test(MPI_Comm comm);

static void
test_repeated_redist(MPI_Comm comm);

65
66
67
68
int main(void) {

  // init mpi

69
  xt_mpi_call(MPI_Init(NULL, NULL), MPI_COMM_WORLD);
70

71
  xt_initialize(MPI_COMM_WORLD);
72

73
  simple_test(MPI_COMM_WORLD);
74

75
76
  xt_finalize();
  MPI_Finalize();
77

78
79
  return TEST_EXIT_CODE;
}
80

81
82
83
84
85
86
static void
simple_test(MPI_Comm comm)
{ // general test with one redist
  // set up data
  enum { src_slice_len = 5, dst_slice_len = 3 };
  Xt_xmap xmap = build_odd_selection_xmap(src_slice_len);
87

88
  Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
89

90
  xt_xmap_delete(xmap);
91

92
  // generate redist_collection
93

94
  static const MPI_Aint displacements[1] = {0};
95

96
97
98
  Xt_redist redist_coll
    = xt_redist_collection_static_new(&redist, 1, displacements,
                                      displacements, comm);
99

100
  // test communicator of redist
101

102
103
  if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
    PUT_ERR("error in xt_redist_get_MPI_Comm\n");
104

105
  xt_redist_delete(redist);
106

107
108
109
110
  // test exchange
  static const double src_data[] = {1,2,3,4,5};
  static const double ref_dst_data[] = {1,3,5};
  enum { num_dst_elems = sizeof (ref_dst_data) / sizeof (ref_dst_data[0]) };
111

112
113
114
115
  double dst_data[num_dst_elems];
  check_redist(redist_coll, src_data,
               num_dst_elems, dst_data, fill_array_double, NULL,
               ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
116

117
118
119
  // clean up
  xt_redist_delete(redist_coll);
}
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
static void
test_repeated_redist(MPI_Comm comm)
{ // test with one redist used three times (two exchanges)
  // set up data
  enum { src_slice_len = 5,
         dst_slice_len = (src_slice_len+1)/2 };
  Xt_xmap xmap = build_odd_selection_xmap(5);
  Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);

  xt_xmap_delete(xmap);

  // generate redist_collection
  Xt_redist redists[3] = {redist, redist, redist};
  static const double src_data[3][src_slice_len]
    = {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
  double dst_data[3][3];
  MPI_Aint src_displacements[3]
    = {0, (MPI_Aint)((size_t)(src_data[1] - src_data[0]) * sizeof (double)),
       (MPI_Aint)((size_t)(src_data[2] - src_data[0]) * sizeof(double)) };
  MPI_Aint dst_displacements[3]
    = {0, (MPI_Aint)((size_t)(dst_data[1] - dst_data[0]) * sizeof(double)),
       (MPI_Aint)((size_t)(dst_data[2] - dst_data[0]) * sizeof(double)) };

  Xt_redist redist_coll
    = xt_redist_collection_static_new(redists, 3, src_displacements,
                                      dst_displacements, comm);

  // test communicator of redist
  if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
    PUT_ERR("error in xt_redist_get_MPI_Comm\n");

  xt_redist_delete(redist);

  // test exchange
  static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
  check_redist(redist_coll, src_data,
               sizeof (dst_data) / sizeof (dst_data[0][0]),
               dst_data, fill_array_double, NULL,
               ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);

  // clean up
  xt_redist_delete(redist_coll);
163
}
164

165

166
167
168
169
170
171
172
173
174
/*
 * Local Variables:
 * c-basic-offset: 2
 * coding: utf-8
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */