Skip to content

Commit

Permalink
fix for replay mpi defs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Sep 9, 2024
1 parent 91a7faf commit caaab3d
Showing 1 changed file with 65 additions and 54 deletions.
119 changes: 65 additions & 54 deletions src/utilities/replay/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,70 +158,81 @@ void trim(std::string &s)

void load_actions(const std::string &file_name, int mpi_comm_id, conduit::Node &actions)
{
int comm_size = 1;
int rank = 0;

#if defined(ASCENT_REPLAY_MPI)
if(mpi_comm_id == -1)
{
// do nothing, an error will be thrown later
// so we can respect the exception handling
return;
}
MPI_Comm mpi_comm = MPI_Comm_f2c(mpi_comm_id);
MPI_Comm_size(mpi_comm, &comm_size);
MPI_Comm_rank(mpi_comm, &rank);
int comm_size = 1;
int rank = 0;
#ifdef ASCENT_REPLAY_MPI
if(mpi_comm_id == -1)
{
// do nothing, an error will be thrown later
// so we can respect the exception handling
return;
}
MPI_Comm mpi_comm = MPI_Comm_f2c(mpi_comm_id);
MPI_Comm_size(mpi_comm, &comm_size);
MPI_Comm_rank(mpi_comm, &rank);
#endif

bool has_file = false;

if(rank==0)
{
has_file = conduit::utils::is_file(file_name);
}

#ifdef ASCENT_MPI_ENABLED
MPI_Bcast(&has_file, 1, MPI_BOOL, 0, mpi_comm);
int has_file = 0;
if(rank == 0 && conduit::utils::is_file(file_name))
{
has_file = 1;
}
#ifdef ASCENT_REPLAY_MPI
MPI_Bcast(&has_file, 1, MPI_INT, 0, mpi_comm);
#endif
if(has_file == 0)
{
return;
}

bool actions_file_valid = false;
std::string file_load_error_msg = "";
int actions_file_valid = 0;
std::string emsg = "";

if(rank==0 && has_file)
{
try
if(rank == 0)
{
std::string curr, next;
conduit::utils::rsplit_string(file_name, ".", curr, next);
std::string curr,next;

std::string protocol = curr=="yaml" ? "yaml" : "json";
actions.load(file_name, protocol);
actions_file_valid = true;
}
catch(conduit::Error &e)
{
file_load_error_msg = e.message();
actions_file_valid = false;
std::string protocol = "json";
// if file ends with yaml, use yaml as proto
conduit::utils::rsplit_string(file_name,
".",
curr,
next);

if(curr == "yaml")
{
protocol = "yaml";
}

try
{
conduit::Node file_node;
file_node.load(file_name, protocol);

actions = file_node;

actions_file_valid = 1;
}
catch(conduit::Error &e)
{
// failed to open or parse the actions file
actions_file_valid = 0;
emsg = e.message();
}
}
}

#ifdef ASCENT_MPI_ENABLED
MPI_Bcast(&actions_file_valid, 1, MPI_BOOL, 0, mpi_comm);
#ifdef ASCENT_REPLAY_MPI
// make sure all ranks error if the parsing on rank 0 failed.
MPI_Bcast(&actions_file_valid, 1, MPI_INT, 0, mpi_comm);
#endif

if(!has_file)
{
ASCENT_WARN("Actions file not found: " << file_name);
}
else if(!actions_file_valid)
{
// Raise Error
ASCENT_ERROR("Failed to load actions file: " << file_name
<< "\n" << file_load_error_msg);
}

#ifdef ASCENT_MPI_ENABLED
relay::mpi::broadcast_using_schema(node, 0, mpi_comm);
if(actions_file_valid == 0)
{
// Raise Error
ASCENT_ERROR("Failed to load actions file: " << file_name
<< "\n" << emsg);
}
#ifdef ASCENT_REPLAY_MPI
conduit::relay::mpi::broadcast_using_schema(actions, 0, mpi_comm);
#endif
}

Expand Down

0 comments on commit caaab3d

Please sign in to comment.