Skip to content

Commit

Permalink
by calling ParsecRuntime::initialize_with_existing_context(ctx) befor…
Browse files Browse the repository at this point in the history
…e madness::initialize can use existing parsec context
  • Loading branch information
evaleev committed Jul 17, 2023
1 parent 71514c5 commit 16fd3d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/madness/world/parsec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,25 @@ namespace madness {
const parsec_task_class_t* madness_parsec_tc_array[]= {&(madness::madness_parsec_tc), NULL};
parsec_taskpool_t *ParsecRuntime::tp = nullptr;
parsec_context_t *ParsecRuntime::ctx = nullptr;
std::optional<bool> ParsecRuntime::made_new_ctx{};
parsec_execution_stream_t *ParsecRuntime::madness_comm_thread_es = nullptr;
#ifdef PARSEC_PROF_TRACE
int ParsecRuntime::taskpool_profiling_array[2];
#endif
ParsecRuntime::ParsecRuntime(int nb_threads) {
assert(ctx == nullptr);
/* Scheduler init*/
int argc = 1;
char *argv[2] = { (char *)"madness-app", nullptr };
char **pargv = (char **)argv;
ctx = parsec_init(nb_threads, &argc, &pargv);
MPI_Comm parsec_comm = MPI_COMM_SELF;
parsec_remote_dep_set_ctx(ctx, (intptr_t)parsec_comm);
if (ctx == nullptr) {
/* Scheduler init*/
int argc = 1;
char *argv[2] = {(char *)"madness-app", nullptr};
char **pargv = (char **)argv;
ctx = parsec_init(nb_threads, &argc, &pargv);
MPI_Comm parsec_comm = MPI_COMM_SELF;
parsec_remote_dep_set_ctx(ctx, (intptr_t)parsec_comm);
made_new_ctx = true;
}
else {
made_new_ctx = false;
}
tp = PARSEC_OBJ_NEW(parsec_taskpool_t);
tp->taskpool_name = strdup("MADNESS taskpool");
tp->devices_index_mask = PARSEC_DEVICES_ALL;
Expand Down Expand Up @@ -194,17 +200,25 @@ namespace madness {
}
}

void ParsecRuntime::initialize_with_existing_context(parsec_context_t* ctx) {
ParsecRuntime::ctx = ctx;
}


ParsecRuntime::~ParsecRuntime() {
parsec_context_wait(ctx);
parsec_taskpool_free(tp);
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
assert(made_new_ctx.has_value());
if (made_new_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
* actually freed during parsec_fini. Just need to free memory allocated to store it. */
free(madness_comm_thread_es);
madness_comm_thread_es = nullptr;
free(madness_comm_thread_es);
madness_comm_thread_es = nullptr;
}
ctx = nullptr;
}
ctx = nullptr;
}

parsec_context_t *ParsecRuntime::context() { return ctx; }
Expand Down
3 changes: 3 additions & 0 deletions src/madness/world/parsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#include <parsec/scheduling.h>

#include <iostream>
#include <optional>

namespace madness{
class PoolTaskInterface;

class ParsecRuntime {
private:
static parsec_context_t *ctx;
static std::optional<bool> made_new_ctx;
static parsec_taskpool_t *tp;
static parsec_execution_stream_t *madness_comm_thread_es;
#ifdef PARSEC_PROF_TRACE
Expand All @@ -31,6 +33,7 @@ namespace madness{
~ParsecRuntime();

static parsec_context_t* context();
static void initialize_with_existing_context(parsec_context_t* ctx);
static parsec_execution_stream_t *execution_stream();
static void schedule(PoolTaskInterface* task);
static int test();
Expand Down

0 comments on commit 16fd3d5

Please sign in to comment.