Skip to content

Commit

Permalink
Update to latest version of parsec; Properly wait on the parsec taskp…
Browse files Browse the repository at this point in the history
…ool only if the MADNESS library did not create the parsec context (required to share the parsec context with other libraries).
  • Loading branch information
therault committed Oct 30, 2023
1 parent 4f7d30b commit c3fe51d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion external/versions.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set(MADNESS_TRACKED_PARSEC_TAG 9fc74b6f165605a133125d8a5b62cf55642c1907)
set(MADNESS_TRACKED_PARSEC_TAG 6fd959e4a8d2dad8b701d0b83cd85b372f1a306b)
18 changes: 16 additions & 2 deletions src/madness/world/parsec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,20 @@ namespace madness {
return PARSEC_SUCCESS;
}

static int parsec_madness_taskpool_leave_wait(parsec_taskpool_t* tp, void*_)
static int parsec_madness_taskpool_leave_wait(parsec_taskpool_t* tp, void*_b)
{
assert(tp != NULL);
assert(NULL != tp->tdm.module);
(void)_;

bool restart = *(bool*)_b;

if(!restart) {
/* This is the final taskpool_wait: we don't want to restart the termination
* detection and re-attach to the context. */
return PARSEC_SUCCESS;
}

/* Reset termination detector, so we can start adding tasks again */
tp->tdm.module->monitor_taskpool(tp, parsec_taskpool_termination_detected);
tp->tdm.module->taskpool_set_nb_tasks(tp, 0);
Expand All @@ -156,6 +164,7 @@ namespace madness {
parsec_context_t *ParsecRuntime::ctx = nullptr;
std::optional<bool> ParsecRuntime::made_new_ctx{};
parsec_execution_stream_t *ParsecRuntime::madness_comm_thread_es = nullptr;
bool ParsecRuntime::parsec_restart_taskpool = true;
#ifdef PARSEC_PROF_TRACE
int ParsecRuntime::taskpool_profiling_array[2];
#endif
Expand All @@ -173,6 +182,8 @@ namespace madness {
else {
made_new_ctx = false;
}
parsec_restart_taskpool = true;

tp = PARSEC_OBJ_NEW(parsec_taskpool_t);
tp->taskpool_name = strdup("MADNESS taskpool");
tp->devices_index_mask = PARSEC_DEVICES_ALL;
Expand All @@ -181,6 +192,7 @@ namespace madness {
tp->update_nb_runtime_task = madness_parsec_update_runtime_nb_tasks;
tp->on_enter_wait = parsec_madness_taskpool_enter_wait;
tp->on_leave_wait = parsec_madness_taskpool_leave_wait;
tp->on_leave_wait_data = &parsec_restart_taskpool;

parsec_termdet_open_module(tp, (char*)"local");
tp->tdm.module->monitor_taskpool(tp, parsec_taskpool_termination_detected);
Expand Down Expand Up @@ -208,10 +220,12 @@ namespace madness {


ParsecRuntime::~ParsecRuntime() {
parsec_context_wait(ctx);
parsec_restart_termination_detection = false;
parsec_taskpool_wait(tp);
parsec_taskpool_free(tp);
assert(made_new_ctx.has_value());
if (*made_new_ctx) {
parsec_context_wait(ctx);
parsec_fini(&ctx);
if (nullptr != madness_comm_thread_es) {
/* madness_comm_thread_es is just a copy of ES[0]. Resources (including es->profiling_es) are
Expand Down
1 change: 1 addition & 0 deletions src/madness/world/parsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace madness{
static parsec_context_t *ctx;
static std::optional<bool> made_new_ctx;
static parsec_taskpool_t *tp;
static bool parsec_restart_taskpool;
static parsec_execution_stream_t *madness_comm_thread_es;
#ifdef PARSEC_PROF_TRACE
static int taskpool_profiling_array[2];
Expand Down

0 comments on commit c3fe51d

Please sign in to comment.