Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
xt_redist_msg.c
Go to the documentation of this file.
1
12/*
13 * Keywords:
14 * Maintainer: Jörg Behrens <behrens@dkrz.de>
15 * Moritz Hanke <hanke@dkrz.de>
16 * Thomas Jahns <jahns@dkrz.de>
17 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met:
22 *
23 * Redistributions of source code must retain the above copyright notice,
24 * this list of conditions and the following disclaimer.
25 *
26 * Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 *
30 * Neither the name of the DKRZ GmbH nor the names of its contributors
31 * may be used to endorse or promote products derived from this software
32 * without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 */
46#ifdef HAVE_CONFIG_H
47#include <config.h>
48#endif
49
50#include "xt/xt_mpi.h"
51#include "xt_redist_internal.h"
52
53void
55 const struct Xt_redist_msg *restrict src,
56 size_t src_stride,
57 struct Xt_redist_msg *restrict dst,
58 size_t dst_stride,
59 MPI_Comm comm, bool dt_dup) {
60
61
62 const unsigned char *restrict src_store = (const unsigned char *)src;
63 unsigned char *restrict dst_store = (unsigned char *)dst;
64 for (size_t i = 0; i < n; ++i) {
65 const struct Xt_redist_msg *restrict src_msg
66 = (const struct Xt_redist_msg *)(const void *)(src_store + i * src_stride);
67 struct Xt_redist_msg *dst_msg
68 = (struct Xt_redist_msg *)(void *)(dst_store + i * dst_stride);
69 dst_msg->rank = src_msg->rank;
70 if (dt_dup)
71 xt_mpi_call(MPI_Type_dup(src_msg->datatype, &(dst_msg->datatype)), comm);
72 else
73 dst_msg->datatype = src_msg->datatype;
74 }
75}
76
78 MPI_Comm comm, size_t ofs_stride) {
79
80 unsigned char *restrict msgs_store = (unsigned char *)msgs;
81 for (size_t i = 0; i < n; ++i) {
82 MPI_Datatype *pdt
83 = &(((struct Xt_redist_msg *)(void *)(msgs_store + i * ofs_stride))->datatype),
84 dt = *pdt;
85 if (dt != MPI_DATATYPE_NULL) {
86 xt_mpi_call(MPI_Type_free(pdt), comm);
87 for (size_t j = i + 1; j < n; ++j) {
88 MPI_Datatype *pdt_j
89 = &(((struct Xt_redist_msg *)(void *)(msgs_store + j * ofs_stride))->datatype);
90 if (*pdt_j == dt)
91 *pdt_j = MPI_DATATYPE_NULL;
92 }
93 }
94 }
95}
96
97
98/*
99 * Local Variables:
100 * c-basic-offset: 2
101 * coding: utf-8
102 * indent-tabs-mode: nil
103 * show-trailing-whitespace: t
104 * require-trailing-newline: t
105 * End:
106 */
int MPI_Comm
Definition core.h:64
MPI_Datatype datatype
Definition xt_redist.h:69
int MPI_Type_free(MPI_Datatype *datatype)
int MPI_Type_dup(MPI_Datatype oldtype, MPI_Datatype *newtype)
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition xt_mpi.h:68
redistribution of data, non-public declarations
void xt_redist_msgs_strided_copy(size_t n, const struct Xt_redist_msg *restrict src, size_t src_stride, struct Xt_redist_msg *restrict dst, size_t dst_stride, MPI_Comm comm, bool dt_dup)
void xt_redist_msgs_strided_destruct(size_t n, struct Xt_redist_msg *msgs, MPI_Comm comm, size_t ofs_stride)