Remove #ifdef GMX_THREAD_MPI for basic thread safety.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 14 Sep 2013 12:05:06 +0000 (15:05 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 26 Nov 2013 20:27:34 +0000 (21:27 +0100)
Simplifies the code, and at least most of this should have zero impact
on performance.  Basic thread support from thread-MPI is already
required for compilation anyways even with GMX_THREAD_MPI off.
This removes about 70% of the #ifdefs, making it clearer what is
different between MPI and thread-MPI implementation in Gromacs.

Also set MPI_IN_PLACE_EXISTS with GMX_THREAD_MPI instead of checking for
GMX_THREAD_MPI separately each time.  Adjust one #ifdef in network.c to
replace an GMX_LIB_MPI made unnecessary by this with GMX_MPI.

Related to #948 and #1320.

Change-Id: I03a54b0bffde090100afe5ed2e91c184af36c189

24 files changed:
CMakeLists.txt
cmake/ThreadMPI.cmake
src/gromacs/fileio/filenm.c
src/gromacs/fileio/futil.cpp
src/gromacs/fileio/gmxfio.c
src/gromacs/fileio/gmxfio_asc.c
src/gromacs/fileio/gmxfio_bin.c
src/gromacs/fileio/gmxfio_int.h
src/gromacs/fileio/gmxfio_rw.c
src/gromacs/fileio/gmxfio_xdr.c
src/gromacs/fileio/tpxio.c
src/gromacs/gmxlib/gmx_fatal.c
src/gromacs/gmxlib/main.cpp
src/gromacs/gmxlib/network.c
src/gromacs/gmxlib/nonbonded/nonbonded.c
src/gromacs/gmxlib/smalloc.c
src/gromacs/gmxlib/tcontrol.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxlib/typedefs.c
src/gromacs/gmxpreprocess/fflibutil.cpp
src/gromacs/legacyheaders/mdrun.h
src/programs/mdrun/md.c
src/programs/mdrun/mdrun.cpp
src/programs/mdrun/runner.c

index 6d9c021d1db9a4b75a14accfa012308013c54de6..40556d361b57d4200c0d9a9987c07fb3b05e6baf 100644 (file)
@@ -568,6 +568,7 @@ if(GMX_THREAD_MPI)
     tmpi_enable()
     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
     set(GMX_MPI 1)
+    set(MPI_IN_PLACE_EXISTS 1)
 endif(GMX_THREAD_MPI)
 tmpi_get_source_list(THREAD_MPI_SRC)
 
index 18a2c3c49fea9df2d12d90accf82dabab6cb3ccd..d0a02e5e03caf1346c0b04ab1d4542f1ed3fe068 100644 (file)
@@ -170,7 +170,8 @@ MACRO(TMPI_GET_SOURCE_LIST SRC_VARIABLE)
     set(${SRC_VARIABLE}
         thread_mpi/errhandler.c
         thread_mpi/tmpi_malloc.c
-        thread_mpi/atomic.c)
+        thread_mpi/atomic.c
+        thread_mpi/lock.c)
     if (THREAD_PTHREADS)
         list(APPEND ${SRC_VARIABLE} thread_mpi/pthreads.c)
     elseif (THREAD_WINDOWS)
@@ -190,9 +191,8 @@ MACRO(TMPI_GET_SOURCE_LIST SRC_VARIABLE)
              thread_mpi/gather.c        thread_mpi/scatter.c
              thread_mpi/group.c         thread_mpi/tmpi_init.c
              thread_mpi/topology.c      thread_mpi/list.c
-             thread_mpi/type.c          thread_mpi/lock.c
-             thread_mpi/numa_malloc.c   thread_mpi/once.c
-             thread_mpi/scan.c)
+             thread_mpi/type.c          thread_mpi/scan.c
+             thread_mpi/numa_malloc.c   thread_mpi/once.c)
     endif()
 ENDMACRO(TMPI_GET_SOURCE_LIST)
 
index 97b941d248c4361d8d0ea95079ec05dd2c39ad68..e439b0fe2aef4fb7bfff3e9e3ad52bbeba8fc827 100644 (file)
@@ -50,9 +50,7 @@
 #include "xdrf.h"
 #include "macros.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 /* NOTE: this was a cesspool of thread-unsafe code, has now been
    properly proteced by mutexes (hopefully). */
