Commit 30ec7725 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added mona_wait_any

parent 4d45959b
......@@ -115,6 +115,7 @@ static void parse_options(int argc, char** argv, options_t* options) {
options->iterations = 1024;
options->msg_size = 128;
options->transport = (char*)default_transport;
options->method = NULL;
while((c = getopt(argc, argv, "i:s:m:t:")) != -1) {
switch (c)
......@@ -151,7 +152,7 @@ int main(int argc, char** argv) {
int rank, size;
options_t options;
options_t options = { 0 };
parse_options(argc, argv, &options);
MPI_Init(&argc, &argv);
......@@ -164,10 +165,10 @@ int main(int argc, char** argv) {
MPI_Abort(MPI_COMM_WORLD, -1);
}
if(strcmp(options.method, "mpi") == 0) {
if(options.method && strcmp(options.method, "mpi") == 0) {
run_mpi_benchmark(&options);
} else if(strcmp(options.method, "mona") == 0) {
run_mona_benchmark(&options);
} else if(options.method && strcmp(options.method, "mona") == 0) {
run_mona_benchmark(&options);
} else {
if(rank == 0) {
fprintf(stderr, "Unknown benchmark method %s\n", options.method);
......
......@@ -1241,7 +1241,7 @@ const char* mona_error_to_string(int errnum);
na_return_t mona_wait(mona_request_t req);
/**
* Test ifthe provided request has completed.
* Test if the provided request has completed.
*
* \param req [IN] request to test
* \param flag [OUT] 1 if request completed, 0 otherwise
......@@ -1250,6 +1250,24 @@ na_return_t mona_wait(mona_request_t req);
*/
int mona_test(mona_request_t req, int* flag);
/**
* Block until one of the provided requests completes.
* When a request completes, index is set to the corresponding
* index in the array of requests. The completed request will be freed
* and reqs[index] will be changed to MONA_REQUEST_NULL.
*
* The provided array may safely contain MONA_REQUEST_NULL objects,
* which will be ignored. If all the requests are MONA_REQUEST_NULL,
* index will be set to count and the function will return immediately.
*
* @param count Number of requests in the array
* @param reqs Array of requests
* @param index Index of the request that completed
*
* @return NA_SUCCESS or corresponding NA error code
*/
na_return_t mona_wait_any(size_t count, mona_request_t* reqs, size_t* index);
#ifdef __cplusplus
}
#endif
......
/*
* (C) 2020 The University of Chicago
*
*
* See COPYRIGHT in top-level directory.
*/
#include "mona-types.h"
......@@ -444,6 +444,40 @@ int mona_test(mona_request_t req, int* flag)
return ABT_eventual_test(req->eventual, NULL, flag);
}
na_return_t mona_wait_any(size_t count, mona_request_t* reqs, size_t* index)
{
// XXX this is an active loop, we should change it
// when Argobots provide an ABT_eventual_wait_any
size_t i;
int ret;
int flag = 0;
int has_pending_requests;
try_again:
has_pending_requests = 0;
for(i = 0; i < count; i++) {
if(reqs[i] == MONA_REQUEST_NULL)
continue;
else
has_pending_requests = 1;
ret = mona_test(reqs[i], &flag);
if(ret != ABT_SUCCESS) {
*index = i;
return NA_RETURN_MAX;
}
if(flag) {
*index = i;
mona_request_t req = reqs[i];
reqs[i] = MONA_REQUEST_NULL;
return mona_wait(req);
}
}
ABT_thread_yield();
if(has_pending_requests)
goto try_again;
*index = count;
return NA_SUCCESS;
}
static int mona_callback(const struct na_cb_info *info)
{
na_return_t na_ret = info->ret;
......@@ -1066,7 +1100,7 @@ na_return_t mona_recv_nc(
char* p = msg->buffer + header_size;
if(*p == HL_MSG_SMALL) { // small message, embedded data
p += 1;
recv_size -= header_size + 1;
na_size_t remaining_size = recv_size;
......@@ -1258,7 +1292,7 @@ na_return_t mona_recv_mem(
// and the attributes are recv_size, recv_tag, and recv_addr
char* p = msg->buffer + header_size + 1;
na_size_t mem_handle_size;
na_size_t remote_data_size;
na_size_t remote_offset;
......@@ -1529,7 +1563,7 @@ na_return_t mona_msg_irecv_unexpected(
{
mona_request_t tmp_req = get_req_from_cache(mona);
na_return_t na_ret = mona_msg_irecv_unexpected_internal(
mona, buf, buf_size, plugin_data,
mona, buf, buf_size, plugin_data,
source_addr, tag, size, op_id, tmp_req);
if(na_ret != NA_SUCCESS) {
return_req_to_cache(mona, tmp_req);
......@@ -1690,7 +1724,7 @@ na_return_t mona_msg_irecv_expected(
na_op_id_t *op_id,
mona_request_t* req)
{
mona_request_t tmp_req = get_req_from_cache(mona);
mona_request_t tmp_req = get_req_from_cache(mona);
na_return_t na_ret = mona_msg_irecv_expected_internal(
mona, buf, buf_size, plugin_data, source_addr, source_id, tag, op_id, tmp_req);
if(na_ret != NA_SUCCESS) {
......@@ -1955,7 +1989,7 @@ na_return_t mona_iget(
}
// ------------------------------------------------------------------------------------
// Other functions
// Other functions
// ------------------------------------------------------------------------------------
int mona_poll_get_fd(mona_instance_t mona)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment