Skip to content

Commit

Permalink
Updates to build on Windows with Visual Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchwiebert committed Nov 30, 2024
1 parent 69b4ebc commit 64eba6e
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 37 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if(NOT GOMC_ASAN)
set(CMAKE_CLANG_COMP_FLAGS ${CMAKE_CLANG_COMP_FLAGS} ${OpenMP_CXX_FLAGS})
set(CMAKE_CLANG_CUDA_COMP_FLAGS ${CMAKE_CLANG_CUDA_COMP_FLAGS} "SHELL:-Xcompiler ${OpenMP_CXX_FLAGS}")
set(CMAKE_CLANG_LINK_FLAGS ${CMAKE_CLANG_LINK_FLAGS} ${OpenMP_CXX_FLAGS})
set(CMAKE_MSVC_OPENMP_FLAGS "/openmp:llvm")
endif()
endif()

Expand Down Expand Up @@ -93,12 +94,12 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_GPU_COMP_FLAGS "${CMAKE_CLANG_CUDA_COMP_FLAGS}")
set(CMAKE_LINK_FLAGS "${CMAKE_CLANG_LINK_FLAGS}")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT} /D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} /MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} /MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} /MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT} /MT /Zi /O2 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_MSVC_OPENMP_FLAGS} /D DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /D DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

