Merge "Fix ICC on Windows Build" into release-4-5-patches
authorDavid van der Spoel <davidvanderspoel@gmail.com>
Tue, 31 Jan 2012 18:38:42 +0000 (19:38 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 31 Jan 2012 18:38:42 +0000 (19:38 +0100)
cmake/ThreadMPI.cmake
include/thread_mpi/atomic/gcc_x86.h
src/gmxlib/thread_mpi/pthreads.c
src/kernel/md.c
src/kernel/readir.c
src/tools/gmx_mindist.c

index 19e90c1b753621bac7e443290849084b9d42f6e1..8ae8f9423b75c688bd048bb63bbf90357e97ff2a 100644 (file)
@@ -106,7 +106,14 @@ if (THREAD_WINDOWS)
        endif(HAVE_PROCESSOR_NUMBER)
 endif(THREAD_WINDOWS)
 
-
+# option to set affinity 
+option(THREAD_MPI_SET_AFFINITY "Set thread affinity to a core if number of threads equal to number of hardware threads." ON)
+mark_as_advanced(THREAD_MPI_SET_AFFINITY)
+if (THREAD_MPI_SET_AFFINITY)
+    add_definitions(-DTMPI_SET_AFFINITY)
+else (THREAD_MPI_SET_AFFINITY)
+    add_definitions()
+endif (THREAD_MPI_SET_AFFINITY)
 
 include(CheckFunctionExists)
 if (THREAD_PTHREADS)
@@ -139,6 +146,6 @@ check_include_files(sys/time.h      HAVE_SYS_TIME_H)
 check_function_exists(sysconf       HAVE_SYSCONF)
 # this runs on windows
 #check_include_files(windows.h         HAVE_WINDOWS_H)
-#check_function_exists(GetSystemInfo HAVE_SYSTEM_INFO)
+
 
 test_tmpi_atomics(TMPI_ATOMICS)
index ea0e6777bc485da23b1c91d24d4814e2551f5775..4cac16cba8d1e3c2a5ca48b7621aa32abf969576 100644 (file)
@@ -158,8 +158,8 @@ static inline int tMPI_Atomic_swap(tMPI_Atomic_t *a, int b)
 {
     volatile int ret=b;
     __asm__ __volatile__("\txchgl %0, %1;" 
-                         :"=r"(ret)
-                         :"m"(a->value), "0"(ret)
+                         :"+r"(ret), "+m"(a->value)
+                         : 
                          :"memory");
     return (int)ret;
 }
@@ -174,14 +174,14 @@ static inline void *tMPI_Atomic_ptr_swap(tMPI_Atomic_ptr_t *a, void *b)
                          :"memory");
 */
     __asm__ __volatile__("\txchgl %0, %1;" 
-                         :"=r"(ret)
-                         :"m"(a->value), "0"(ret)
+                         :"+r"(ret), "+m"(a->value)
+                         :
                          :"memory");
 
 #else
     __asm__ __volatile__("\txchgq %0, %1;" 
-                         :"=r"(ret)
-                         :"m"(a->value), "0"(ret)
+                         :"+r"(ret), "+m"(a->value)
+                         :
                          :"memory");
 #endif
     return (void*)ret;
@@ -219,7 +219,7 @@ static inline void tMPI_Spinlock_lock(tMPI_Spinlock_t *x)
                                                      value with 0 */
                          "\tjne 1b"               /* jump backward if we didn't
                                                      just lock */
-                         : "=m" (x->lock)         /* input & output var */
+                         : "+m" (x->lock)         /* input & output var */
                          : 
                          : "%eax", "memory"/* we changed memory */
                         );
@@ -239,15 +239,16 @@ static inline void tMPI_Spinlock_unlock(tMPI_Spinlock_t *  x)
 
 static inline int tMPI_Spinlock_trylock(tMPI_Spinlock_t *x)
 {
-    int old_value;
+    int old_value=1;
         
-    __asm__ __volatile__("\tmovl $1, %0\n"     /* set eax to 1, the locked
+    __asm__ __volatile__("\tmovl %2, %0\n"     /* set eax to 1, the locked
                                                   value of the lock */
                          "\txchgl %0, %1\n"    /* atomically exchange 
                                                   eax with the address in
                                                   rdx. */
-                         :"=r" (old_value), "=m" (x->lock)
-                         : : "memory");
+                         : "+r"(old_value), "+m" (x->lock)
+                         : "i" (1)
+                         : "memory");
     return (old_value);
 }
 
@@ -270,7 +271,7 @@ static inline void tMPI_Spinlock_wait(tMPI_Spinlock_t *x)
                          "\tjmp 1b\n"             /* and jump back */  
                          "2:\tnop\n"              /* jump target for end 
                                                      of wait */
-                         : "=m"(x->lock)         /* input & output var */
+                         : "+m"(x->lock)         /* input & output var */
                          : 
                          : "memory"/* we changed memory */
                         );
index 378a796f67e647d9f63a103832356d8deaad6eaf..4e3735150daa9a0347090f63950a4a51821abdf5 100644 (file)
@@ -87,13 +87,9 @@ static pthread_mutex_t cond_init=PTHREAD_MUTEX_INITIALIZER;
 /* mutex for initializing barriers */
 static pthread_mutex_t barrier_init=PTHREAD_MUTEX_INITIALIZER; 
 
