From: heister Date: Sat, 2 Nov 2013 19:40:03 +0000 (+0000) Subject: make quick tests work, add an mpi test X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfabfe20b2f7a0f66f71cae170b0ea91690db9f6;p=dealii-svn.git make quick tests work, add an mpi test git-svn-id: https://svn.dealii.org/trunk@31514 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/tests/quick_tests/CMakeLists.txt b/deal.II/tests/quick_tests/CMakeLists.txt index a88ff5d18f..4c0791b5d9 100644 --- a/deal.II/tests/quick_tests/CMakeLists.txt +++ b/deal.II/tests/quick_tests/CMakeLists.txt @@ -20,6 +20,7 @@ ENABLE_TESTING() + FOREACH(_build ${DEAL_II_BUILD_TYPES}) STRING(TOLOWER ${_build} _build_lowercase) @@ -32,10 +33,37 @@ FOREACH(_build ${DEAL_II_BUILD_TYPES}) DEAL_II_INSOURCE_SETUP_TARGET(${_target} ${_build}) ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK - COMMAND ${_target} > ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK 2>&1 && echo "${_target}: PASSED." || (rm ${_target}-OK && exit 1) + COMMAND ${_target} > ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK 2>&1 || (rm ${_target}-OK && exit 1) + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + ADD_CUSTOM_TARGET(${_target}.run + DEPENDS ${_target} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK + COMMAND echo "${_target}: PASSED.") + + ADD_TEST(NAME ${_target} + COMMAND ${CMAKE_COMMAND} -DTRGT=${_target}.run -DTEST=${_target} + -DDEAL_II_BINARY_DIR=${CMAKE_BINARY_DIR} + -P ${CMAKE_SOURCE_DIR}/cmake/scripts/run_test.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + SET_TESTS_PROPERTIES(${_target} PROPERTIES LABEL "sanity checks") + + + # test MPI + SET(_target mpi.${_build_lowercase}) + + ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL mpi.cc) + DEAL_II_INSOURCE_SETUP_TARGET(${_target} ${_build}) + + ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK + COMMAND mpirun -n 2 ${_target} > ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK 2>&1 && echo "${_target}: PASSED." || (rm ${_target}-OK && exit 1) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - ADD_CUSTOM_TARGET(${_target}.run DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK) + ADD_CUSTOM_TARGET(${_target}.run + DEPENDS ${_target} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK + COMMAND echo "${_target}: PASSED.") ADD_TEST(NAME ${_target} COMMAND ${CMAKE_COMMAND} -DTRGT=${_target}.run -DTEST=${_target} diff --git a/deal.II/tests/quick_tests/mpi.cc b/deal.II/tests/quick_tests/mpi.cc new file mode 100644 index 0000000000..33028246d3 --- /dev/null +++ b/deal.II/tests/quick_tests/mpi.cc @@ -0,0 +1,70 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// test that MPI is working correctly. Note that this test expects to +// be executed with exactly two threads. + +#include +#include +#include +#include +#include + +int main(int argc, char *argv[] ) +{ + MPI_Init( &argc, &argv ); + + int myrank, nproc; + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (nproc != 2) + { + std::cerr << "ERROR: process does not see nproc=2!" << std::endl; + return -1; + } + + MPI_Barrier(MPI_COMM_WORLD); + + int err; + int value = myrank; + + if (myrank==1) + err = MPI_Send(&value, 1, MPI_INT, 0, 1, MPI_COMM_WORLD); + else if (myrank==0) + err = MPI_Recv(&value, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, NULL); + + if (myrank==0 && value!=1) + { + std::cerr << "ERROR: MPI_Send/Recv did not work!" << std::endl; + return -1; + } + + value = 1; + int output = 0; + + MPI_Allreduce(&value, &output, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + if (output != nproc) + { + std::cerr << "ERROR: MPI_Allreduce doesn't seem to work!" << std::endl; + return -1; + } + + // we need this, otherwise gcc will not link against deal.II + dealii::Triangulation<2> test; + + MPI_Finalize(); +}