Make some symbols in gmxpre-config.h always defined
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 26 Sep 2018 12:09:28 +0000 (14:09 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 28 Sep 2018 06:51:42 +0000 (08:51 +0200)
Made related minor simplifications in a few places.

Fixes #2654

Change-Id: Ie3245c78f1f88bd9df6f81c86f8f04dae2ceb45c

14 files changed:
src/config.h.cmakein
src/external/thread_mpi/include/thread_mpi/wait.h
src/external/thread_mpi/src/settings.h
src/gmxpre-config.h.cmakein
src/gmxpre.h
src/gromacs/fileio/checkpoint.cpp
src/gromacs/fileio/gmxfio.cpp
src/gromacs/mdlib/mdoutf.cpp
src/gromacs/mdlib/trajectory_writing.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/runner.cpp
src/gromacs/utility/binaryinformation.cpp
src/gromacs/utility/futil.cpp
src/gromacs/utility/init.cpp

index 2e31c480b6f339c81fc03a27e6fd7243c9057fa0..cab63d23a4425305e077eed4040166f990612ea6 100644 (file)
 #cmakedefine THREAD_WINDOWS
 
 /* Define for busy wait option  */
-/* See gmxpre-config.h.cmakein for explanation for the #ifdef */
+/* See gmxpre-config.h.cmakein for explanation for the #ifndef */
 #ifndef TMPI_WAIT_FOR_NO_ONE
-#cmakedefine TMPI_WAIT_FOR_NO_ONE
+#cmakedefine01 TMPI_WAIT_FOR_NO_ONE
 #endif
 
 /* Define for copy buffer option */
index 8c2ec839728969ab4f73d983572cc9018a32bff6..47e2244a9b0cd40a40b59a7970b3e4ca42ee535d 100644 (file)
@@ -39,7 +39,7 @@
 #ifndef TMPI_WAIT_H_
 #define TMPI_WAIT_H_
 
-#ifndef TMPI_WAIT_FOR_NO_ONE
+#if TMPI_WAIT_FOR_NO_ONE
 
 #if !(defined( _WIN32 ) || defined( _WIN64 ) )
 #ifdef HAVE_UNISTD_H
index 986a516b27caacee090d17b738b0b6ecfd67f7e0..d44e973fdba516ab8f9c6454122406013db53f61 100644 (file)
@@ -79,7 +79,7 @@
    system.
 
    This option can be set with cmake. */
-/*#define TMPI_WAIT_FOR_NO_ONE */
+/*#define TMPI_WAIT_FOR_NO_ONE */
 
 
 
index 2f840259d01080427afd3a322a9dfdc4b83577cb..dc3f7c558ef31dcf7fcd356f4e74e65affe1f6c8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * \see gmxpre.h
  */
 
-/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc
+ * 2.2). This symbol affects non-GROMACS code, so is not subject to
+ * our no-undefined-preprocessor-symbols policy. */
 #cmakedefine _LARGEFILE_SOURCE
 
-/* Define for large files, on AIX-style hosts. */
+/* Define for large files, on AIX-style hosts. This symbol affects
+ * non-GROMACS code, so is not subject to our
+ * no-undefined-preprocessor-symbols policy. */
 #cmakedefine _LARGE_FILES
 
-/* Some systems requires this to be set to 64 for large file support */
+/* Some systems requires this to be set to 64 for large file support.
+ * This symbol affects non-GROMACS code, so is not subject to our
+ * no-undefined-preprocessor-symbols policy. */
 #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
 
 /* Build special-purpose mdrun library */
-#cmakedefine GMX_FAHCORE
+#cmakedefine01 GMX_FAHCORE
 
 /* This is here for simplicity, since the layout for some thread-MPI structs
  * declared in headers depend on this being consistently defined.
  * But thread-MPI itself does not include gmxpre.h, so the same define is also
  * set in config.h (which gets included by thread-MPI, but only in the source
  * files). There are some other config.h defines that appear in thread-MPI
- * headers, but currently Gromacs does not use any code that would depend on
+ * headers, but currently GROMACS does not use any code that would depend on
  * those, and for thread-MPI, config.h provides the definitions wherever
  * required. */
 /* Define for busy wait option  */
