Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to dash::Future #451

Merged
merged 17 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dart-if/include/dash/dart/if/dart_communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,18 @@ dart_ret_t dart_testall_local(
size_t n,
int32_t * result) DART_NOTHROW;


/**
* Free the handle without testing or waiting for completion of the operation.
*
* \param handle Pointer to the handle to free.
*
* \return \c DART_OK on success, any other of \ref dart_ret_t otherwise.
*
*/
dart_ret_t dart_handle_free(
dart_handle_t * handle) DART_NOTHROW;

/** \} */

/**
Expand Down
10 changes: 10 additions & 0 deletions dart-impl/mpi/src/dart_communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,16 @@ dart_ret_t dart_testall_local(
return DART_OK;
}

dart_ret_t dart_handle_free(
dart_handle_t * handleptr)
{
if (handleptr != NULL && *handleptr != DART_HANDLE_NULL) {
free(*handleptr);
*handleptr = DART_HANDLE_NULL;
}
return DART_OK;
}

/* -- Dart collective operations -- */

static int _dart_barrier_count = 0;
Expand Down
71 changes: 50 additions & 21 deletions dash/include/dash/Future.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ template<typename ResultT>
class Future
{
private:
typedef Future<ResultT> self_t;
typedef std::function<ResultT (void)> func_t;
typedef Future<ResultT> self_t;
typedef std::function<ResultT (void)> get_func_t;
typedef std::function<bool (ResultT*)> test_func_t;
typedef std::function<void (void)> destroy_func_t;

private:
func_t _func;
ResultT _value;
bool _ready = false;
bool _has_func = false;
get_func_t _get_func;
test_func_t _test_func;
destroy_func_t _destroy_func;
ResultT _value;
bool _ready = false;

public:
// For ostream output
Expand All @@ -33,32 +36,55 @@ class Future
const Future<ResultT_> & future);

public:

Future()
: _ready(false),
_has_func(false)
: _ready(false)
{ }

Future(ResultT & result)
: _value(result),
_ready(true)
{ }

Future(const func_t & func)
: _func(func),
_ready(false),
_has_func(true)
Future(const get_func_t & func)
: _get_func(func),
_ready(false)
{ }


Future(
const get_func_t & get_func,
const test_func_t & test_func,
const destroy_func_t & destroy_func)
: _get_func(get_func),
_test_func(test_func),
_destroy_func(destroy_func),
_ready(false)
{ }

Future(
const self_t & other)
: _func(other._func),
: _get_func(other._get_func),
_test_func(other._test_func),
_destroy_func(other._destroy_func),
_value(other._value),
_ready(other._ready),
_has_func(other._has_func)
_ready(other._ready)
{ }

~Future() {
if (_destroy_func) {
_destroy_func();
}
}

Future<ResultT> & operator=(const self_t & other)
{
if (this != &other) {
_func = other._func;
_value = other._value;
_ready = other._ready;
_has_func = other._has_func;
_get_func = other._get_func;
_test_func = other._test_func;
_destroy_func = other._destroy_func;
_value = other._value;
_ready = other._ready;
}
return *this;
}
Expand All @@ -69,19 +95,22 @@ class Future
if (_ready) {
return;
}
if (!_has_func) {
if (!_get_func) {
DASH_LOG_ERROR("Future.wait()", "No function");
DASH_THROW(
dash::exception::RuntimeError,
"Future not initialized with function");
}
_value = _func();
_value = _get_func();
_ready = true;
DASH_LOG_TRACE_VAR("Future.wait >", _ready);
}

bool test() const
{
if (!_ready && _test_func) {
_ready = _test_func(&_value);
}
return _ready;
}

Expand Down
Loading