Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
xt_request_msgs_packed.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 <assert.h>
51#include <stdlib.h>
52#include <string.h>
53
54#include "core/ppm_xfuncs.h"
55#include "xt/xt_mpi.h"
56
58#include "xt_config_internal.h"
59#include "xt_mpi_internal.h"
60#include "xt_request_internal.h"
62
66 MPI_Datatype *datatypes;
67 void *buffers[];
68};
69
70static void
72{
74 struct Xt_request_msgs_packed *request_msgs_packed = ebuf;
75 int n_packed = request_msgs_packed->n_packed;
76 for (int i = 0; i < n_packed; ++i) {
77 int position = 0, buffer_size;
78 xt_mpi_call(MPI_Pack_size(1, request_msgs_packed->datatypes[i],
79 comm, &buffer_size), comm);
80 xt_mpi_call(MPI_Unpack(request_msgs_packed->buffers[i], buffer_size,
81 &position, request_msgs_packed->unpacked_data,
82 1, request_msgs_packed->datatypes[i], comm), comm);
83 }
84
85 int n_tmp_buffers = request_msgs_packed->n_tmp_buffers;
86 for (int i = 0; i < n_packed + n_tmp_buffers; ++i)
87 free(request_msgs_packed->buffers[i]);
88 for (int i = 0; i < n_packed; ++i)
89 xt_mpi_call(MPI_Type_free(request_msgs_packed->datatypes+i), comm);
90 free(request_msgs_packed->datatypes);
91}
92
94 const MPI_Request requests[n_requests],
95 MPI_Comm comm, int n_packed,
96 int n_tmp_buffers,
97 const MPI_Datatype datatypes[n_packed],
98 void *packed_data[n_packed],
99 void *tmp_buffers[n_tmp_buffers],
100 void * unpacked_data) {
101
102 assert(n_requests >= 0 && n_packed >= 0 && n_tmp_buffers >= 0);
103 size_t hdr_size = sizeof(struct Xt_request_msgs_packed),
104 bufp_size = ((size_t)n_packed + (size_t)n_tmp_buffers) * sizeof(void *);
105
106 struct Xt_config_ conf = xt_default_config;
108 Xt_request request
109 = xt_request_msgs_ebuf_alloc(n_requests, comm, hdr_size+bufp_size, &conf);
110 MPI_Request *requests_
112 memcpy(requests_, requests,
113 (size_t)n_requests * sizeof(*requests_));
114 struct Xt_request_msgs_packed *ebuf
116 ebuf->n_packed = n_packed;
118 ebuf->datatypes = xmalloc((size_t)n_packed * sizeof(*ebuf->datatypes));
119 for (int i = 0; i < n_packed; ++i)
120 xt_mpi_call(MPI_Type_dup(datatypes[i], ebuf->datatypes + i), comm);
121 memcpy(ebuf->buffers, packed_data,
122 (size_t)n_packed * sizeof(*ebuf->buffers));
123 memcpy(ebuf->buffers + n_packed, tmp_buffers,
124 (size_t)n_tmp_buffers * sizeof(*ebuf->buffers));
127 return request;
128}
129
130/*
131 * Local Variables:
132 * c-basic-offset: 2
133 * coding: utf-8
134 * indent-tabs-mode: nil
135 * show-trailing-whitespace: t
136 * require-trailing-newline: t
137 * End:
138 */
int MPI_Comm
Definition core.h:64
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition ppm_xfuncs.h:70
int MPI_Type_free(MPI_Datatype *datatype)
int MPI_Type_dup(MPI_Datatype oldtype, MPI_Datatype *newtype)
struct Xt_config_ xt_default_config
Definition xt_config.c:204
void xt_config_set_redist_mthread_mode(Xt_config config, int mode)
Definition xt_config.c:347
@ XT_MT_NONE
Definition xt_config.h:140
implementation of configuration object
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition xt_mpi.h:68
Provide non-public declarations common to all requests.
void xt_request_msgs_ebuf_set_finalizer(Xt_request request, Xt_request_msgs_ebuf_finalizer finalizer)
MPI_Comm xt_request_msgs_ebuf_get_comm(Xt_request request)
Xt_request xt_request_msgs_ebuf_alloc(int n_requests, MPI_Comm comm, size_t extra_buf_size, Xt_config config)
MPI_Request * xt_request_msgs_ebuf_get_req_ptr(Xt_request request)
void * xt_request_msgs_ebuf_get_extra_buf(Xt_request request)
internal interfaces for xt_request_msgs_ebuf
Xt_request xt_request_msgs_packed_new(int n_requests, const MPI_Request requests[n_requests], MPI_Comm comm, int n_packed, int n_tmp_buffers, const MPI_Datatype datatypes[n_packed], void *packed_data[n_packed], void *tmp_buffers[n_tmp_buffers], void *unpacked_data)
static void xt_request_msgs_packed_finalize(Xt_request request, void *ebuf)