@@ -209,9 +207,7 @@ static const t_deffile
 
 static char *default_file_name = NULL;
 
-#ifdef GMX_THREAD_MPI
 static tMPI_Thread_mutex_t filenm_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 #define NZEXT 2
 static const char *z_ext[NZEXT] =
@@ -219,15 +215,9 @@ static const char *z_ext[NZEXT] =
 
 void set_default_file_name(const char *name)
 {
-    int i;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&filenm_mutex);
-#endif
     default_file_name = strdup(name);
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&filenm_mutex);
-#endif
-
 }
 
 const char *ftp2ext(int ftp)
@@ -344,9 +334,7 @@ const char *ftp2defnm(int ftp)
 {
     const char *buf = NULL;
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&filenm_mutex);
-#endif
 
     if (default_file_name)
     {
@@ -359,9 +347,8 @@ const char *ftp2defnm(int ftp)
             buf = deffile[ftp].defnm;
         }
     }
-#ifdef GMX_THREAD_MPI
+
     tMPI_Thread_mutex_unlock(&filenm_mutex);
-#endif
 
     return buf;
 }
index c12aa5b3dc72e5bd5393632ae5680eac40fb0a11..6cacc9562de309618b5d4457fda0b1372b1c96d7 100644 (file)
@@ -76,9 +76,7 @@
 #include "gromacs/utility/programinfo.h"
 #include "gromacs/utility/stringutil.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi/threads.h"
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 /* we keep a linked list of all files opened through pipes (i.e.
    compressed or .gzipped files. This way we can distinguish between them
@@ -92,11 +90,9 @@ typedef struct t_pstack {
 static t_pstack    *pstack      = NULL;
 static gmx_bool     bUnbuffered = FALSE;
 
-#ifdef GMX_THREAD_MPI
 /* this linked list is an intrinsically globally shared object, so we have
    to protect it with mutexes */
 static tMPI_Thread_mutex_t pstack_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 void no_buffers(void)
 {
@@ -107,17 +103,14 @@ void push_ps(FILE *fp)
 {
     t_pstack *ps;
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&pstack_mutex);
-#endif
 
     snew(ps, 1);
     ps->fp   = fp;
     ps->prev = pstack;
     pstack   = ps;
-#ifdef GMX_THREAD_MPI
+
     tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
 }
 
 #ifdef GMX_FAHCORE
@@ -156,9 +149,8 @@ int ffclose(FILE *fp)
 #else
     t_pstack *ps, *tmp;
     int       ret = 0;
-#ifdef GMX_THREAD_MPI
+
     tMPI_Thread_mutex_lock(&pstack_mutex);
-#endif
 
     ps = pstack;
     if (ps == NULL)
@@ -201,9 +193,8 @@ int ffclose(FILE *fp)
             }
         }
     }
-#ifdef GMX_THREAD_MPI
+
     tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
     return ret;
 #endif
 }
@@ -215,28 +206,21 @@ int ffclose(FILE *fp)
 
 void frewind(FILE *fp)
 {
-    t_pstack *ps;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&pstack_mutex);
-#endif
 
-    ps = pstack;
+    t_pstack *ps = pstack;
     while (ps != NULL)
     {
         if (ps->fp == fp)
         {
             fprintf(stderr, "Cannot rewind compressed file!\n");
-#ifdef GMX_THREAD_MPI
             tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
             return;
         }
         ps = ps->prev;
     }
     rewind(fp);
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
 }
 
 int gmx_fseek(FILE *stream, gmx_off_t offset, int whence)
@@ -268,26 +252,19 @@ gmx_off_t gmx_ftell(FILE *stream)
 
 gmx_bool is_pipe(FILE *fp)
 {
-    t_pstack *ps;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&pstack_mutex);
-#endif
 
-    ps = pstack;
+    t_pstack *ps = pstack;
     while (ps != NULL)
     {
         if (ps->fp == fp)
         {
-#ifdef GMX_THREAD_MPI
             tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
             return TRUE;
         }
         ps = ps->prev;
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&pstack_mutex);
-#endif
     return FALSE;
 }
 
index 700c84c2bea3181c55bc4bcfc45a018263268d39..0e6499ba23eccf7d95dcd71f4cbf064b29e0c963 100644 (file)
@@ -57,9 +57,7 @@
 #include "gmxfio.h"
 #include "md5.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 #include "gmxfio_int.h"
 