-#cmakedefine TMPI_WAIT_FOR_NO_ONE
-
+#cmakedefine01 TMPI_WAIT_FOR_NO_ONE
index 0573e37a11a77bbaf7147b63d6c47920f42016ab..ad248a81698248f9233da9b3192f7a59471271b8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -85,7 +85,7 @@
 #define __STDC_LIMIT_MACROS
 #define __STDC_FORMAT_MACROS
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
 #define FULLINDIRECT 1
 #define USE_FAH_XDR  1
 #include "swindirect.h"
index fa69f490e8696333ed34b45848daf611689e27fe..c4461a69aef9d5b36bb53480a24b365cbcae4d4d 100644 (file)
@@ -89,7 +89,7 @@
 #include "gromacs/utility/sysinfo.h"
 #include "gromacs/utility/txtdump.h"
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
 #include "corewrap.h"
 #endif
 
@@ -1995,19 +1995,22 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
             buf[std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1] = '\0';
             std::strcat(buf, "_prev");
             std::strcat(buf, fn+std::strlen(fn) - std::strlen(ftp2ext(fn2ftp(fn))) - 1);
-#ifndef GMX_FAHCORE
-            /* we copy here so that if something goes wrong between now and
-             * the rename below, there's always a state.cpt.
-             * If renames are atomic (such as in POSIX systems),
-             * this copying should be unneccesary.
-             */
-            gmx_file_copy(fn, buf, FALSE);
-            /* We don't really care if this fails:
-             * there's already a new checkpoint.
-             */
-#else
-            gmx_file_rename(fn, buf);
-#endif
+            if (!GMX_FAHCORE)
+            {
+                /* we copy here so that if something goes wrong between now and
+                 * the rename below, there's always a state.cpt.
+                 * If renames are atomic (such as in POSIX systems),
+                 * this copying should be unneccesary.
+                 */
+                gmx_file_copy(fn, buf, FALSE);
+                /* We don't really care if this fails:
+                 * there's already a new checkpoint.
+                 */
+            }
+            else
+            {
+                gmx_file_rename(fn, buf);
+            }
         }
         if (gmx_file_rename(fntemp, fn) != 0)
         {
@@ -2018,7 +2021,7 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
 
     sfree(fntemp);
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
     /*code for alternate checkpointing scheme.  moved from top of loop over
        steps */
     fcRequestCheckPoint();
@@ -2380,77 +2383,79 @@ static void read_checkpoint(const char *fn, FILE **pfplog,
                           " offsets. Can not append. Run mdrun with -noappend",
                           outputfile.filename);
             }
