Skip to content

Commit

Permalink
provide access to mpi comm handle for python extracts (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Jan 25, 2018
1 parent b56228d commit ab3c4cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/ascent/runtimes/ascent_main_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ AscentRuntime::ConvertExtractToFlow(const conduit::Node &extract,
// read script only on rank 0
if(rank == 0)
{
ostringstream py_src;
std::string script_fname = params["file"].as_string();
ifstream ifs(script_fname.c_str());

ostringstream py_src;

py_src << "# script from: " << script_fname << std::endl;
copy(istreambuf_iterator<char>(ifs),
istreambuf_iterator<char>(),
Expand All @@ -449,6 +449,17 @@ AscentRuntime::ConvertExtractToFlow(const conduit::Node &extract,
params.remove("file");
params["source"] = n_py_src;
}

// inject helper that provides the mpi comm handle
ostringstream py_src_final;
py_src_final << "# ascent mpi comm helper function" << std::endl
<< "def ascent_mpi_comm_id():" << std::endl
<< " return " << comm_id << std::endl
<< std::endl
<< params["source"].as_string(); // now include user's script

params["source"] = py_src_final.str();

#endif

// todo, inspect args, if passed via file, read on root proc and broadcast
Expand Down
8 changes: 7 additions & 1 deletion src/tests/ascent/t_ascent_mpi_python_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ using ascent::Ascent;

std::string py_script = "\n"
"v = input()\n"
"print(v['state'])\n";
"print(v['state'])\n"
"\n"
"from mpi4py import MPI\n"
"print(ascent_mpi_comm_id())\n"
"comm = MPI.Comm.f2py(ascent_mpi_comm_id())\n"
"print('COMM SIZE = {}'.format(comm.Get_size()))\n"
"\n";

//-----------------------------------------------------------------------------
TEST(ascent_mpi_runtime, test_pyhton_script_extract_src)
Expand Down

0 comments on commit ab3c4cc

Please sign in to comment.