Yet Another eXchange Tool  0.9.0
xt_request_msgs.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://doc.redmine.dkrz.de/yaxt/html/
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 <mpi.h>
55 
56 #include "core/ppm_xfuncs.h"
57 #include "xt/xt_mpi.h"
58 
59 #include "xt/xt_request_msgs.h"
60 #include "xt_mpi_internal.h"
61 #include "xt_request_internal.h"
62 
63 static void xt_request_msgs_wait(Xt_request request);
64 static int xt_request_msgs_test(Xt_request request);
65 
66 static const struct Xt_request_vtable request_msgs_vtable = {
67 
69  .test = xt_request_msgs_test,
70 };
71 
73 
75 
76  const struct Xt_request_vtable *vtable;
77  int n;
80  MPI_Request requests[];
81 };
82 
83 Xt_request xt_request_msgs_new(int n, const MPI_Request *requests,
84  MPI_Comm comm) {
85 
86  assert(n >= 0);
87  Xt_request_msgs request
88  = xmalloc(sizeof(*request) + (size_t)n * sizeof(MPI_Request) +
89  (size_t)n * sizeof(int));
90 
91  request->vtable = &request_msgs_vtable;
92  request->n = n;
93  request->comm = comm;
94  request->ops_completed_buffer = (int *)(request->requests + (size_t)n);
95  memcpy(request->requests, requests, (size_t)n * sizeof(*request->requests));
96 
97  return (Xt_request)request;
98 }
99 
100 static void xt_request_msgs_wait(Xt_request request) {
101 
102  Xt_request_msgs request_msgs = (Xt_request_msgs)request;
103  xt_mpi_call(MPI_Waitall(request_msgs->n, request_msgs->requests,
104  MPI_STATUSES_IGNORE), request_msgs->comm);
105 
106  free(request_msgs);
107 }
108 
109 static int xt_request_msgs_test(Xt_request request) {
110 
111  Xt_request_msgs request_msgs = (Xt_request_msgs)request;
112 
113  int flag = xt_mpi_test_some(&(request_msgs->n), request_msgs->requests,
114  request_msgs->ops_completed_buffer,
115  request_msgs->comm);
116 
117  if (flag) free(request_msgs);
118 
119  return flag;
120 }
121 
122 /*
123  * Local Variables:
124  * c-basic-offset: 2
125  * coding: utf-8
126  * indent-tabs-mode: nil
127  * show-trailing-whitespace: t
128  * require-trailing-newline: t
129  * End:
130  */
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
MPI_Request requests[]
const struct Xt_request_vtable * vtable
void(* wait)(Xt_request request)
bool xt_mpi_test_some(int *restrict num_req, MPI_Request *restrict req, int *restrict ops_completed, MPI_Comm comm)
Definition: xt_mpi.c:892
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition: xt_mpi.h:68
Provide non-public declarations common to all requests.
static int xt_request_msgs_test(Xt_request request)
Xt_request xt_request_msgs_new(int n, const MPI_Request *requests, MPI_Comm comm)
static const struct Xt_request_vtable request_msgs_vtable
static void xt_request_msgs_wait(Xt_request request)
struct Xt_request_msgs_ * Xt_request_msgs