Skip to content
Snippets Groups Projects
Commit ef60ae5d authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added MpiCommunicatorTest.

parent 1ed0ceb2
No related branches found
No related tags found
1 merge request!34Runge kutta
ADD_SUBDIRECTORY( Communicators )
ADD_SUBDIRECTORY( Containers )
ADD_SUBDIRECTORY( Functions )
ADD_SUBDIRECTORY( Matrices )
......
if( ${BUILD_MPI} )
ADD_EXECUTABLE( MpiCommunicatorTest MpiCommunicatorTest.cpp )
TARGET_COMPILE_OPTIONS( MpiCommunicatorTest PRIVATE ${CXX_TESTS_FLAGS} )
TARGET_LINK_LIBRARIES( MpiCommunicatorTest ${GTEST_BOTH_LIBRARIES} )
SET( mpi_test_parameters -np 4 -H localhost:4 "${EXECUTABLE_OUTPUT_PATH}/MpiCommunicatorTest${CMAKE_EXECUTABLE_SUFFIX}" )
ADD_TEST( NAME MpiCommunicatorTest COMMAND "mpirun" ${mpi_test_parameters})
endif()
/***************************************************************************
MpiCommunicatorTest.h - description
-------------------
begin : Jul 10, 2019
copyright : (C) 2019 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#ifdef HAVE_GTEST
#include "gtest/gtest.h"
#include <TNL/Communicators/MpiCommunicator.h>
using namespace TNL;
using namespace TNL::Communicators;
// test fixture for typed tests
template< typename Real >
class MpiCommunicatorTest : public ::testing::Test
{
protected:
using RealType = Real;
using CommunicatorType = MpiCommunicator;
};
// types for which MpiCommunicatorTest is instantiated
using MpiCommunicatorTypes = ::testing::Types<
short,
int,
long,
float,
double
>;
TYPED_TEST_CASE( MpiCommunicatorTest, MpiCommunicatorTypes );
TYPED_TEST( MpiCommunicatorTest, allReduce )
{
using RealType = typename TestFixture::RealType;
using CommunicatorType = typename TestFixture::CommunicatorType;
RealType a = CommunicatorType::GetRank();
RealType b = 0;
CommunicatorType::Allreduce( &a, &b, 1, MPI_MAX, MPI_COMM_WORLD );
EXPECT_EQ( b, CommunicatorType::GetSize() - 1 );
}
#endif // HAVE_GTEST
#include "../main_mpi.h"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment