A brief introduction of windows gromacs compiled by Visual Studio

## CMake usage

Firstly, you should unpack installation package of gromacs, then, choosing the path of ‘Where is the source code’ and ‘Where is build the binaries’. Next, click Configure button, then we choose ‘Visual Studio 15 2017 Win64’ option by drop-down list and using default native compliers(cl). If you use other VS version, you need match the corresponding option. The figure as follow:

Clicking Finish button, waiting…,, then some errors may occur, a common error is ‘Cannot find FFTW 3’. Here, you are able to assign the path of MKL include and MKL library after choosing GMX_FFT_LIBRARY to MKL. For example, as follow:
include:

library:

GPU is optional, if you want to compile GPU version, you should open the option of GMX_GPU to ON. Next, re-clicking Configure button until you pass cmake or no error, now you can click Generate button.
Note: I don’t recommend you use CMake version 3.14, because some error will occur. You can find it in this website, I was also in trouble while using 3.14 version.

## VS usage

Open Gromacs.sln file in your build path, then choosing Release option on toolbar. You should right click on gmx solution to choose Use Intel C++. Finally, right click again to choose build option, now we need wait a long until finish. Then, you can right click INSTALL solution to install compiled .exe file to default path(you can find it in C:/Program Files/Gromacs folder).

## Finish and usage

You can find the below file after compiling finish.

After setting up correct environment variable on windows, you can use it as below:

Questions:
I found that the GPU version of GROMACS 5.X could be compiled successfully, but GROMACS 2016/2018.X version only could compile CPU version, not GPU version. It reminds error information error : identifier "c_oneSixth" is undefined,..., it also was found in this website. I can not find a good way to solve this question.

## Supplements（2018.2.12)

### The above mentioned error that definition variable does not recognize has been solved(gromacs 2016)

Solution one: Reference material[4]. Simple note: CUDA does not recognize static const float that defined floating point type, you can change const to __constant__ for solving it. the changed file is:

changed it to the below:

Solution two: Recently, when compiling the Windows gromacs2019.1-gpu version (the compilation process is more time-consuming than the previous version), I found that there was no the above error. When looking at the source code, I found that this section has been changed to the CUDA global variable bug mention, as below:

but also met other question[only occur in VS2017 RTW 15.0], the final I solve it.

### The CUDA version question occurred in full series of Gromacs2018.X

When you use CMake, the error is CUDA compiler does not seem to be functional, but in fact CUDA is no problem. You could add Control options GMX_NVCC_WORKS=ON in order to skip nvcc detection, now cmake will pass correctly. When in the compiling process, undefined M_PI problem occurred, this is because the constant is not defined in the VS-related header file, the problem can be found bug. The approach given by the developers is to add #include <math_constants.h> into src/gromacs/ewald/pme-solve.cu file and change M_PI to CUDART_PI_F. It can be seen that the software compiled on different platforms is quite different. Gromacs source code has been constantly updated and improved.

### Eliminating C4819 warning（If necessary）

When you cmake, add -Xcompiler "/wd 4819" word into CUDA_NVCC_FLAGS

### One-click installation

Here, I have provided two simple installation scripts. If your previous software environment has been configured correctly, you can use Microsoft MKL library or FFTW library to compile CPU/GPU version of gromacs 5.x/2016.x/2018.x/2019.x.
Note: MKL library is not recommended, there is no advantages compared with FFTW , and configuration is also troublesome, FFTW software is small, fast compilation; When compiling with VS, it is highly recommended to use the Intel C++ compiler instead of the C++ compiler from VS. The Intel C++ compiler maximizes the efficiency of the software.

### Improve the efficiency of compilation

We noticed that the compiling efficiency is very low by the above setting, that is gromacs is compilied via a single core of CPU. In order to improve the utilization of CPU, we need install JOM or Ninja on Windows, it supports the execution of multiple independent commands in parallel. It is very easy to install on Windows. Finally, you should open VS command prompt (X64) to use Cmake command the above mentioned. Here, you are supposed to replace -G "Visual Studio 15 2017 Win64" with -G "NMake Makefiles JOM" or "Ninja". Yes! Now you will use all cores of CPU to compile gromacs by cmake --build . --target INSTALL --config Release -j 4, the 4 indicates your core number.

Watching

## Regressiontest

After installing GROMACS on Linux we usually requires simple tests. For example, you can add the -DREGRESSIONTEST_DOWNLOAD=ON option when you cmake on Linux. You can download test package on Windows, such as the 2019.3 version of http://gerrit.gromacs.org/download/regressiontests-2019.3.tar.gz. Uncompressing and executing ./gmxtest.pl all or perl gmxtest.pl all to test all cases.

## Windows x64 GROMACS with CUDA 10.0 （AVX2_256） (Only provided the latest version)

In order to use CUDA acceleration on other Windows OS with GPU, you must install >=411.31 driver version of GPU.