@@ -72,7 +70,6 @@
 static t_fileio *open_files = NULL;
 
 
-#ifdef GMX_THREAD_MPI
 /* this mutex locks the open_files structure so that no two threads can
    modify it.
 
@@ -83,7 +80,6 @@ static t_fileio *open_files = NULL;
    iterating along all open files. All these cases should be rare
    during the simulation. */
 static tMPI_Thread_mutex_t open_file_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 
 /* These simple lists define the I/O type for these files */
@@ -264,16 +260,12 @@ static void gmx_fio_set_iotype(t_fileio *fio)
    type of access to the fio's elements. */
 void gmx_fio_lock(t_fileio *fio)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Lock_lock(&(fio->mtx));
-#endif
 }
 /* unlock the mutex associated with this fio.  */
 void gmx_fio_unlock(t_fileio *fio)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Lock_unlock(&(fio->mtx));
-#endif
 }
 
 /* make a dummy head element, assuming we locked everything. */
@@ -286,9 +278,7 @@ static void gmx_fio_make_dummy(void)
         open_files->fn   = NULL;
         open_files->next = open_files;
         open_files->prev = open_files;
-#ifdef GMX_THREAD_MPI
         tMPI_Lock_init(&(open_files->mtx));
-#endif
     }
 }
 
@@ -309,10 +299,8 @@ static void gmx_fio_make_dummy(void)
 static void gmx_fio_insert(t_fileio *fio)
 {
     t_fileio *prev;
-#ifdef GMX_THREAD_MPI
     /* first lock the big open_files mutex. */
     tMPI_Thread_mutex_lock(&open_file_mutex);
-#endif
     /* now check whether the dummy element has been allocated,
        and allocate it if it hasn't */
     gmx_fio_make_dummy();
@@ -341,10 +329,8 @@ static void gmx_fio_insert(t_fileio *fio)
     gmx_fio_unlock(open_files);
     gmx_fio_unlock(fio);
 
-#ifdef GMX_THREAD_MPI
     /* now unlock the big open_files mutex.  */
     tMPI_Thread_mutex_unlock(&open_file_mutex);
-#endif
 }
 
 /* remove a t_fileio into the list. We assume the fio is locked, and we leave
@@ -378,10 +364,8 @@ static t_fileio *gmx_fio_get_first(void)
     t_fileio *ret;
     /* first lock the big open_files mutex and the dummy's mutex */
 
-#ifdef GMX_THREAD_MPI
     /* first lock the big open_files mutex. */
     tMPI_Thread_mutex_lock(&open_file_mutex);
-#endif
     gmx_fio_make_dummy();
 
     gmx_fio_lock(open_files);
@@ -415,9 +399,7 @@ static t_fileio *gmx_fio_get_next(t_fileio *fio)
     if (fio->next == open_files)
     {
         ret = NULL;
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_unlock(&open_file_mutex);
-#endif
     }
     else
     {
@@ -432,9 +414,7 @@ static t_fileio *gmx_fio_get_next(t_fileio *fio)
 static void gmx_fio_stop_getting_next(t_fileio *fio)
 {
     gmx_fio_unlock(fio);
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&open_file_mutex);
-#endif
 }
 
 
@@ -501,9 +481,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
     }
 
     snew(fio, 1);
-#ifdef GMX_THREAD_MPI
     tMPI_Lock_init(&(fio->mtx));
-#endif
     bRead      = (newmode[0] == 'r' && newmode[1] != '+');
     bReadWrite = (newmode[1] == '+');
     fio->fp    = NULL;
@@ -617,11 +595,9 @@ int gmx_fio_close(t_fileio *fio)
 {
     int rc = 0;
 
-#ifdef GMX_THREAD_MPI
     /* first lock the big open_files mutex. */
     /* We don't want two processes operating on the list at the same time */
     tMPI_Thread_mutex_lock(&open_file_mutex);
-#endif
 
     gmx_fio_lock(fio);
     /* first remove it from the list */
@@ -632,9 +608,7 @@ int gmx_fio_close(t_fileio *fio)
     sfree(fio->fn);
     sfree(fio);
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&open_file_mutex);
-#endif
 
     return rc;
 }
index c02cab30c5ff0228b4d262a3f652b6326cb98bd8..b8563657d12762ba778eb2cf46e17344b5bd93a5 100644 (file)
 #include "gmxfio.h"
 #include "md5.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "gmxfio_int.h"
 
 
index cf50e0fdc48c71ebc8cacf5915c71606c83bf041..821da26aa6f4c09513179a0388f4b6e513a6ac66 100644 (file)
 #include "gmxfio.h"
 #include "md5.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "gmxfio_int.h"
 
 /* This is the part that reads dummy and ascii files.  */
index 9a8f069c903b223afd57f13de9a54f88b24577be..0fefe60fc53e49a91b7a4fa2a4e6fe2ed3bde8c6 100644 (file)
@@ -58,7 +58,7 @@
  */
 #define USE_XDR
 
-
+#include "gromacs/legacyheaders/thread_mpi/lock.h"
 
 /* the reader/writer functions  for t_iotype */
 typedef gmx_bool read_func (t_fileio *fio, void *item, int nitem, int eio,
@@ -97,12 +97,10 @@ struct t_fileio
 
     t_fileio   *next, *prev;           /* next and previous file pointers in the
                                           linked list */
-#ifdef GMX_THREAD_MPI
     tMPI_Lock_t  mtx;                  /* content locking mutex. This is a fast lock
                                           for performance reasons: in some cases every
                                           single byte that gets read/written requires
                                           a lock */
-#endif
 };
 
 
index 6a66545c9b577c017f993dfe9360b7afe0f728e9..5036fd75efeae12c91ae0b8f651b663046d105d7 100644 (file)
 #include "gmxfio.h"
 #include "md5.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "gmxfio_int.h"
 
 
index da24d2a74890c9369fd4cc9741a33185eecd8cc4..5d82febed976ffe4a31c0c338648b1714a52eddf 100644 (file)
 #include "gmxfio.h"
 #include "md5.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "gmxfio_int.h"
 
 /* This is the part that reads xdr files.  */
index f319075b4bf0864c403b9b59ba73b33b15c0396d..0f807bdb46dba52d7bc6df7e4931380a362a8e55 100644 (file)
 #endif
 
 /* This file is completely threadsafe - keep it that way! */
-#ifdef GMX_THREAD_MPI
-#include <thread_mpi.h>
-#endif
-
 
 #include <ctype.h>
 #include "sysstuff.h"
index 6fa091f196e55a12992c22b49cfaaad5bec55e3f..3d9fd5c784928e928a1d829fb4c29f04442e7a4d 100644 (file)
 
 #include "gromacs/utility/gmxmpi.h"
 
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
+
 static gmx_bool bDebug         = FALSE;
 static char    *fatal_tmp_file = NULL;
 static FILE    *log_file       = NULL;
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi/threads.h"
 static tMPI_Thread_mutex_t debug_mutex     = TMPI_THREAD_MUTEX_INITIALIZER;
 static tMPI_Thread_mutex_t where_mutex     = TMPI_THREAD_MUTEX_INITIALIZER;
 static tMPI_Thread_mutex_t fatal_tmp_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 
 gmx_bool bDebugMode(void)
 {
     gmx_bool ret;
-/*#ifdef GMX_THREAD_MPI*/
 #if 0
     tMPI_Thread_mutex_lock(&debug_mutex);
 #endif
     ret = bDebug;
-/*#ifdef GMX_THREAD_MPI*/
 #if 0
     tMPI_Thread_mutex_unlock(&debug_mutex);
 #endif
@@ -97,22 +94,17 @@ void _where(const char *file, int line)
 
     if (bFirst)
     {
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_lock(&where_mutex);
         if (bFirst) /* we repeat the check in the locked section because things
                        might have changed */
         {
-#endif
-        if ((temp = getenv("WHERE")) != NULL)
-        {
-            nskip = strtol(temp, NULL, 10);
+            if ((temp = getenv("WHERE")) != NULL)
+            {
+                nskip = strtol(temp, NULL, 10);
+            }
+            bFirst = FALSE;
         }
-        bFirst = FALSE;
-#ifdef GMX_THREAD_MPI
-    }
-    tMPI_Thread_mutex_unlock(&where_mutex);
-#endif
-
+        tMPI_Thread_mutex_unlock(&where_mutex);
     }
 
     if (nskip >= 0)
@@ -219,9 +211,7 @@ static int fatal_errno = 0;
 
 static void quit_gmx(const char *msg)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
     if (fatal_errno == 0)
     {
         if (log_file)
@@ -275,9 +265,7 @@ static void quit_gmx(const char *msg)
     }
 
     exit(fatal_errno);
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 }
 
 /* The function below should be identical to quit_gmx,
@@ -285,9 +273,7 @@ static void quit_gmx(const char *msg)
  */
 static void quit_gmx_noquit(const char *msg)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
     if (!fatal_errno)
     {
         if (log_file)
@@ -324,16 +310,12 @@ static void quit_gmx_noquit(const char *msg)
     }
 #endif
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 }
 
 void _set_fatal_tmp_file(const char *fn, const char *file, int line)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&fatal_tmp_mutex);
-#endif
     if (fatal_tmp_file == NULL)
     {
         fatal_tmp_file = strdup(fn);
@@ -343,16 +325,12 @@ void _set_fatal_tmp_file(const char *fn, const char *file, int line)
         fprintf(stderr, "BUGWARNING: fatal_tmp_file already set at %s:%d",
                 file, line);
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&fatal_tmp_mutex);
-#endif
 }
 
 void _unset_fatal_tmp_file(const char *fn, const char *file, int line)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&fatal_tmp_mutex);
-#endif
     if (strcmp(fn, fatal_tmp_file) == 0)
     {
         sfree(fatal_tmp_file);
@@ -363,16 +341,12 @@ void _unset_fatal_tmp_file(const char *fn, const char *file, int line)
         fprintf(stderr, "BUGWARNING: file %s not set as fatal_tmp_file at %s:%d",
                 fn, file, line);
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&fatal_tmp_mutex);
-#endif
 }
 
 static void clean_fatal_tmp_file()
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&fatal_tmp_mutex);
-#endif
     if (fatal_tmp_file)
     {
         fprintf(stderr, "Cleaning up temporary file %s\n", fatal_tmp_file);
@@ -380,9 +354,7 @@ static void clean_fatal_tmp_file()
         sfree(fatal_tmp_file);
         fatal_tmp_file = NULL;
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&fatal_tmp_mutex);
-#endif
 }
 
 static void parse_printf_args(const char *fmt, va_list *ap, char *msg)
@@ -489,15 +461,9 @@ void gmx_fatal(int f_errno, const char *file, int line, const char *fmt, ...)
 
     va_end(ap);
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
-
     fatal_errno = f_errno;
-
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 
     _gmx_error("fatal", msg, file, line);
 }
@@ -540,15 +506,9 @@ void gmx_fatal_collective(int f_errno, const char *file, int line,
 
         va_end(ap);
 
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
-
         fatal_errno = f_errno;
-
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 
         if (bFinalize)
         {
@@ -607,11 +567,9 @@ void _unexpected_eof(const char *fn, int line, const char *srcfn, int srcline)
 FILE *debug           = NULL;
 gmx_bool gmx_debug_at = FALSE;
 
-void init_debug (const int dbglevel, const char *dbgfile)
+void init_debug(const int dbglevel, const char *dbgfile)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
     if (!bDebug) /* another thread hasn't already run this*/
     {
         no_buffers();
@@ -622,9 +580,7 @@ void init_debug (const int dbglevel, const char *dbgfile)
             gmx_debug_at = TRUE;
         }
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 }
 
 #if (defined __sgi && defined USE_SGI_FPE)
@@ -657,9 +613,7 @@ void doexceptions(void)
 
     int onoff, en_mask, abort_action, i;
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
     onoff   = _DEBUG;
     en_mask = _EN_UNDERFL | _EN_OVERFL | _EN_DIVZERO |
         _EN_INVALID | _EN_INT_OVERFL;
@@ -670,9 +624,7 @@ void doexceptions(void)
     {
         signal(hs[i], handle_signals);
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 }
 #endif /* __sgi and FPE */
 
@@ -682,13 +634,9 @@ static void (*gmx_error_handler)(const char *msg) = quit_gmx;
 
 void set_gmx_error_handler(void (*func)(const char *msg))
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&debug_mutex);
-#endif
     gmx_error_handler = func;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&debug_mutex);
-#endif
 }
 
 char *gmx_strerror(const char *key)
index c3a5f66cd6d8fc058c9f9338cfd90d6f32ee5afa..f8acb00db4e187b616d6129ea51cadd6192ca06a 100644 (file)
 #include "string2.h"
 #include "copyrite.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/gmxmpi.h"
 #include "gromacs/utility/programinfo.h"
 
 /* The source code in this file should be thread-safe.
@@ -409,7 +406,7 @@ void init_multisystem(t_commrec *cr, int nsim, char **multidirs,
     MPI_Comm_create(MPI_COMM_WORLD, ms->mpi_group_masters,
                     &ms->mpi_comm_masters);
 
-#if !defined(GMX_THREAD_MPI) && !defined(MPI_IN_PLACE_EXISTS)
+#if !defined(MPI_IN_PLACE_EXISTS)
     /* initialize the MPI_IN_PLACE replacement buffers */
     snew(ms->mpb, 1);
     ms->mpb->ibuf        = NULL;
index b3480a5f20947fb72346e7cf6bf78ce667925e03..816161e42470ec276fb17ee32339741f7e5d2f68 100644 (file)
@@ -103,7 +103,7 @@ t_commrec *init_commrec()
     // TODO cr->duty should not be initialized here
     cr->duty = (DUTY_PP | DUTY_PME);
 
-#if defined GMX_LIB_MPI && !defined MPI_IN_PLACE_EXISTS
+#if defined GMX_MPI && !defined MPI_IN_PLACE_EXISTS
     /* initialize the MPI_IN_PLACE replacement buffers */
     snew(cr->mpb, 1);
     cr->mpb->ibuf        = NULL;