# Set Source and Header files
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ To cite GOMC project, please cite the following papers:
2. Set the Source Folder to the GOMC root folder.
3. Set the Build Folder to your build folder.
4. Click Configure, select your compiler/environment.
5. Wait for CMake to finish the configuration.
6. Click Configure again and click Generate.
7. If your version of CUDA is older than CUDA 11, download the [CUB library](https://nvlabs.github.io/cub/download_cub.html).
8. If your version of CUDA is older than CUDA 11, extract the CUB library and copy the "cub" folder from the CUB library into the "lib" folder inside the GOMC directory.
9. Open the CMake-generated project/solution etc. in the desired IDE (e.g., Visual Studio).
5. Wait for CMake to finish creating the configuration.
6. Click Generate.
7. If building GPU executables and the CUDA version is older than CUDA 11, download the [CUB library](https://nvlabs.github.io/cub/download_cub.html).
8. If building GPU executables and the CUDA version is older than CUDA 11, extract the CUB library and copy the "cub" folder from the CUB library into the "lib" folder inside the GOMC directory.
9. Open the CMake-generated project/solution file, located in your Build Folder, in the desired IDE (e.g., Visual Studio).
10. Using the solution in the IDE, build GOMC per the IDE's standard release compilation/executable generation methods.
> NOTES: You can also use CMake from the Windows command line if its directory is added to the PATH environment variable.
Expand Down
1 change: 1 addition & 0 deletions lib/BasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ along with this program, also can be found at
#ifndef BASIC_TYPES_H
#define BASIC_TYPES_H

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstddef>
#include <fstream>
Expand Down
14 changes: 10 additions & 4 deletions lib/GeomLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ along with this program, also can be found at
// Standard way to get pi constant on most platforms
// Needs to be defined _before_ including cmath
// so that the PI constants come from cmath
#define _USE_MATH_DEFINES

#include <cmath> //For sqrt, fabs, M_PI
#include <limits> //for double limits
//#define _USE_MATH_DEFINES
//#include <cmath> //For sqrt, fabs, M_PI

#include "BasicTypes.h" //For uint, XYZ
#include "XYZArray.h"
#include <limits> //for double limits

/////////////////////////////////////////////////////////////
// DEFINES //
Expand All @@ -30,6 +29,10 @@ along with this program, also can be found at
#define M_PI \
3.14159265358979323846264338327950288419716939937510582097494459230781640629
#endif
#ifndef M_1_PI
// Reciprocal of PI:
#define M_1_PI 1.0 / M_PI
#endif
#ifndef M_PI_2
// From Mathematica:
// N[Pi/2, 75]
Expand All @@ -40,6 +43,9 @@ along with this program, also can be found at
#define M_PI_4 \
0.785398163397448309615660845819875721049292349843776455243736148076954101572
#endif
#ifndef M_2_SQRTPI
#define M_2_SQRTPI 2.0 / std::sqrt(M_PI)
#endif

#define DEG_TO_RAD (M_PI / 180.0)
#define RAD_TO_DEG (180.0 * M_1_PI) // Same as 180/PI
Expand Down
6 changes: 3 additions & 3 deletions lib/NumLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ along with this program, also can be found at
#define NUMERIC_LIB_H

#include "BasicTypes.h" //For uint, XYZ
#include <cmath>
#include <iostream>
#include <limits> //for double limits
#include <vector> //for vector average
Expand Down Expand Up @@ -196,7 +195,8 @@ inline double POW(const double d2, const double d4, const double d6, uint e) {
// Class to define the function used in Zbrent
class Exp6Fun {
public:
Exp6Fun(const double a, const double s) : sigma(s), alpha(a) {}
Exp6Fun(const float a, const float s, const float r = 0.0) : sigma(s),
alpha(a), rmin(r) {}
virtual ~Exp6Fun(){};
virtual float operator()(float x) = 0;

Expand All @@ -216,7 +216,7 @@ class RminFun : public Exp6Fun {

class RmaxFun : public Exp6Fun {
public:
RmaxFun(double a, double s, double r) : Exp6Fun(a, s) { rmin = r; }
RmaxFun(double a, double s, double r) : Exp6Fun(a, s, r) {}
virtual ~RmaxFun(){};
virtual float operator()(float x) {
double rep = (-1.0 / rmin) * exp(alpha * (1.0 - x / rmin));
Expand Down
2 changes: 1 addition & 1 deletion lib/VectorLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ template <typename T> T *TransferInto(T *array, const std::vector<T> &vec) {
// overloaded because vector<bool> is a lie and copy may not be supported
inline bool *transfer(const std::vector<bool> &vec) {
bool *array = new bool[vec.size()];
for (unsigned int i = 0; i < vec.size(); ++i) {
for (size_t i = 0; i < vec.size(); ++i) {
array[i] = vec[i];
}
return array;
Expand Down
2 changes: 1 addition & 1 deletion src/CheckpointSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void CheckpointSetup::SetCheckpointData(bool &parallelTemperingIsEnabled,
void CheckpointSetup::SetStepNumber() { startStepRef = chkObj.stepNumber; }

void CheckpointSetup::SetTrueStepNumber() {
printf("%-40s %-lu \n", "Info: Loading true step from checkpoint",
printf("%-40s %-l64u \n", "Info: Loading true step from checkpoint",
chkObj.trueStepNumber);
trueStepRef = chkObj.trueStepNumber;
}
Expand Down
18 changes: 9 additions & 9 deletions src/ConfigSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeBox(idx, b);
sys.intraTargetedSwapCollection.AddsubVolumeBox(idx, b);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 2 values for SubVolumeBox, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -457,7 +457,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeCenter(idx, temp);
sys.intraTargetedSwapCollection.AddsubVolumeCenter(idx, temp);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 4 values for SubVolumeCenter, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -468,7 +468,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumePBC(idx, line[2]);
sys.intraTargetedSwapCollection.AddsubVolumePBC(idx, line[2]);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 2 values for SubVolumePBC, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -483,7 +483,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeAtomList(idx, temp);
sys.intraTargetedSwapCollection.AddsubVolumeAtomList(idx, temp);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected atleast 3 values for SubVolumeCenterList, but "
"received",
line.size() - 1);
Expand All @@ -499,7 +499,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeDimension(idx, temp);
sys.intraTargetedSwapCollection.AddsubVolumeDimension(idx, temp);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 4 values for SubVolumeDim, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -515,7 +515,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeResKind(idx, temp);
sys.intraTargetedSwapCollection.AddsubVolumeResKind(idx, temp);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected atleast 2 values for SubVolumeResidueKind, but "
"received",
line.size() - 1);
Expand All @@ -528,7 +528,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeSwapType(idx, isRigid);
sys.intraTargetedSwapCollection.AddsubVolumeSwapType(idx, isRigid);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 2 values for SubVolumeRigidSwap, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -544,7 +544,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeChemPot(idx, resName, value,
isFugacity);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 3 values for SubVolumeChemPot, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand All @@ -558,7 +558,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const *const &multisim) {
sys.targetedSwapCollection.AddsubVolumeChemPot(idx, resName, value,
isFugacity);
} else {
printf("%-40s %-lu !\n",
printf("%-40s %-zu !\n",
"ERROR: Expected 3 values for SubVolumeFugacity, but received",
line.size() - 1);
exit(EXIT_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ struct TargetSwapCollection {
(std::find(newKind.begin(), newKind.end(), "All") != newKind.end());
if (selectedAll) {
if (newKind.size() > 1) {
printf("Warning: %lu additional residue kinds were defined for "
printf("Warning: %zu additional residue kinds were defined for "
"subVolume index %d, while using all residues!\n",
newKind.size() - 1, subVIdx);
printf(
Expand Down
2 changes: 0 additions & 2 deletions src/Coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ along with this program, also can be found at
********************************************************************************/
#include "Coordinates.h"

#include <algorithm> //For copy
#include <cassert>
#include <cmath>

#include "TransformMatrix.h"

Expand Down
2 changes: 1 addition & 1 deletion src/DCDlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ OFF_T NAMD_seek(int file, OFF_T offset, int whence) {
if (whence == SEEK_SET && retval != offset) {
char buf[256];
sprintf(buf,
"seek failed while writing DCD file: SEEK_SET %ld returned %ld\n",
"seek failed while writing DCD file: SEEK_SET %lld returned %lld\n",
offset, retval);
NAMD_die(buf);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Random123Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ along with this program, also can be found at
#ifndef RANDOM123_WRAPPER_H
#define RANDOM123_WRAPPER_H

#ifdef _MSC_VER
#define R123_NO_SINCOS 1
#endif

#include "BasicTypes.h"
#include "Random123/philox.h"
typedef r123::Philox4x64 RNG;
Expand Down
2 changes: 0 additions & 2 deletions src/TransformMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ along with this program, also can be found at
#define TRANSFORM_MATRIX_H

#include "BasicTypes.h"
#define _USE_MATH_DEFINES
#include <cmath> //cos and sin

class TransformMatrix;
typedef TransformMatrix RotationMatrix;
Expand Down
2 changes: 1 addition & 1 deletion src/moves/IntraTargetedSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ void IntraTargetedSwap::PrintIntraTargetedSwapInfo() {
tsp.subVolumeIdx);
printf("%-40s %d \n", " SubVolume Box:", b);
if (tsp.calcSubVolCenter) {
printf("%-40s Using %lu defined atom indexes \n",
printf("%-40s Using %zu defined atom indexes \n",
" Calculating subVolume center:", tsp.atomList.size());
int max = *std::max_element(tsp.atomList.begin(), tsp.atomList.end());
if (max >= (int)coordCurrRef.Count()) {
Expand Down
2 changes: 1 addition & 1 deletion src/moves/TargetedSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void TargetedSwap::PrintTargetedSwapInfo() {
tsp.subVolumeIdx);
printf("%-40s %d \n", " SubVolume Box:", b);
if (tsp.calcSubVolCenter) {
printf("%-40s Using %lu defined atom indexes \n",
printf("%-40s Using %zu defined atom indexes \n",
" Calculating subVolume center:", tsp.atomList.size());
int max = *std::max_element(tsp.atomList.begin(), tsp.atomList.end());
if (max >= (int)coordCurrRef.Count()) {
Expand Down

0 comments on commit 64eba6e

Please sign in to comment.