-#ifdef GMX_FAHCORE
-            chksum_file = gmx_fio_open(outputfile.filename, "a");
-
-#else
-            chksum_file = gmx_fio_open(outputfile.filename, "r+");
-
-            /* lock log file */
-            if (firstFile)
+            if (GMX_FAHCORE)
             {
-                /* Note that there are systems where the lock operation
-                 * will succeed, but a second process can also lock the file.
-                 * We should probably try to detect this.
-                 */
+                chksum_file = gmx_fio_open(outputfile.filename, "a");
+            }
+            else
+            {
+                chksum_file = gmx_fio_open(outputfile.filename, "r+");
+
+                /* lock log file */
+                if (firstFile)
+                {
+                    /* Note that there are systems where the lock operation
+                     * will succeed, but a second process can also lock the file.
+                     * We should probably try to detect this.
+                     */
 #if defined __native_client__
-                errno = ENOSYS;
-                if (1)
+                    errno = ENOSYS;
+                    if (1)
 
 #elif GMX_NATIVE_WINDOWS
-                if (_locking(fileno(gmx_fio_getfp(chksum_file)), _LK_NBLCK, LONG_MAX) == -1)
+                    if (_locking(fileno(gmx_fio_getfp(chksum_file)), _LK_NBLCK, LONG_MAX) == -1)
 #else
-                if (fcntl(fileno(gmx_fio_getfp(chksum_file)), F_SETLK, &fl) == -1)
+                    if (fcntl(fileno(gmx_fio_getfp(chksum_file)), F_SETLK, &fl) == -1)
 #endif
-                {
-                    if (errno == ENOSYS)
                     {
-                        if (!bForceAppend)
+                        if (errno == ENOSYS)
+                        {
+                            if (!bForceAppend)
+                            {
+                                gmx_fatal(FARGS, "File locking is not supported on this system. Use -noappend or specify -append explicitly to append anyhow.");
+                            }
+                            else
+                            {
+                                if (fplog)
+                                {
+                                    fprintf(fplog, "\nNOTE: File locking not supported on this system, will not lock %s\n\n", outputfile.filename);
+                                }
+                            }
+                        }
+                        else if (errno == EACCES || errno == EAGAIN)
                         {
-                            gmx_fatal(FARGS, "File locking is not supported on this system. Use -noappend or specify -append explicitly to append anyhow.");
+                            gmx_fatal(FARGS, "Failed to lock: %s. Already running "
+                                      "simulation?", outputfile.filename);
                         }
                         else
                         {
-                            if (fplog)
-                            {
-                                fprintf(fplog, "\nNOTE: File locking not supported on this system, will not lock %s\n\n", outputfile.filename);
-                            }
+                            gmx_fatal(FARGS, "Failed to lock: %s. %s.",
+                                      outputfile.filename, std::strerror(errno));
                         }
                     }
-                    else if (errno == EACCES || errno == EAGAIN)
-                    {
-                        gmx_fatal(FARGS, "Failed to lock: %s. Already running "
-                                  "simulation?", outputfile.filename);
-                    }
-                    else
-                    {
-                        gmx_fatal(FARGS, "Failed to lock: %s. %s.",
-                                  outputfile.filename, std::strerror(errno));
-                    }
                 }
-            }
 
-            /* compute md5 chksum */
-            if (outputfile.chksum_size != -1)
-            {
-                if (gmx_fio_get_file_md5(chksum_file, outputfile.offset,
-                                         digest) != outputfile.chksum_size) /*at the end of the call the file position is at the end of the file*/
+                /* compute md5 chksum */
+                if (outputfile.chksum_size != -1)
                 {
-                    gmx_fatal(FARGS, "Can't read %d bytes of '%s' to compute checksum. The file has been replaced or its contents have been modified. Cannot do appending because of this condition.",
-                              outputfile.chksum_size,
-                              outputfile.filename);
+                    if (gmx_fio_get_file_md5(chksum_file, outputfile.offset,
+                                             digest) != outputfile.chksum_size) /*at the end of the call the file position is at the end of the file*/
+                    {
+                        gmx_fatal(FARGS, "Can't read %d bytes of '%s' to compute checksum. The file has been replaced or its contents have been modified. Cannot do appending because of this condition.",
+                                  outputfile.chksum_size,
+                                  outputfile.filename);
+                    }
                 }
-            }
-            /* log file needs to be seeked in case we need to truncate
-             * (other files are truncated below)*/
-            if (firstFile)
-            {
-                if (gmx_fio_seek(chksum_file, outputfile.offset))
+                /* log file needs to be seeked in case we need to truncate
+                 * (other files are truncated below)*/
+                if (firstFile)
                 {
-                    gmx_fatal(FARGS, "Seek error! Failed to truncate log-file: %s.", std::strerror(errno));
+                    if (gmx_fio_seek(chksum_file, outputfile.offset))
+                    {
+                        gmx_fatal(FARGS, "Seek error! Failed to truncate log-file: %s.", std::strerror(errno));
+                    }
                 }
             }
-#endif
 
             /* open log file here - so that lock is never lifted
              * after chksum is calculated */
@@ -2462,9 +2467,9 @@ static void read_checkpoint(const char *fn, FILE **pfplog,
             {
                 gmx_fio_close(chksum_file);
             }
-#ifndef GMX_FAHCORE
             /* compare md5 chksum */
-            if (outputfile.chksum_size != -1 &&
+            if (!GMX_FAHCORE &&
+                outputfile.chksum_size != -1 &&
                 memcmp(digest, outputfile.chksum, 16) != 0)
             {
                 if (debug)
@@ -2479,20 +2484,23 @@ static void read_checkpoint(const char *fn, FILE **pfplog,
                 gmx_fatal(FARGS, "Checksum wrong for '%s'. The file has been replaced or its contents have been modified. Cannot do appending because of this condition.",
                           outputfile.filename);
             }
-#endif
 
-
-            if (!firstFile) /* log file is already seeked to correct position */
+            // We could preprocess less, but then checkers complain
+            // about possible bugs when using logic on constant
+            // expressions.
+#if !GMX_NATIVE_WINDOWS || !GMX_FAHCORE
+            // The log file is already seeked to correct position, but
+            // others must be truncated.
+            if (!firstFile)
             {
-#if !GMX_NATIVE_WINDOWS || !defined(GMX_FAHCORE)
                 /* For FAHCORE, we do this elsewhere*/
                 rc = gmx_truncate(outputfile.filename, outputfile.offset);
                 if (rc != 0)
                 {
                     gmx_fatal(FARGS, "Truncation of file %s failed. Cannot do appending because of this failure.", outputfile.filename);
                 }
-#endif
             }
+#endif
             firstFile = false;
         }
     }
index 4a2102df745122a2aa60b08fee9ef8fed15ca4b3..1c9de79bad05908cdf42ea319e54291b2f4731c7 100644 (file)
@@ -593,12 +593,13 @@ std::vector<gmx_file_position_t> gmx_fio_get_output_file_positions()
 
             /* Get the file position */
             gmx_fio_int_get_file_position(cur, &outputfiles.back().offset);
-#ifndef GMX_FAHCORE
-            outputfiles.back().chksum_size
-                = gmx_fio_int_get_file_md5(cur,
-                                           outputfiles.back().offset,
-                                           outputfiles.back().chksum);
-#endif
+            if (!GMX_FAHCORE)
+            {
+                outputfiles.back().chksum_size
+                    = gmx_fio_int_get_file_md5(cur,
+                                               outputfiles.back().offset,
+                                               outputfiles.back().chksum);
+            }
         }
 
         cur = gmx_fio_get_next(cur);
index 0d64071dca5637aecb541c3664fcc1055fb0a6ed..1ddf2c7ae050c2a4b3f53b4016e8f3baec5b18e5 100644 (file)
@@ -142,14 +142,13 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[],
                     gmx_incons("Invalid reduced precision file format");
             }
         }
