Fix Visual Studio build
authorRoland Schulz <roland.schulz@intel.com>
Thu, 10 Sep 2020 04:51:17 +0000 (21:51 -0700)
committerPaul Bauer <paul.bauer.q@gmail.com>
Thu, 10 Sep 2020 15:35:32 +0000 (15:35 +0000)
- Add /permissive- flag to disable MSVC extension. Fixes
  ternary operator.
- Fix usage of %l for size_t
- Disable non-wroking FFTW SIMD check
- Missing imports
- Compiler warning fix

cmake/FindFFTW.cmake
cmake/gmxCFlags.cmake
cmake/gmxManageFFTLibraries.cmake
src/gromacs/hardware/device_management_common.cpp
src/gromacs/mdlib/md_support.cpp
src/gromacs/mdtypes/checkpointdata.h
src/gromacs/mdtypes/energyhistory.cpp
src/gromacs/nbnxm/pairlist.cpp

index f46fe2c21b2797d3a789853de951904a5410a8a6..b1f5827d34ba143e7fe1f8921aa6aaab5eebb754 100644 (file)
@@ -106,56 +106,58 @@ if (${FFTW}_FOUND)
       message(FATAL_ERROR "Could not find ${${FFTW}_FUNCTION_PREFIX}_plan_many_[r2c|c2r] in ${${FFTW}_LIBRARY}, take a look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what went wrong. If you are using a static lib (.a) make sure you have specified all dependencies of ${${FFTW}_PKG} in ${FFTW}_LIBRARY by hand (e.g. -D${FFTW}_LIBRARY='/path/to/lib${${FFTW}_PKG}.so;/path/to/libm.so') !")
   endif()
 
-  # Check for FFTW3 compiled with --enable-sse
-  foreach(SSE_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse ${${FFTW}_FUNCTION_PREFIX}_have_sse)
-    if (FFTW_LIBRARY_CHANGED)
-      unset(${FFTW}_HAVE_${SSE_FUNCTION} CACHE)
-    endif()
-    check_library_exists("${${FFTW}_LIBRARIES}" "${SSE_FUNCTION}" "" ${FFTW}_HAVE_${SSE_FUNCTION})
-    if(${FFTW}_HAVE_${SSE_FUNCTION})
-      set(${FFTW}_HAVE_SSE TRUE)
-      set(${FFTW}_HAVE_SIMD TRUE)
-      break()
-    endif()
-  endforeach()
-
-  # Check for FFTW3 compiled with --enable-sse2
-  foreach(SSE2_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse2 ${${FFTW}_FUNCTION_PREFIX}_have_sse2)
-    if (FFTW_LIBRARY_CHANGED)
-      unset(${FFTW}_HAVE_${SSE2_FUNCTION} CACHE)
-    endif()
-    check_library_exists("${${FFTW}_LIBRARIES}" "${SSE2_FUNCTION}" "" ${FFTW}_HAVE_${SSE2_FUNCTION})
-    if(${FFTW}_HAVE_${SSE2_FUNCTION})
-      set(${FFTW}_HAVE_SSE2 TRUE)
-      set(${FFTW}_HAVE_SIMD TRUE)
-      break()
+  if(NOT WIN32) # *_have_* functions aren't external. Thus aren't visible on Windows.
+    # Check for FFTW3 compiled with --enable-sse
+    foreach(SSE_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse ${${FFTW}_FUNCTION_PREFIX}_have_sse)
+      if (FFTW_LIBRARY_CHANGED)
+        unset(${FFTW}_HAVE_${SSE_FUNCTION} CACHE)
+      endif()
+      check_library_exists("${${FFTW}_LIBRARIES}" "${SSE_FUNCTION}" "" ${FFTW}_HAVE_${SSE_FUNCTION})
+      if(${FFTW}_HAVE_${SSE_FUNCTION})
+        set(${FFTW}_HAVE_SSE TRUE)
+        set(${FFTW}_HAVE_SIMD TRUE)
+        break()
+      endif()
+    endforeach()
+    
+    # Check for FFTW3 compiled with --enable-sse2
+    foreach(SSE2_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse2 ${${FFTW}_FUNCTION_PREFIX}_have_sse2)
+      if (FFTW_LIBRARY_CHANGED)
+        unset(${FFTW}_HAVE_${SSE2_FUNCTION} CACHE)
+      endif()
+      check_library_exists("${${FFTW}_LIBRARIES}" "${SSE2_FUNCTION}" "" ${FFTW}_HAVE_${SSE2_FUNCTION})
+      if(${FFTW}_HAVE_${SSE2_FUNCTION})
+        set(${FFTW}_HAVE_SSE2 TRUE)
+        set(${FFTW}_HAVE_SIMD TRUE)
+        break()
+      endif()
+    endforeach()
+    
+    # Check for any other SIMD support in FFTW
+    if (NOT ${FFTW}_HAVE_SIMD)
+        foreach(SIMD_FCT
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2_128
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx512
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_128_fma
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_512
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_kcvi
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_neon
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_vsx
+                ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
+                ${${FFTW}_FUNCTION_PREFIX}_have_altivec) # Name used before FFTW 3.3
+            if (FFTW_LIBRARY_CHANGED)
+                unset(${FFTW}_HAVE_${SIMD_FCT} CACHE)
+            endif()
+            check_library_exists("${${FFTW}_LIBRARIES}" "${SIMD_FCT}" "" ${FFTW}_HAVE_${SIMD_FCT})
+            if(${FFTW}_HAVE_${SIMD_FCT})
+                set(${FFTW}_HAVE_SIMD TRUE)
+                break()
+            endif()
+        endforeach()
     endif()
