Skip to content

Commit

Permalink
Merge pull request #1882 from JasonRuonanWang/insitumpi
Browse files Browse the repository at this point in the history
added exceptions in insitumpi
  • Loading branch information
JasonRuonanWang authored Nov 22, 2019
2 parents 4abd2f4 + 035f07d commit ed5e80f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
6 changes: 6 additions & 0 deletions source/adios2/engine/insitumpi/InSituMPIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ InSituMPIReader::InSituMPIReader(IO &io, const std::string &name,
m_ReaderNproc = m_Comm.Size();
m_RankDirectPeers =
insitumpi::AssignPeers(m_ReaderRank, m_ReaderNproc, m_RankAllPeers);
if (m_RankAllPeers.empty())
{
throw(std::runtime_error(
"no writers are found. Make sure that the writer and reader "
"applications are launched as one application in MPMD mode."));
}
if (m_Verbosity == 5)
{
std::cout << "InSituMPI Reader " << m_ReaderRank << " Open(" << m_Name
Expand Down
6 changes: 6 additions & 0 deletions source/adios2/engine/insitumpi/InSituMPIWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ InSituMPIWriter::InSituMPIWriter(IO &io, const std::string &name,
m_CommWorld, true, (m_BP3Serializer.m_RankMPI == 0), m_GlobalRank,
m_RankDirectPeers);
m_AmIPrimaryContact = static_cast<bool>(primaryContact);
if (m_RankAllPeers.empty())
{
throw(std::runtime_error(
"No writers are found. Make sure that the writer and reader "
"applications are launched as one application in MPMD mode."));
}
if (m_Verbosity == 5)
{
std::cout << "InSituMPI Writer " << m_WriterRank << " Open(" << m_Name
Expand Down
1 change: 1 addition & 0 deletions testing/adios2/engine/insitumpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
#------------------------------------------------------------------------------#

gtest_add_tests_helper(FunctionAssignPeers TRUE InSituMPI Engine.InSituMPI. "")
gtest_add_tests_helper(MPMDExceptions TRUE InSituMPI Engine.InSituMPI. "")
58 changes: 58 additions & 0 deletions testing/adios2/engine/insitumpi/TestInSituMPIMPMDExceptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*/
#include <cstdint>
#include <cstring>

#include <iostream>
#include <stdexcept>
#include <vector>

#include <adios2.h>

#include <gtest/gtest.h>

#ifdef ADIOS2_HAVE_MPI
#include "mpi.h"
#endif

class InSituMPIMPMDExceptions : public ::testing::Test
{
public:
InSituMPIMPMDExceptions() = default;
};

TEST_F(InSituMPIMPMDExceptions, Writer)
{
adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON);
adios2::IO dataManIO = adios.DeclareIO("Test");
dataManIO.SetEngine("insitumpi");
EXPECT_THROW(dataManIO.Open("filename", adios2::Mode::Write),
std::runtime_error);
}

TEST_F(InSituMPIMPMDExceptions, Reader)
{
adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON);
adios2::IO dataManIO = adios.DeclareIO("Test");
dataManIO.SetEngine("insitumpi");
EXPECT_THROW(dataManIO.Open("filename", adios2::Mode::Read),
std::runtime_error);
}

//******************************************************************************
// main
//******************************************************************************

int main(int argc, char **argv)
{
MPI_Init(nullptr, nullptr);

int result;
::testing::InitGoogleTest(&argc, argv);
result = RUN_ALL_TESTS();

MPI_Finalize();
return result;
}
3 changes: 2 additions & 1 deletion testing/adios2/engine/staging-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ endforeach()
# Setup tests for InSituMPI engine
#
if(ADIOS2_HAVE_MPI)
set (INSITU_TESTS ${ALL_SIMPLE_TESTS})
set (SIMPLE_IMPI_TESTS "1x1;TimeoutOnOpen;1x1.Modes;1x1.Attrs;1x1.Local;1x1.SharedNothing;1x1.SharedIO;1x1.SharedVar;1x1.SharedNothingSync;1x1.SharedIOSync;1x1.SharedVarSync;2x1.SharedNothing;2x1.SharedIO;2x1.SharedVar;2x1.SharedNothingSync;2x1.SharedIOSync;2x1.SharedVarSync")
set (INSITU_TESTS ${SIMPLE_IMPI_TESTS} ${SIMPLE_FORTRAN_TESTS} ${SIMPLE_MPI_TESTS} ${SIMPLE_ZFP_TESTS})
# Tests that don't work for InSitu
list (REMOVE_ITEM INSITU_TESTS "TimeoutOnOpen" "1x1.Modes" "1x1.Attrs")
# Local Vars don't work for InSitu
Expand Down

0 comments on commit ed5e80f

Please sign in to comment.