]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
update affinity quicktest to work with 1 cpu and on mac
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 Feb 2014 20:35:58 +0000 (20:35 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 Feb 2014 20:35:58 +0000 (20:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@32415 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/tests/quick_tests/CMakeLists.txt
deal.II/tests/quick_tests/affinity.cc

index 1d6da9b8e8ef6a751184f87f9cccfd871e9ed719..a21bcc72008894d1e5bea033257fb2286997a85b 100644 (file)
@@ -82,7 +82,9 @@ FOREACH(_build ${DEAL_II_BUILD_TYPES})
 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)
index e9d01a4ea05d1f71f0869b619d28313ce1b42cf8..ab0fca1bca0b0203ff7506ace84dfc102f4ff27e 100644 (file)
 // ---------------------------------------------------------------------
 
 #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
 
-int main ()
+bool getaffinity(unsigned int &bits_set,unsigned int &mask)
 {
-  // we need this, otherwise gcc will not link against deal.II
-  dealii::Triangulation<2> test;
-
+  bits_set = 0;
+  mask = 0x00;
+  
+#if defined(__linux__)
   cpu_set_t my_set;
   CPU_ZERO(&my_set);
 
@@ -32,17 +38,45 @@ int main ()
   if (ret!=0)
     {
       printf("sched_getaffinity() failed, return value: %d\n", ret);
-      return -1;
+      return false;
     }
-
-  unsigned int bits_set = 0;//not supported on old kernels: CPU_COUNT(&my_set);
   for (int i=0;i<CPU_SETSIZE;++i)
     bits_set += CPU_ISSET(i,&my_set);
 
-  if (bits_set==1)
+  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::multithread_info.n_cpus;
+  unsigned int tbbprocs = dealii::multithread_info.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: sched_getaffinity() returns that we can only use one CPU.\n");
-      return 1;
+      printf("Warning: for some reason TBB only wants to use %d out of %d CPUs.\n",
+            tbbprocs, nprocs);
+      return 3;
     }
-  printf("ncpus=%d, mask=%08X\n", bits_set, *(unsigned int*)(&my_set));
+  
+  return 0;
 }

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.