Skip to content

Commit 03c36a5

Browse files
committed
Minor changes to the continuation API to reflect current proposal
- Swap flags and max_poll parameter in MPI_Continue_init - Swap cont_req and info parameter in MPI_Continue_init - Add new flags and remove support for info keys mpi_continue_poll_only, mpi_continue_max_poll, and mpi_continue_enqueue_complete Signed-off-by: Joseph Schuchart <[email protected]>
1 parent aace1a0 commit 03c36a5

File tree

5 files changed

+108
-54
lines changed

5 files changed

+108
-54
lines changed

ompi/mpiext/continue/c/continuation.c

+3-26
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ int ompi_continue_attach(
824824
}
825825

826826
bool req_volatile = (flags & MPIX_CONT_REQBUF_VOLATILE);
827+
bool defer_complete = (flags & MPIX_CONT_DEFER_COMPLETE);
827828

828829
ompi_cont_request_t *cont_req = (ompi_cont_request_t *)continuation_request;
829830
ompi_continuation_t *cont = ompi_continue_cont_create(count, cont_req, cont_cb,
@@ -901,7 +902,7 @@ int ompi_continue_attach(
901902
last_num_active = OPAL_THREAD_ADD_FETCH32(&cont->cont_num_active, -num_complete);
902903
}
903904
if (0 == last_num_active) {
904-
if (cont_req->cont_enqueue_complete || OMPI_REQUEST_INACTIVE == cont_req->super.req_state) {
905+
if (defer_complete || OMPI_REQUEST_INACTIVE == cont_req->super.req_state) {
905906
/* enqueue for later processing */
906907
ompi_continue_enqueue_runnable(cont);
907908
} else {
@@ -930,8 +931,8 @@ int ompi_continue_attach(
930931
*/
931932
int ompi_continue_allocate_request(
932933
ompi_request_t **cont_req_ptr,
933-
int max_poll,
934934
int flags,
935+
int max_poll,
935936
ompi_info_t *info)
936937
{
937938
ompi_cont_request_t *cont_req = OBJ_NEW(ompi_cont_request_t);
@@ -940,35 +941,11 @@ int ompi_continue_allocate_request(
940941

941942
cont_req->cont_flags = flags;
942943

943-
int flag;
944-
bool test_poll = false;
945-
/* TODO: remove the info flag */
946-
ompi_info_get_bool(info, "mpi_continue_poll_only", &test_poll, &flag);
947-
948-
if ((flag && test_poll)) {
949-
cont_req->cont_flags |= MPIX_CONT_POLL_ONLY;
950-
}
951-
952944
if (cont_req->cont_flags & MPIX_CONT_POLL_ONLY) {
953945
cont_req->cont_complete_list = OBJ_NEW(opal_list_t);
954946
}
955947

956-
/* TODO: remove this flags, it should be part of attach */
957-
bool enqueue_complete = false;
958-
ompi_info_get_bool(info, "mpi_continue_enqueue_complete", &enqueue_complete, &flag);
959-
cont_req->cont_enqueue_complete = (flag && enqueue_complete);
960-
961948
cont_req->continue_max_poll = max_poll;
962-
/* TODO: remove this flag, it's explicit now */
963-
opal_cstring_t *value_str;
964-
ompi_info_get(info, "mpi_continue_max_poll", &value_str, &flag);
965-
if (flag) {
966-
int max_poll = atoi(value_str->string);
967-
OBJ_RELEASE(value_str);
968-
if (max_poll > 0) {
969-
cont_req->continue_max_poll = max_poll;
970-
}
971-
}
972949
if (0 == cont_req->continue_max_poll) {
973950
cont_req->continue_max_poll = UINT32_MAX;
974951
}

ompi/mpiext/continue/c/continue_init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ static const char FUNC_NAME[] = "MPIX_Continue_init";
3636
int MPIX_Continue_init(
3737
int max_poll,
3838
int flags,
39-
MPI_Request *cont_req,
40-
MPI_Info info)
39+
MPI_Info info,
40+
MPI_Request *cont_req)
4141
{
4242
int rc = MPI_SUCCESS;
4343

ompi/mpiext/continue/c/mpiext_continue_c.h

+95-7
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,105 @@
1616

1717
#include <mpi.h>
1818

19+
/**
20+
* Mark the continuation request(s) as volatile.
21+
* Generally, the request buffer should remain accessible until the continuation is invoked
22+
* and will be set to MPI_REQUEST_NULL before the continuation is invoked.
23+
* However, if this flag is specified the requests are not accessed after the call to
24+
* MPI_Continue[all] returns.
25+
*/
1926
#define MPIX_CONT_REQBUF_VOLATILE 1<<0
20-
/* the continuation is persistent (only valid with persistent requests) */
21-
#define MPIX_CONT_PERSISTENT 1<<1
22-
#define MPIX_CONT_POLL_ONLY 1<<2
2327

24-
typedef int (MPIX_Continue_cb_function)(int rc, void *user_data);
25-
OMPI_DECLSPEC int MPIX_Continue_init(int max_poll, int flags, MPI_Request *cont_req, MPI_Info info);
28+
/**
29+
* the continuation is persistent (only valid with persistent requests)
30+
* TODO: not implemented yet
31+
*/
32+
#define MPIX_CONT_PERSISTENT 1<<1
33+
34+
/*
35+
* mark the continuation request as poll-only, i.e., only execute continuations
36+
* when testing/waiting for the continuation request to complete
37+
*/
38+
#define MPIX_CONT_POLL_ONLY 1<<2
39+
40+
/* Wwhether the execution of continuations is deferred in MPI_Continue or
41+
* MPI_Continueall if all operations are complete.
42+
* By default, continuations eligible for execution are invoked immediately. */
43+
#define MPIX_CONT_DEFER_COMPLETE 1<<3
44+
45+
/* whether failed continuations will be invoked and passed the error code
46+
* TODO: not implemented yet
47+
*/
48+
#define MPIX_CONT_INVOKE_FAILED 1<<4
49+
50+
/**
51+
* Completion callback signature:
52+
* \param rc an error code (MPI_SUCCESS, unless MPIX_CONT_INVOKE_FAILED is provided)
53+
* \param cb_data the pointer passed as cb_data to MPI_Continue[all]
54+
* \returns MPI_SUCECSS on success, an error code to mark the continuation as failed
55+
*/
56+
typedef int (MPIX_Continue_cb_function)(int rc, void *cb_data);
57+
58+
/**
59+
* Initialize a continuation request.
60+
* \param flags 0 or \ref MPIX_CONT_POLL_ONLY
61+
* \param max_poll the maximum number of continuations to execute when testing
62+
* the continuation request for completion or MPI_UNDEFINED for
63+
* unlimited execution of eligible continuations
64+
* \param info info object used to further control the behavior of the continuation request.
65+
* Currently supported:
66+
* - mpi_continue_thread: either "all" (any thread in the process may execute callbacks)
67+
* or "application" (only application threads may execute callbacks; default)
68+
* - mpi_continue_async_signal_safe: whether the callbacks may be executed from within a signal handler
69+
* \param[out] cont_req the newly created continuation request
70+
*/
71+
OMPI_DECLSPEC int MPIX_Continue_init(int flags, int max_poll, MPI_Info info, MPI_Request *cont_req);
72+
73+
/**
74+
* Attach a new continuation to the operation represented by \c request and register it with the continuation request \c cont_req.
75+
* The callback will be executed once the operation has completed and will be passed the \c cb_data pointer.
76+
*
77+
* \param request the request representing the the operation to attach a continuation to
78+
* \param cb the callback to invoke upon completion, with signature \ref MPIX_Continue_cb_function
79+
* \param cb_data the user-data to pass to the callback
80+
* \param flags 0 or OR-combination of \ref MPIX_CONT_REQBUF_VOLATILE, \ref MPIX_CONT_PERSISTENT,
81+
* \ref MPIX_CONT_DEFER_COMPLETE, \ref MPIX_CONT_INVOKE_FAILED
82+
* \param status MPI_STATUS_IGNORE or a pointer to a status object that will be a filled before the callback is invoked
83+
* \param cont_req a continuation request created through \ref MPIX_Continue_init
84+
*/
2685
OMPI_DECLSPEC int MPIX_Continue(MPI_Request *request, MPIX_Continue_cb_function *cb, void *cb_data,
2786
int flags, MPI_Status *status, MPI_Request cont_req);
28-
OMPI_DECLSPEC int MPIX_Continueall(int count, MPI_Request request[], MPIX_Continue_cb_function *cb, void *cb_data,
87+
88+
/**
89+
* Attach a new continuation to the operations represented by the \c count \c requests and
90+
* register it with the continuation request \c cont_req.
91+
* The callback will be executed once the operations have completed and will be passed the \c cb_data pointer.
92+
*
93+
* \param count the number of requests in \c requests
94+
* \param requests the requests representing the the operations to attach a continuation to
95+
* \param cb the callback to invoke upon completion of all operations, with signature \ref MPIX_Continue_cb_function
96+
* \param cb_data the user-data to pass to the callback
97+
* \param flags 0 or OR-combination of \ref MPIX_CONT_REQBUF_VOLATILE, \ref MPIX_CONT_PERSISTENT,
98+
* \ref MPIX_CONT_DEFER_COMPLETE, \ref MPIX_CONT_INVOKE_FAILED
99+
* \param status MPI_STATUS_IGNORE or a pointer to a status object that will be a filled before the callback is invoked
100+
* \param cont_req a continuation request created through \ref MPIX_Continue_init
101+
*/
102+
OMPI_DECLSPEC int MPIX_Continueall(int count, MPI_Request requests[], MPIX_Continue_cb_function *cb, void *cb_data,
29103
int flags, MPI_Status status[], MPI_Request cont_req);
30-
OMPI_DECLSPEC int MPIX_Continue_get_failed( MPI_Request cont_req, int *count, void **cb_data);
104+
105+
/**
106+
* Query the callback data for failed continuations, i.e., continuations that returned a value other than
107+
* MPI_SUCCESS or whose operations experienced an error.
108+
* The applications passes in \c cb_data an array of size \c count. Upon return, \c count will be set
109+
* to the actual number of elements stored in \c cb_data. If the resulting \c count equals \c count
110+
* on input there may be more failed continuations to query and the call should be repeated.
111+
* \note Handling of failed continuations requires an error handler for the involved operations that does not abort and
112+
* is not supported if \ref MPIX_CONT_REQBUF_VOLATILE is used.
113+
*
114+
* \param cont_req The continuation request from which to query failed continuations
115+
* \param[inout] count The maximum number of elements to be stored in \c cb_data
116+
* \param cb_data Buffer of size \c count elements to store the callback data of failed continuations into
117+
*/
118+
OMPI_DECLSPEC int MPIX_Continue_get_failed(MPI_Request cont_req, int *count, void **cb_data);
31119

32120
#endif // MPIEXT_CONTINUE_C_H

test/continuations/continutions-mt.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
7676
sleep(2);
7777

7878
/* initialize the continuation request */
79-
MPIX_Continue_init(0, 0, &cont_req, MPI_INFO_NULL);
79+
MPIX_Continue_init(0, 0, MPI_INFO_NULL, &cont_req);
8080

8181
MPI_Start(&cont_req);
8282

@@ -113,14 +113,8 @@ int main(int argc, char *argv[])
113113
/****************************************************************
114114
* Do the same thing, but with a poll-only continuation request
115115
****************************************************************/
116-
117-
MPI_Info info;
118-
MPI_Info_create(&info);
119-
MPI_Info_set(info, "mpi_continue_poll_only", "true");
120-
MPI_Info_set(info, "mpi_continue_enqueue_complete", "true");
121-
122116
/* initialize the continuation request */
123-
MPIX_Continue_init(0, 0, &cont_req, info);
117+
MPIX_Continue_init(MPIX_CONT_POLL_ONLY, MPI_UNDEFINED, MPI_INFO_NULL, &cont_req);
124118

125119
MPI_Info_free(&info);
126120

@@ -133,7 +127,7 @@ int main(int argc, char *argv[])
133127
MPI_Isend(&val, 1, MPI_INT, rank, 1001, MPI_COMM_WORLD, &reqs[1]);
134128

135129
cb_cnt = 0;
136-
MPIX_Continueall(2, reqs, &complete_cnt_cb, &cb_cnt, 0, MPI_STATUSES_IGNORE, cont_req);
130+
MPIX_Continueall(2, reqs, &complete_cnt_cb, &cb_cnt, MPIX_CONT_DEFER_COMPLETE, MPI_STATUSES_IGNORE, cont_req);
137131
MPI_Wait(&cont_req, MPI_STATUS_IGNORE);
138132
assert(reqs[0] == MPI_REQUEST_NULL && reqs[1] == MPI_REQUEST_NULL);
139133
assert(cb_cnt == 1);
@@ -145,10 +139,10 @@ int main(int argc, char *argv[])
145139
*/
146140
cb_cnt = 0;
147141
MPI_Irecv(&val, 1, MPI_INT, rank, 1001, MPI_COMM_WORLD, &reqs[0]);
148-
MPIX_Continue(&reqs[0], &complete_cnt_cb, &cb_cnt, 0, MPI_STATUS_IGNORE, cont_req);
142+
MPIX_Continue(&reqs[0], &complete_cnt_cb, &cb_cnt, MPIX_CONT_DEFER_COMPLETE, MPI_STATUS_IGNORE, cont_req);
149143

150144
MPI_Isend(&val, 1, MPI_INT, rank, 1001, MPI_COMM_WORLD, &reqs[1]);
151-
MPIX_Continue(&reqs[1], &complete_cnt_cb, &cb_cnt, 0, MPI_STATUS_IGNORE, cont_req);
145+
MPIX_Continue(&reqs[1], &complete_cnt_cb, &cb_cnt, MPIX_CONT_DEFER_COMPLETE, MPI_STATUS_IGNORE, cont_req);
152146

153147
MPI_Wait(&cont_req, MPI_STATUS_IGNORE);
154148
assert(reqs[0] == MPI_REQUEST_NULL && reqs[1] == MPI_REQUEST_NULL);

test/continuations/continutions.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
5252
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5353

5454
/* initialize the continuation request */
55-
MPIX_Continue_init(0, 0, &cont_req, MPI_INFO_NULL);
55+
MPIX_Continue_init(0, 0, MPI_INFO_NULL, &cont_req);
5656

5757
MPI_Start(&cont_req);
5858

@@ -92,13 +92,8 @@ int main(int argc, char *argv[])
9292
/**
9393
* One send, one recv, two continuations in two continuation requests
9494
*/
95-
MPI_Info info;
96-
MPI_Info_create(&info);
97-
MPI_Info_set(info, "mpi_continue_poll_only", "true");
98-
MPI_Info_set(info, "mpi_continue_enqueue_complete", "true");
99-
10095
/* initialize a poll-only continuation request */
101-
MPIX_Continue_init(0, 0, &cont_req2, info);
96+
MPIX_Continue_init(MPIX_CONT_POLL_ONLY, MPI_UNDEFINED, MPI_INFO_NULL, &cont_req2);
10297

10398
MPI_Start(&cont_req2);
10499

@@ -107,7 +102,7 @@ int main(int argc, char *argv[])
107102
MPIX_Continue(&reqs[0], &complete_cnt_cb, &cb_cnt, 0, MPI_STATUS_IGNORE, cont_req);
108103

109104
MPI_Isend(&val, 1, MPI_INT, rank, 1001, MPI_COMM_WORLD, &reqs[1]);
110-
MPIX_Continue(&reqs[1], &complete_cnt_cb, &cb_cnt, 0, MPI_STATUS_IGNORE, cont_req2);
105+
MPIX_Continue(&reqs[1], &complete_cnt_cb, &cb_cnt, MPIX_CONT_DEFER_COMPLETE, MPI_STATUS_IGNORE, cont_req2);
111106

112107
MPI_Wait(&cont_req, MPI_STATUS_IGNORE);
113108
assert(reqs[0] == MPI_REQUEST_NULL && reqs[1] == MPI_REQUEST_NULL);

0 commit comments

Comments
 (0)