-  endforeach()
-
-  # Check for any other SIMD support in FFTW
-  if (NOT ${FFTW}_HAVE_SIMD)
-      foreach(SIMD_FCT
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2_128
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx512
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_128_fma
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_512
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_kcvi
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_neon
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_vsx
-              ${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
-              ${${FFTW}_FUNCTION_PREFIX}_have_altivec) # Name used before FFTW 3.3
-          if (FFTW_LIBRARY_CHANGED)
-              unset(${FFTW}_HAVE_${SIMD_FCT} CACHE)
-          endif()
-          check_library_exists("${${FFTW}_LIBRARIES}" "${SIMD_FCT}" "" ${FFTW}_HAVE_${SIMD_FCT})
-          if(${FFTW}_HAVE_${SIMD_FCT})
-              set(${FFTW}_HAVE_SIMD TRUE)
-              break()
-          endif()
-      endforeach()
   endif()
 
   #Verify FFTW is compiled with fPIC (necessary for shared libraries)
index 7f7e46632643afbb65aa1cb927b96b62282b12d9..5789f62e51cdfb884d4d3932e85b3873f883078b 100644 (file)
@@ -407,6 +407,7 @@ GMX_TEST_CFLAG(CFLAGS_WARN "/W3;/wd161;/wd177;/wd411;/wd593;/wd981;/wd1418;/wd14
         else() # MSVC projects only use the C++ flags
             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068;" GMXC_CXXFLAGS)
         endif()
+        GMX_TEST_CXXFLAG(CXXFLAGS_LANG "/permissive-" GMXC_CXXFLAGS)
     endif()
 
     if (CMAKE_C_COMPILER_ID MATCHES "Clang")
index 65434390aa093cdb0ac75680ac424e91afdabd70..f59e011ecc86f7f72d27d668424ce369b5c0e6ec 100644 (file)
@@ -96,14 +96,16 @@ if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
         set(PKG_FFT "${${FFTW}_PKG}")
         include_directories(SYSTEM ${${FFTW}_INCLUDE_DIRS})
 
-        if ((${GMX_SIMD_ACTIVE} MATCHES "SSE" OR ${GMX_SIMD_ACTIVE} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD)
-            set(FFT_WARNING_MESSAGE "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
-        else()
-            if(${GMX_SIMD_ACTIVE} MATCHES "AVX" AND NOT (${FFTW}_HAVE_SSE OR ${FFTW}_HAVE_SSE2))
-                # If we end up here we have an AVX Gromacs build, and
-                # FFTW with SIMD.
-                set(FFT_WARNING_MESSAGE "The FFTW library was compiled with neither --enable-sse nor --enable-sse2; those would have enabled SSE(2) SIMD instructions. This will give suboptimal performance. You should (re)compile the FFTW library with --enable-sse2 and --enable-avx (and --enable-avx2 or --enable-avx512 if supported).")
-            endif()
+        if(NOT WIN32) # Detection doesn't work on Windows
+          if ((${GMX_SIMD_ACTIVE} MATCHES "SSE" OR ${GMX_SIMD_ACTIVE} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD)
+              set(FFT_WARNING_MESSAGE "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
+          else()
+              if(${GMX_SIMD_ACTIVE} MATCHES "AVX" AND NOT (${FFTW}_HAVE_SSE OR ${FFTW}_HAVE_SSE2))
+                  # If we end up here we have an AVX Gromacs build, and
+                  # FFTW with SIMD.
+                  set(FFT_WARNING_MESSAGE "The FFTW library was compiled with neither --enable-sse nor --enable-sse2; those would have enabled SSE(2) SIMD instructions. This will give suboptimal performance. You should (re)compile the FFTW library with --enable-sse2 and --enable-avx (and --enable-avx2 or --enable-avx512 if supported).")
+              endif()
+          endif()
         endif()
 
         find_path(ARMPL_INCLUDE_DIR "armpl.h" HINTS ${${FFTW}_INCLUDE_DIRS}
index d505833d76124aa2b67a4dabb154c996d3451d90..3d043234321f3df055a78cd76fb54da9ac709711 100644 (file)
@@ -60,7 +60,14 @@ bool canPerformDeviceDetection(std::string* errorMessage)
 
 bool isDeviceDetectionEnabled()
 {
-    return c_binarySupportsGpus && getenv("GMX_DISABLE_GPU_DETECTION") == nullptr;
+    if (c_binarySupportsGpus)
+    {
+        return getenv("GMX_DISABLE_GPU_DETECTION") == nullptr;
+    }
+    else
+    {
+        return false;
+    }
 }
 
 bool canComputeOnDevice()
index eab2e1e69a0709de12d8421ca592817ad51ea50b..26c19efa166ccea033ae2885c5585bacb070f485 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/gmxlib/network.h"
 #include "gromacs/gmxlib/nrnb.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/coupling.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
index b82da7cf1e72cdceebac689d78c7848ec316594d..e2a2f8829c73a297171969662445de3e584a9dd4 100644 (file)
@@ -42,6 +42,8 @@
 #ifndef GMX_MODULARSIMULATOR_CHECKPOINTDATA_H
 #define GMX_MODULARSIMULATOR_CHECKPOINTDATA_H
 
+#include <optional>
+
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/keyvaluetreebuilder.h"
index a0c09a08e2f290fed1109c06e0569ee923eb9a7e..5cadd9e4cbad4f9445bddc6b031ec144d34164d2 100644 (file)
@@ -92,8 +92,8 @@ void delta_h_history_t::doCheckpoint(gmx::CheckpointData<operation> checkpointDa
     checkpointData.scalar("start_lambda_set", &start_lambda_set);
     for (std::size_t idx = 0; idx < dh.size(); ++idx)
     {
-        checkpointVectorSize(&checkpointData, gmx::formatString("vecSize %lu", idx), &dh[idx]);
-        checkpointData.arrayRef(gmx::formatString("vec %lu", idx),
+        checkpointVectorSize(&checkpointData, gmx::formatString("vecSize %zu", idx), &dh[idx]);
+        checkpointData.arrayRef(gmx::formatString("vec %zu", idx),
                                 gmx::makeCheckpointArrayRef<operation>(dh[idx]));
     }
 }
index 95f8243c88732a82131641144d4bd3d192a740a6..aa29c61cdee6f7057a5014fbdaf4139fc09ce19c 100644 (file)
@@ -3638,7 +3638,7 @@ static void print_reduction_cost(gmx::ArrayRef<const gmx_bitmask_t> flags, int n
     }
     const auto numFlags = static_cast<double>(flags.size());
     fprintf(debug,
-            "nbnxn reduction: #flag %lu #list %d elem %4.2f, keep %4.2f copy %4.2f red %4.2f\n",
+            "nbnxn reduction: #flag %zu #list %d elem %4.2f, keep %4.2f copy %4.2f red %4.2f\n",
             flags.size(), nout, nelem / numFlags, nkeep / numFlags, ncopy / numFlags, nred / numFlags);
 }