@@ -529,7 +529,7 @@ void gmx_sumd(int nr, double r[], const t_commrec *cr)
 #ifndef GMX_MPI
     gmx_call("gmx_sumd");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     if (cr->nc.bUse)
     {
         if (cr->nc.rank_intra == 0)
@@ -592,7 +592,7 @@ void gmx_sumf(int nr, float r[], const t_commrec *cr)
 #ifndef GMX_MPI
     gmx_call("gmx_sumf");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     if (cr->nc.bUse)
     {
         /* Use two step summing.  */
@@ -654,7 +654,7 @@ void gmx_sumi(int nr, int r[], const t_commrec *cr)
 #ifndef GMX_MPI
     gmx_call("gmx_sumi");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     if (cr->nc.bUse)
     {
         /* Use two step summing */
@@ -712,7 +712,7 @@ void gmx_sumli(int nr, gmx_large_int_t r[], const t_commrec *cr)
 #ifndef GMX_MPI
     gmx_call("gmx_sumli");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     if (cr->nc.bUse)
     {
         /* Use two step summing */
@@ -775,7 +775,7 @@ void gmx_sumli(int nr, gmx_large_int_t r[], const t_commrec *cr)
 #ifdef GMX_MPI
 void gmx_sumd_comm(int nr, double r[], MPI_Comm mpi_comm)
 {
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_DOUBLE, MPI_SUM, mpi_comm);
 #else
     /* this function is only used in code that is not performance critical,
@@ -798,7 +798,7 @@ void gmx_sumd_comm(int nr, double r[], MPI_Comm mpi_comm)
 #ifdef GMX_MPI
 void gmx_sumf_comm(int nr, float r[], MPI_Comm mpi_comm)
 {
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_FLOAT, MPI_SUM, mpi_comm);
 #else
     /* this function is only used in code that is not performance critical,
@@ -841,7 +841,7 @@ void gmx_sumi_sim(int nr, int r[], const gmx_multisim_t *ms)
 #ifndef GMX_MPI
     gmx_call("gmx_sumi_sim");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     MPI_Allreduce(MPI_IN_PLACE, r, nr, MPI_INT, MPI_SUM, ms->mpi_comm_masters);
 #else
     /* this is thread-unsafe, but it will do for now: */
@@ -866,7 +866,7 @@ void gmx_sumli_sim(int nr, gmx_large_int_t r[], const gmx_multisim_t *ms)
 #ifndef GMX_MPI
     gmx_call("gmx_sumli_sim");
 #else
-#if defined(MPI_IN_PLACE_EXISTS) || defined(GMX_THREAD_MPI)
+#if defined(MPI_IN_PLACE_EXISTS)
     MPI_Allreduce(MPI_IN_PLACE, r, nr, GMX_MPI_LARGE_INT, MPI_SUM,
                   ms->mpi_comm_masters);
 #else
index 2c1f1686c28d0a53a6c5f58bf026d72410a54171..b80eeff02aed17b60cefbafadefa8ad499a6ac41 100644 (file)
@@ -37,9 +37,7 @@
 #include <config.h>
 #endif
 
-#ifdef GMX_THREAD_MPI
-#include <thread_mpi.h>
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #endif
 
 
-#ifdef GMX_THREAD_MPI
 static tMPI_Thread_mutex_t nonbonded_setup_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 static gmx_bool            nonbonded_setup_done  = FALSE;
 
 
@@ -111,9 +107,7 @@ void
 gmx_nonbonded_setup(t_forcerec *   fr,
                     gmx_bool       bGenericKernelOnly)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&nonbonded_setup_mutex);
-#endif
     /* Here we are guaranteed only one thread made it. */
     if (nonbonded_setup_done == FALSE)
     {
@@ -162,9 +156,7 @@ gmx_nonbonded_setup(t_forcerec *   fr,
 
         nonbonded_setup_done = TRUE;
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&nonbonded_setup_mutex);
-#endif
 }
 
 
index 9ebdd67080d0348c6b8f337f124b6f9bedc71d50..c5cccd5a99f99b24bbef1ada65fe59a672ffe371 100644 (file)
@@ -51,6 +51,8 @@
 #endif
 
 #ifdef DEBUG
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
+
 static void log_action(int bMal, const char *what, const char *file, int line,
                        int nelem, int size, void *ptr)
 {
@@ -64,9 +66,7 @@ static void log_action(int bMal, const char *what, const char *file, int line,
         bytes = -bytes;
     }
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&gmx_logfile_mtx);
-#endif
 
     /* This total memory count is not correct, since with realloc
      * it adds the whole size again, not just the increment.
@@ -101,9 +101,7 @@ static void log_action(int bMal, const char *what, const char *file, int line,
                what ? what  : NN, bytes/1024.0,
                file ? fname : NN, line, nelem, size);
     }
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&gmx_logfile_mtx);
-#endif
 }
 #endif
 
index 7b53634baa609f69fe5c14361bf055a4f2ad14dd..9e6e88177926f0e6ecb7d3ec09722a329d83d81f 100644 (file)
@@ -41,9 +41,7 @@
 #include "typedefs.h"
 #include "gmx_fatal.h"
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 /* The source code in this file should be thread-safe.
          Please keep it that way. */
@@ -60,22 +58,16 @@ static t_timecontrol timecontrol[TNR] = {
     { 0, FALSE }
 };
 
-#ifdef GMX_THREAD_MPI
 static tMPI_Thread_mutex_t tc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 gmx_bool bTimeSet(int tcontrol)
 {
     gmx_bool ret;
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&tc_mutex);
-#endif
     range_check(tcontrol, 0, TNR);
     ret = timecontrol[tcontrol].bSet;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&tc_mutex);
-#endif
 
     return ret;
 }
@@ -84,26 +76,18 @@ real rTimeValue(int tcontrol)
 {
     real ret;
 
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&tc_mutex);
-#endif
     range_check(tcontrol, 0, TNR);
     ret = timecontrol[tcontrol].t;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&tc_mutex);
-#endif
     return ret;
 }
 
 void setTimeValue(int tcontrol, real value)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&tc_mutex);
-#endif
     range_check(tcontrol, 0, TNR);
     timecontrol[tcontrol].t    = value;
     timecontrol[tcontrol].bSet = TRUE;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&tc_mutex);
-#endif
 }
index c65b8ff8a057c35f6efcb442ad4567a9318c8865..8dcc68dc14656b75c42f9ad4a451fed5a9839ac7 100644 (file)
 #endif
 
 /* This file is completely threadsafe - please keep it that way! */
-#ifdef GMX_THREAD_MPI
-#include <thread_mpi.h>
-#endif
-
 
 #include <stdio.h>
 #include "smalloc.h"
