]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Revert "Remove the test affinity.cc."
authorTimo Heister <timo.heister@gmail.com>
Mon, 31 Aug 2015 13:10:12 +0000 (09:10 -0400)
committerTimo Heister <timo.heister@gmail.com>
Mon, 31 Aug 2015 13:35:32 +0000 (09:35 -0400)
This reverts commit 384d5c60b376a25c4e7b65b1e4c5364767dd449d.

tests/quick_tests/CMakeLists.txt
tests/quick_tests/affinity.cc [new file with mode: 0644]
tests/quick_tests/run.cmake

index aa5c7425c1a9fe21938bfd0d355558df86c6ee39..1647fc7835d35f442e70fb7085a993bf7ece2d91 100644 (file)
@@ -80,6 +80,11 @@ FOREACH(_build ${DEAL_II_BUILD_TYPES})
   make_quicktest("step" ${_build} "")
 ENDFOREACH()
 
+# Test whether thread affinity is well behaved
+IF (DEAL_II_WITH_THREADS)
+make_quicktest("affinity" ${_mybuild} "")
+ENDIF()
+
 # Test if MPI is configured correctly
 IF (DEAL_II_WITH_MPI)
   make_quicktest("mpi" ${_mybuild} 2)
diff --git a/tests/quick_tests/affinity.cc b/tests/quick_tests/affinity.cc
new file mode 100644 (file)
index 0000000..24bb167
--- /dev/null
@@ -0,0 +1,81 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+#include <deal.II/grid/tria.h>
+#include <deal.II/base/multithread_info.h>
+#include <stdio.h>
+
+#if defined(__linux__)
+#include <sched.h>
+#include <sys/sysinfo.h>
+#endif
+
+bool getaffinity(unsigned int &bits_set,unsigned int &mask)
+{
+  bits_set = 0;
+  mask = 0x00;
+  
+#if defined(__linux__)
+  cpu_set_t my_set;
+  CPU_ZERO(&my_set);
+
+  unsigned int len = sizeof(my_set);
+  int   ret = sched_getaffinity(0, len, &my_set);
+
+  if (ret!=0)
+    {
+      printf("sched_getaffinity() failed, return value: %d\n", ret);
+      return false;
+    }
+  for (int i=0;i<CPU_SETSIZE;++i)
+    bits_set += CPU_ISSET(i,&my_set);
+
+  mask = *(int*)(&my_set);
+#else
+  // sadly we don't have an implementation
+  // for mac/windows
+#endif
+  return true;
+}
+
+
+int main ()
+{
+  // we need this, otherwise gcc will not link against deal.II
+  dealii::Triangulation<2> test;
+
+  unsigned int bits_set, mask;
+  if (!getaffinity(bits_set, mask))
+    return 1;
+
+  unsigned int nprocs = dealii::MultithreadInfo::n_cores();
+  unsigned int tbbprocs = dealii::MultithreadInfo::n_threads();
+  printf("aff_ncpus=%d, mask=%08X, nprocs=%d, tbb_threads=%d\n",
+        bits_set, mask, nprocs, tbbprocs );
+
+  if (bits_set !=0  && bits_set!=nprocs)
+    {
+      printf("Warning: sched_getaffinity() returns that we can only use %d out of %d CPUs.\n",bits_set, nprocs);
+      return 2;
+    }
+  if (nprocs != tbbprocs)
+    {
+      printf("Warning: for some reason TBB only wants to use %d out of %d CPUs.\n",
+            tbbprocs, nprocs);
+      return 3;
+    }
+  
+  return 0;
+}
index 77527d110480e9db58d4b1bd9ff79381c99b72d1..e941ff0b6582eb80d757326c84e7be7896a74d42 100644 (file)
@@ -1,6 +1,6 @@
 ## ---------------------------------------------------------------------
 ##
-## Copyright (C) 2015 by the deal.II authors
+## Copyright (C) 2013 by the deal.II authors
 ##
 ## This file is part of the deal.II library.
 ##
@@ -34,6 +34,15 @@ to the mailing list linked at http://www.dealii.org\n"
     )
 
   FOREACH(test ${ALL_TESTS})  
+    IF (${test} MATCHES "^affinity" AND NOT EXISTS ${test}-OK)
+      MESSAGE("
+The affinity test can fail when you are linking in a library like BLAS
+which uses OpenMP. Even without calling any BLAS functions, OpenMP messes
+with the thread affinity which causes TBB to run single-threaded only. You
+can fix this by exporting OMP_NUM_THREADS=1.\n"
+        )
+    ENDIF()
+
     IF (${test} MATCHES "^step-petsc" AND NOT EXISTS ${test}-OK)
       MESSAGE("
 Additional information about PETSc issues is available

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.