-
-/* lock & variable for setting main thread affinity */
-static tMPI_Spinlock_t main_thread_aff_lock=TMPI_SPINLOCK_INITIALIZER;
-static tMPI_Atomic_t main_thread_aff_set={ 0 };
-static tMPI_Atomic_t aff_thread_number;
-
-
+/* mutex for initializing barriers */
+static pthread_mutex_t aff_init=PTHREAD_MUTEX_INITIALIZER; 
+static int aff_thread_number=0;
 
 
 /* TODO: this needs to go away!  (there's another one in winthreads.c)
@@ -152,7 +148,8 @@ int tMPI_Thread_create(tMPI_Thread_t *thread, void *(*start_routine)(void *),
     if(ret!=0)
     {
         /* Cannot use tMPI_error() since messages use threads for locking */
-        tMPI_Fatal_error(TMPI_FARGS,"Failed to create POSIX thread, rc=%d",ret);
+        tMPI_Fatal_error(TMPI_FARGS,"Failed to create POSIX thread:%s, rc=%d",
+                         strerror(errno), ret);
         /* Use system memory allocation routines */
         return -1;
     }
@@ -180,25 +177,15 @@ int tMPI_Thread_create_aff(tMPI_Thread_t *thread,
 {
     int ret;
 
+#ifdef TMPI_SET_AFFINITY
     /* set the calling thread's affinity mask */
-    if (tMPI_Atomic_get(&main_thread_aff_set) == 0)
+    pthread_mutex_lock( &(aff_init) );
+    if (aff_thread_number==0)
     {
-#ifdef HAVE_PTHREAD_SETAFFINITY
-        cpu_set_t set;
-#endif
-        /* this can be a spinlock because the chances of collision are low. */
-        tMPI_Spinlock_lock( &main_thread_aff_lock );
-        tMPI_Atomic_set( &aff_thread_number, 0);
-#ifdef HAVE_PTHREAD_SETAFFINITY
-        CPU_ZERO(&set);
-        CPU_SET(0, &set);
-        pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
-        /*fprintf(stderr, "Setting affinity.\n");*/
-#endif
-        tMPI_Atomic_set( &main_thread_aff_set, 1);
-        tMPI_Spinlock_unlock( &main_thread_aff_lock );
+        tMPI_Set_affinity(aff_thread_number++);
     }
-
+    pthread_mutex_unlock( &(aff_init) );
+#endif
 
     if(thread==NULL)
     {
@@ -212,20 +199,22 @@ int tMPI_Thread_create_aff(tMPI_Thread_t *thread,
     if(ret!=0)
     {
         /* Cannot use tMPI_error() since messages use threads for locking */
-        tMPI_Fatal_error(TMPI_FARGS,"Failed to create POSIX thread, rc=%d",ret);
+        tMPI_Fatal_error(TMPI_FARGS,"Failed to create POSIX thread:%s, rc=%d",
+                         strerror(errno), ret);
         /* Use system memory allocation routines */
         return -1;
     }
     else
     {
-#ifdef HAVE_PTHREAD_SETAFFINITY
-        int n;
-        cpu_set_t set;
+#ifdef TMPI_SET_AFFINITY
+        /* now set the affinity of the new thread */
+        int ret;
 
-        n=tMPI_Atomic_add_return(&aff_thread_number, 1);
-        CPU_ZERO(&set);
-        CPU_SET(n, &set);
-        return pthread_setaffinity_np((*thread)->th, sizeof(set), &set);
+        pthread_mutex_lock( &(aff_init) );
+        ret=tMPI_Set_affinity(aff_thread_number++);
+        pthread_mutex_unlock( &(aff_init) );
+        /* failure is non-fatal, so we won't check the result */
+        return 0;
 #else
         return 0;
 #endif
index 8ae0b4ce1eba204c6216431f6bf8f63c7907002c..0ca2dc97a077c21174f505830ec60071c83b38e9 100644 (file)
@@ -476,7 +476,7 @@ double do_md(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
     
     bSumEkinhOld = FALSE;
     compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
-                    wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
+                    NULL,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
                     constr,NULL,FALSE,state->box,
                     top_global,&pcurr,top_global->natoms,&bSumEkinhOld,cglo_flags);
     if (ir->eI == eiVVAK) {
@@ -487,7 +487,7 @@ double do_md(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
            perhaps loses some logic?*/
         
         compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
-                        wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
+                        NULL,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
                         constr,NULL,FALSE,state->box,
                         top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
                         cglo_flags &~ CGLO_PRESSURE);
index aad2f4cdfe62151f8fb1fa733de2878246fa2e82..0887758b185e4c107ae3f9d3007818a815a712a8 100644 (file)
@@ -1317,7 +1317,12 @@ int search_string(char *s,int ng,char *gn[])
     }
   }
     
-  gmx_fatal(FARGS,"Group %s not found in index file.\nGroup names must match either [moleculetype] names\nor custom index group names,in which case you\nmust supply an index file to the '-n' option of grompp.",s);
+  gmx_fatal(FARGS,
+            "Group %s referenced in the .mdp file was not found in the index file.\n"
+            "Group names must match either [moleculetype] names or custom index group\n"
+            "names, in which case you must supply an index file to the '-n' option\n"
+            "of grompp.",
+            s);
   
   return -1;
 }
index be8c231e6d0cf68c0f0ea5a9ec57e528d046fbd2..f3062942726e0576fff6ae1320cdc21a3330c9a1 100644 (file)
@@ -387,7 +387,7 @@ void dist_plot(const char *fn,const char *afile,const char *dfile,
     fprintf(dist,"\n");
     if (num) 
       fprintf(num,"\n");
-    if ( bMin?min1:max1 != -1 )
+    if ( (bMin?min1:max1) != -1 )
       if (atm)
        fprintf(atm,"%12e  %12d  %12d\n",
                output_env_conv_time(oenv,t),1+(bMin ? min1 : max1),