-        if ((EI_DYNAMICS(ir->eI) || EI_ENERGY_MINIMIZATION(ir->eI))
-#ifndef GMX_FAHCORE
-            &&
-            !(EI_DYNAMICS(ir->eI) &&
-              ir->nstxout == 0 &&
-              ir->nstvout == 0 &&
-              ir->nstfout == 0)
-#endif
+        if ((EI_DYNAMICS(ir->eI) || EI_ENERGY_MINIMIZATION(ir->eI)) &&
+            (!GMX_FAHCORE &&
+             !(EI_DYNAMICS(ir->eI) &&
+               ir->nstxout == 0 &&
+               ir->nstvout == 0 &&
+               ir->nstfout == 0)
+            )
             )
         {
             const char *filename;
index d330b736c856c2906b1f2972ca8e020e2a358140..2414581dc46d369bd9ae289c25ca68db2e1a339a 100644 (file)
@@ -119,7 +119,7 @@ do_md_trajectory_writing(FILE                    *fplog,
         mdof_flags |= MDOF_LAMBDA_COMPRESSED;
     }
 
-#if defined(GMX_FAHCORE)
+#if GMX_FAHCORE
     if (bLastStep)
     {
         /* Enforce writing positions and velocities at end of run */
index 1834e633aaa23b868b5bb8276974f80c65502936..a6aa8eab8648344a0bf5e004e3b7c1e3d5bcc4cc 100644 (file)
 #include "integrator.h"
 #include "replicaexchange.h"
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
 #include "corewrap.h"
 #endif
 
@@ -201,10 +201,6 @@ void gmx::Integrator::do_md()
     /* Interactive MD */
     gmx_bool          bIMDstep = FALSE;
 
-#ifdef GMX_FAHCORE
-    /* Temporary addition for FAHCORE checkpointing */
-    int chkpt_ret;
-#endif
     /* Domain decomposition could incorrectly miss a bonded
        interaction, but checking for that requires a global
        communication stage, which does not otherwise happen in DD
@@ -571,10 +567,10 @@ void gmx::Integrator::do_md()
     wallcycle_start(wcycle, ewcRUN);
     print_start(fplog, cr, walltime_accounting, "mdrun");
 
+#if GMX_FAHCORE
     /* safest point to do file checkpointing is here.  More general point would be immediately before integrator call */
-#ifdef GMX_FAHCORE
-    chkpt_ret = fcCheckPointParallel( cr->nodeid,
-                                      NULL, 0);
+    int chkpt_ret = fcCheckPointParallel( cr->nodeid,
+                                          NULL, 0);
     if (chkpt_ret == 0)
     {
         gmx_fatal( 3, __FILE__, __LINE__, "Checkpoint error on step %d\n", 0 );
index 92d245e96af142b18f30d9b585a8fde8977643ff..678ba99535d7139db614d2b63f5a776d49681854 100644 (file)
 #include "integrator.h"
 #include "replicaexchange.h"
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
 #include "corewrap.h"
 #endif
 
@@ -749,7 +749,7 @@ int Mdrunner::mdrunner()
         }
     }
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
     if (MASTER(cr))
     {
         fcRegisterSteps(inputrec->nsteps, inputrec->init_step);
index 28c4f32e06cfb24318d26a0a6d030c03b7033e60..979e9752f28d474f61aac1dc8a1a37245a08f0c8 100644 (file)
@@ -147,23 +147,10 @@ void printCopyright(gmx::TextWriter *writer)
         "the Royal Institute of Technology, Sweden.",
         "check out http://www.gromacs.org for more information."
     };
-    static const char * const LicenseText[] = {
-        "GROMACS is free software; you can 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."
-    };
 
 #define NCONTRIBUTORS static_cast<int>(asize(Contributors))
 #define NCR static_cast<int>(asize(CopyrightText))
 
-// FAH has an exception permission from LGPL to allow digital signatures in Gromacs.
-#ifdef GMX_FAHCORE
-#define NLICENSE 0
-#else
-#define NLICENSE static_cast<int>(asize(LicenseText))
-#endif
-
     // TODO a centering behaviour of TextWriter could be useful here
     writer->writeLine(formatCentered(78, "GROMACS is written by:"));
     for (int i = 0; i < NCONTRIBUTORS; )
@@ -189,9 +176,16 @@ void printCopyright(gmx::TextWriter *writer)
         writer->writeLine(CopyrightText[i]);
     }
     writer->ensureEmptyLine();
-    for (int i = 0; i < NLICENSE; ++i)
+
+    // Folding At Home has different licence to allow digital
+    // signatures in GROMACS, so does not need to show the normal
+    // license statement.
+    if (!GMX_FAHCORE)
     {
-        writer->writeLine(LicenseText[i]);
+        writer->writeLine("GROMACS is free software; you can redistribute it and/or modify it");
+        writer->writeLine("under the terms of the GNU Lesser General Public License");
+        writer->writeLine("as published by the Free Software Foundation; either version 2.1");
+        writer->writeLine("of the License, or (at your option) any later version.");
     }
 }
 
index a15b7bc4e98a769dc26df03e363ae86040feef05..c2178ba974b6d5fc8c99e7ce129587ea7a92a49d 100644 (file)
@@ -156,7 +156,7 @@ static void push_ps(FILE *fp)
     pstack   = ps;
 }
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
 /* don't use pipes!*/
 #define popen fah_fopen
 #define pclose fah_fclose
@@ -719,7 +719,7 @@ int gmx_fsync(FILE *fp)
 {
     int rc = 0;
 
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
     /* the fahcore defines its own os-independent fsync */
     rc = fah_fsync(fp);
 #else /* GMX_FAHCORE */
index 75eb9aed381e200ebb898948bd02e26e3f1f862d..5609e94a515501f722b78aa3a2dd304581563d25 100644 (file)
@@ -81,7 +81,7 @@ void init(int *argc, char ***argv) // NOLINT(readability-non-const-parameter)
     }
     else
     {
-#ifdef GMX_FAHCORE
+#if GMX_FAHCORE
         fah_MPI_Init(argc, argv);
 #else
 #    if GMX_OPENMP