index c4747e78b2c8f183a09c1712a7d29e4d3148ab49..040e814c41589c6345a4ee1d1011c306586a49dd 100644 (file)
@@ -45,9 +45,7 @@
 #include "macros.h"
 #include <string.h>
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
+#include "gromacs/legacyheaders/thread_mpi/threads.h"
 
 /* The source code in this file should be thread-safe.
       Please keep it that way. */
 
 
 static gmx_bool            bOverAllocDD = FALSE;
-#ifdef GMX_THREAD_MPI
 static tMPI_Thread_mutex_t over_alloc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 
 void set_over_alloc_dd(gmx_bool set)
 {
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_lock(&over_alloc_mutex);
     /* we just make sure that we don't set this at the same time.
        We don't worry too much about reading this rarely-set variable */
-#endif
     bOverAllocDD = set;
-#ifdef GMX_THREAD_MPI
     tMPI_Thread_mutex_unlock(&over_alloc_mutex);
-#endif
 }
 
 int over_alloc_dd(int n)
index cd8e2dec6c42308792dc0403df082234ac11f7a7..b2ac91c928f9b39bcf46295b5a5022815b1ffcda 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef GMX_THREAD_MPI
-#include "thread_mpi.h"
-#endif
-
 #include "fflibutil.h"
 
 const char *fflib_forcefield_dir_ext()
index 286f97b3e0177b68400036d2a927e474b305099e..c7ba433362e27ef296471d93448682e9ed394bc3 100644 (file)
 #include "types/membedt.h"
 #include "types/globsig.h"
 
-
-#ifdef GMX_THREAD_MPI
 #include "thread_mpi/threads.h"
-#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -92,9 +89,9 @@ enum {
  */
 extern gmx_large_int_t     deform_init_init_step_tpx;
 extern matrix              deform_init_box_tpx;
-#ifdef GMX_THREAD_MPI
 extern tMPI_Thread_mutex_t deform_init_box_mutex;
 
+#ifdef GMX_THREAD_MPI
 /* The minimum number of atoms per tMPI thread. With fewer atoms than this,
  * the number of threads will get lowered.
  */
index 5366973b3300241e4133f41ccd8250cba1ebc2d1..44ccd1fd527ceda3c316cf179264d34811d835ae 100644 (file)
@@ -332,15 +332,11 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[],
 
     if (DEFORM(*ir))
     {
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_lock(&deform_init_box_mutex);
-#endif
         set_deform_reference_box(upd,
                                  deform_init_init_step_tpx,
                                  deform_init_box_tpx);
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_unlock(&deform_init_box_mutex);
-#endif
     }
 
     {
index d1ebcc102ea6b653c6db3417c8cae38dacbc6639..0c623935f58a4b5509e40354d41b475e0d7d2953 100644 (file)
@@ -614,7 +614,8 @@ int gmx_mdrun(int argc, char *argv[])
         gmx_bool bParFn = (multidir == NULL);
         init_multisystem(cr, nmultisim, multidir, NFILE, fnm, bParFn);
 #else
-        gmx_fatal(FARGS, "mdrun -multi is not supported with the thread library.Please compile GROMACS with MPI support");
+        gmx_fatal(FARGS, "mdrun -multi is not supported with the thread library. "
+                  "Please compile GROMACS with MPI support");
 #endif
     }
 
index 8229cf1737fabece9096f71e30b33e3eea9217bb..13a23763cb656661e7763fb087c9fa143f45fb9d 100644 (file)
@@ -103,9 +103,7 @@ const gmx_intp_t    integrator[eiNR] = { {do_md}, {do_steep}, {do_cg}, {do_md},
 
 gmx_large_int_t     deform_init_init_step_tpx;
 matrix              deform_init_box_tpx;
-#ifdef GMX_THREAD_MPI
 tMPI_Thread_mutex_t deform_init_box_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-#endif
 
 
 #ifdef GMX_THREAD_MPI
@@ -1322,14 +1320,10 @@ int mdrunner(gmx_hw_opt_t *hw_opt,
          * This should be thread safe, since they are only written once
          * and with identical values.
          */
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_lock(&deform_init_box_mutex);
-#endif
         deform_init_init_step_tpx = inputrec->init_step;
         copy_mat(box, deform_init_box_tpx);
-#ifdef GMX_THREAD_MPI
         tMPI_Thread_mutex_unlock(&deform_init_box_mutex);
-#endif
     }
 
     if (opt2bSet("-cpi", nfile, fnm))