Added extra check in for setaffinity support.
authorSander Pronk <pronk@kth.se>
Wed, 13 Feb 2013 14:24:22 +0000 (15:24 +0100)
committerSander Pronk <pronk@kth.se>
Wed, 13 Feb 2013 14:30:15 +0000 (15:30 +0100)
The Linux version of tMPI_Thread_setaffinity_support() did not check
whether pthread_setaffinity_np() would actually work on the system
it's running on. It now checks by running pthread_getaffinity_np()
and checking its return value.

This is relevant for, for example, Bluegene systems which don't
support explicit affinity setting.

Change-Id: I4833e7384067f897013d6fa4d0b35963ae740fcf

src/gmxlib/thread_mpi/pthreads.c

index 62d8c52cae70df7c1950717c3ede8d5ecd983f36..d49dc1245c0f75122539971ce0873d9f2bde6da3 100644 (file)
@@ -273,7 +273,19 @@ int tMPI_Thread_equal(tMPI_Thread_t t1, tMPI_Thread_t t2)
 enum tMPI_Thread_setaffinity_support tMPI_Thread_setaffinity_support(void)
 {
 #ifdef HAVE_PTHREAD_SETAFFINITY
-    return TMPI_SETAFFINITY_SUPPORT_YES;
+    cpu_set_t set;
+    int ret;
+
+    /* run getaffinity to check whether we get back ENOSYS */
+    ret=pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
+    if (ret == 0)
+    {
+        return TMPI_SETAFFINITY_SUPPORT_YES;
+    }
+    else
+    {
+        return TMPI_SETAFFINITY_SUPPORT_NO;
+    }
 #else
     return TMPI_SETAFFINITY_SUPPORT_NO;
 #endif