1. Compilation of TOUGH4 using Visual Studio
Last updated
Last updated
Before starting compilation of TOUGH4 with Visual studio, several supporting software must be installed in your computer system, including:
(1) Microsoft Visual Studio 2017 or later version.
(2) Fortran compiler integrated with Visual Studio. We recommend installation of the oneAPI which includes the Intel Fortran compiler.
(3) Microsoft MPI (MS-MPI). This is needed only when you intend to compile the TOUGH code with MPI supported parallel computing. Other MPI may also work, such as Intel MPI.
(4) OpenCL or CUDA drivers based on the GPU type on your computer. This is needed only when you intend to compile the TOUGH with GPU supported parallel computing from third-party linear solvers.
(5) METIS V5.0 or late version if you want to use Metis for mesh partitioning.
Some linear solver packages, such as PETSC and Trilinos, may also be needed, but it is challenging to install them under Windows. We do not recommend the installation of these packages. Instructions for installation of above listed public domain software can be found online. The compilation of the Metis can be done through the Visual Studio. The VS solution file for Metis compilation is included in the TOUGH4 installation package.
Once all the required software is ready, we can start the compilation of TOUGH4 in the following steps.
(1) Unzip the TOUGH installation package into a working folder, e.g. c:\tough4.
(2) In the working folder, you can find a VS solution file named TOUGH2022.sln. Double click this file, Visual Studio will open TOUGH4 projects. The provided solution file is for VS2017. If you are using a different version of VS, please allow the VS automatic update of the solution file to corresponding version.
(3) Edit the "toguhSetUp.fi" file as discussed in the previous section. Make sure you comment out the lines for the software that has not been installed on your computer.
(4) The compilation can be done in two modes, "debug" or "release". Most users may not need the "debug" mode, as it is for debugging purposes and the generated executable is very slow for running simulations. We will discuss the compilation in "release" mode for “x64” platform only. Use the pull-down menu to select the compilation configuration type “release” and platform type x64 (based on your CPU type). The pull-down menu is located at the top of VS main window.
(5) Open the Solution Explorer window. You will find two projects: "LinearSolverInterface" and "TOUGH2002" as shown in Figure 3.
(6) Next step is to edit the property of the two projects. The purpose of editing project property is to tell the VS how the codes will be compiled, which libraries will be liked, where are the requested libraries located. Only a couple items need to be changed/inputted, most of them remain no change.
For the project "TOUGH2022", the following items may be needed for modification.
-- In the Solution Explorer Window, right click on the project name "TOUGH2022", and then click "Property". The TOUGH2022 property page will open up (Figure 4). Make sure the configuration is for "release" and platform is for “x64”.
-- Configuration properties->Fortran->Preprocessor->Preprocess Source File, select "Yes".
-- Configuration properties->Fortran->Preprocessor-> Additional include Directories, put the Include directories here. (e.g. C:\Program Files (x86)\Microsoft SDKs\MPI\Include;C:\Program Files (x86)\Microsoft SDKs\MPI\Include\x64). This is only needed when the MPI is required for the compilation.
-- Configuration properties->Fortran->Language->Source File Format, select “Use Free Format”
-- Configuration properties->Fortran->Language->Process OpenMP Directives, select "Generate Parallel Code".
-- Configuration properties->Fortran->Data->Default Integer KIND, select “4”
-- Configuration properties->Fortran->Data->Default Real KIND, select “8”
-- Configuration properties->Fortran->Data->Default Double Precision KIND, select “8”
-- Configuration properties->Linker->General->Additional Library Directories, input the directories of libraries that the code going to link (e.g C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64 C:\metis\libmetis\Release C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64). You may add the location directories of compiled libraries for the MPI, Metis, and/or OpenCL which are selected (defined in "toguhSetUp.fi").
-- Configuration properties->Linker->Input->Additional Dependencies: put the names of library files here (e.g. msmpi.lib msmpifec.lib msmpifmc.lib metis.lib LinearSolverInterface.lib OpenCL.lib). These files can be found in the directories specified in the previous item except LinearSolverInterface.lib which will be built by project “LinearSolverInterface”. You need to remove the libraries, if they do not exist.
Once successfully installed MS-MPI, you can find the library files msmpi.lib, msmpifec.lib and msmpifmc.lib. You are also required to find directories of these files and the header files located. This information needs to be passed into project properties through the above configuration procedure. If different MPI is installed, the library file will be in different names. Same approach is also required for the Metis, OpenCL, or CUDA if they are included in the compilation.
For the Project "LinearSolverInterface", the following items may be needed for modification.
-- In the Solution Explorer Window, right click on the project name "LinearSolverInterface", and then click "Property". The LinearSolverInterface property page will open up (Figure 5). Make sure the configuration is for "release" and platform is for “x64”.
-- Configuration properties->C/C++->General->Additional Include Directories, input the directories of include header files for MPI and selected linear solvers (e.g. C:\Program Files (x86)\Microsoft SDKs\MPI\Include;C:\Program Files (x86)\MicrosoftSDKs\MPI\Include\x64). The AMGCL and VIENNACL are header only library, their including directories are not required.
Once setup for the project property is ready, you can compile the TOUGH4 by clicking on the menu Build