1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2017 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2006-2013 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
15 * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
16 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
17 * reserved.
18 * Copyright (c) 2015 Research Organization for Information Science
19 * and Technology (RIST). All rights reserved.
20 * $COPYRIGHT$
21 *
22 * Additional copyrights may follow
23 *
24 * $HEADER$
25 */
26
27 #include "ompi_config.h"
28
29 #include "ompi/communicator/communicator.h"
30 #include "opal/class/opal_object.h"
31 #include "ompi/request/request.h"
32 #include "ompi/request/request_default.h"
33 #include "ompi/constants.h"
34
35 opal_pointer_array_t ompi_request_f_to_c_table = {{0}};
36 ompi_predefined_request_t ompi_request_null = {{{{{0}}}}};
37 ompi_predefined_request_t *ompi_request_null_addr = &ompi_request_null;
38 ompi_request_t ompi_request_empty = {{{{0}}}};
39 ompi_status_public_t ompi_status_empty = {0};
40 ompi_request_fns_t ompi_request_functions = {
41 ompi_request_default_test,
42 ompi_request_default_test_any,
43 ompi_request_default_test_all,
44 ompi_request_default_test_some,
45 ompi_request_default_wait,
46 ompi_request_default_wait_any,
47 ompi_request_default_wait_all,
48 ompi_request_default_wait_some
49 };
50
ompi_request_construct(ompi_request_t * req)51 static void ompi_request_construct(ompi_request_t* req)
52 {
53 /* don't call _INIT, we don't to set the request to _INACTIVE and there will
54 * be no matching _FINI invocation */
55 req->req_state = OMPI_REQUEST_INVALID;
56 req->req_complete = false;
57 req->req_persistent = false;
58 req->req_start = NULL;
59 req->req_free = NULL;
60 req->req_cancel = NULL;
61 req->req_complete_cb = NULL;
62 req->req_complete_cb_data = NULL;
63 req->req_f_to_c_index = MPI_UNDEFINED;
64 req->req_mpi_object.comm = (struct ompi_communicator_t*) NULL;
65 }
66
ompi_request_destruct(ompi_request_t * req)67 static void ompi_request_destruct(ompi_request_t* req)
68 {
69 assert( MPI_UNDEFINED == req->req_f_to_c_index );
70 assert( OMPI_REQUEST_INVALID == req->req_state );
71 }
72
ompi_request_null_free(ompi_request_t ** request)73 static int ompi_request_null_free(ompi_request_t** request)
74 {
75 return OMPI_SUCCESS;
76 }
77
ompi_request_null_cancel(ompi_request_t * request,int flag)78 static int ompi_request_null_cancel(ompi_request_t* request, int flag)
79 {
80 return OMPI_SUCCESS;
81 }
82
ompi_request_empty_free(ompi_request_t ** request)83 static int ompi_request_empty_free(ompi_request_t** request)
84 {
85 *request = &ompi_request_null.request;
86 return OMPI_SUCCESS;
87 }
88
ompi_request_persistent_proc_null_free(ompi_request_t ** request)89 int ompi_request_persistent_proc_null_free(ompi_request_t** request)
90 {
91 OMPI_REQUEST_FINI(*request);
92 (*request)->req_state = OMPI_REQUEST_INVALID;
93 OBJ_RELEASE(*request);
94 *request = &ompi_request_null.request;
95 return OMPI_SUCCESS;
96 }
97
98
99 OBJ_CLASS_INSTANCE(
100 ompi_request_t,
101 opal_free_list_item_t,
102 ompi_request_construct,
103 ompi_request_destruct);
104
105
ompi_request_init(void)106 int ompi_request_init(void)
107 {
108
109 OBJ_CONSTRUCT(&ompi_request_null, ompi_request_t);
110 OBJ_CONSTRUCT(&ompi_request_f_to_c_table, opal_pointer_array_t);
111 if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_request_f_to_c_table,
112 0, OMPI_FORTRAN_HANDLE_MAX, 32) ) {
113 return OMPI_ERROR;
114 }
115 ompi_request_null.request.req_type = OMPI_REQUEST_NULL;
116 ompi_request_null.request.req_status.MPI_SOURCE = MPI_ANY_SOURCE;
117 ompi_request_null.request.req_status.MPI_TAG = MPI_ANY_TAG;
118 ompi_request_null.request.req_status.MPI_ERROR = MPI_SUCCESS;
119 ompi_request_null.request.req_status._ucount = 0;
120 ompi_request_null.request.req_status._cancelled = 0;
121
122 ompi_request_null.request.req_complete = REQUEST_COMPLETED;
123 ompi_request_null.request.req_state = OMPI_REQUEST_INACTIVE;
124 ompi_request_null.request.req_persistent = false;
125 ompi_request_null.request.req_f_to_c_index =
126 opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_null);
127 ompi_request_null.request.req_start = NULL; /* should not be called */
128 ompi_request_null.request.req_free = ompi_request_null_free;
129 ompi_request_null.request.req_cancel = ompi_request_null_cancel;
130 ompi_request_null.request.req_mpi_object.comm = &ompi_mpi_comm_world.comm;
131
132 if (0 != ompi_request_null.request.req_f_to_c_index) {
133 return OMPI_ERR_REQUEST;
134 }
135
136 /* We need a way to distinguish between the user provided
137 * MPI_REQUEST_NULL to MPI_Wait* and a non-active (MPI_PROC_NULL)
138 * request passed to any P2P non-blocking function.
139 *
140 * The main difference to ompi_request_null is
141 * req_state being OMPI_REQUEST_ACTIVE, so that MPI_Waitall
142 * does not set the status to ompi_status_empty and the different
143 * req_free function, which resets the
144 * request to MPI_REQUEST_NULL.
145 * The req_cancel function need not be changed.
146 */
147 OBJ_CONSTRUCT(&ompi_request_empty, ompi_request_t);
148 ompi_request_empty.req_type = OMPI_REQUEST_NULL;
149 ompi_request_empty.req_status.MPI_SOURCE = MPI_PROC_NULL;
150 ompi_request_empty.req_status.MPI_TAG = MPI_ANY_TAG;
151 ompi_request_empty.req_status.MPI_ERROR = MPI_SUCCESS;
152 ompi_request_empty.req_status._ucount = 0;
153 ompi_request_empty.req_status._cancelled = 0;
154
155 ompi_request_empty.req_complete = REQUEST_COMPLETED;
156 ompi_request_empty.req_state = OMPI_REQUEST_ACTIVE;
157 ompi_request_empty.req_persistent = false;
158 ompi_request_empty.req_f_to_c_index =
159 opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_empty);
160 ompi_request_empty.req_start = NULL; /* should not be called */
161 ompi_request_empty.req_free = ompi_request_empty_free;
162 ompi_request_empty.req_cancel = ompi_request_null_cancel;
163 ompi_request_empty.req_mpi_object.comm = &ompi_mpi_comm_world.comm;
164
165 if (1 != ompi_request_empty.req_f_to_c_index) {
166 return OMPI_ERR_REQUEST;
167 }
168
169 ompi_status_empty.MPI_SOURCE = MPI_ANY_SOURCE;
170 ompi_status_empty.MPI_TAG = MPI_ANY_TAG;
171 ompi_status_empty.MPI_ERROR = MPI_SUCCESS;
172 ompi_status_empty._ucount = 0;
173 ompi_status_empty._cancelled = 0;
174
175 return OMPI_SUCCESS;
176 }
177
178
ompi_request_finalize(void)179 int ompi_request_finalize(void)
180 {
181 OMPI_REQUEST_FINI( &ompi_request_null.request );
182 OBJ_DESTRUCT( &ompi_request_null.request );
183 OMPI_REQUEST_FINI( &ompi_request_empty );
184 OBJ_DESTRUCT( &ompi_request_empty );
185 OBJ_DESTRUCT( &ompi_request_f_to_c_table );
186 return OMPI_SUCCESS;
187 }
188