]> https://gitweb.dealii.org/ - dealii.git/commitdiff
make quick tests work, add an mpi test
authorTimo Heister <timo.heister@gmail.com>
Sat, 2 Nov 2013 19:40:03 +0000 (19:40 +0000)
committerTimo Heister <timo.heister@gmail.com>
Sat, 2 Nov 2013 19:40:03 +0000 (19:40 +0000)
git-svn-id: https://svn.dealii.org/trunk@31514 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/tests/quick_tests/CMakeLists.txt
deal.II/tests/quick_tests/mpi.cc [new file with mode: 0644]

index a88ff5d18fc5c3f669133a4ef501c810631f2f2f..4c0791b5d9dcb91000658b73c9677e149d36048c 100644 (file)
@@ -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 (file)
index 0000000..3302824
--- /dev/null
@@ -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 <deal.II/grid/tria.h>
+#include <stdio.h>
+#include <sched.h>
+#include <mpi.h>
+#include <iostream>
+
+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();
+}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.