Skip to content

Commit

Permalink
Updates to resolve MSVC warnings and improve MSVC build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchwiebert committed Dec 3, 2024
1 parent 64f8f80 commit 713622a
Show file tree
Hide file tree
Showing 31 changed files with 27 additions and 91 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(GOMC_ASAN)
set(CMAKE_CLANG_COMP_FLAGS ${CMAKE_CLANG_COMP_FLAGS} -fsanitize=address -fno-omit-frame-pointer)
set(CMAKE_CLANG_CUDA_COMP_FLAGS ${CMAKE_CLANG_CUDA_COMP_FLAGS} "SHELL:-Xcompiler -fsanitize=address" "SHELL:-Xcompiler -fno-omit-frame-pointer")
set(CMAKE_CLANG_LINK_FLAGS ${CMAKE_CLANG_LINK_FLAGS} -fsanitize=address -fno-omit-frame-pointer)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /fsanitize=address")
endif()

# find OpenMP and set it up
Expand Down Expand Up @@ -94,12 +95,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} ${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")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_MSVC_OPENMP_FLAGS} /D DEBUG /MTd /Zi /Ob0 /Od /RTC1 /D_USE_MATH_DEFINES")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /D DEBUG /MTd /Zi /Ob0 /Od /RTC1 /D_USE_MATH_DEFINES")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O1 /Ob1 /D NDEBUG /D_USE_MATH_DEFINES")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O2 /D NDEBUG /D_USE_MATH_DEFINES")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /O2 /D NDEBUG /D_USE_MATH_DEFINES")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT} ${CMAKE_MSVC_OPENMP_FLAGS} /MT /Zi /O2 /Ob1 /D NDEBUG /D_USE_MATH_DEFINES")
endif()

# Set Source and Header files
Expand Down
6 changes: 6 additions & 0 deletions lib/BasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ along with this program, also can be found at
#ifndef BASIC_TYPES_H
#define BASIC_TYPES_H

// Standard way to get pi constant on most platforms
// Needs to be defined _before_ including cmath
// so that the PI constants come from cmath
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

#include <cmath>
#include <cstddef>
#include <fstream>
Expand Down
9 changes: 0 additions & 9 deletions lib/GeomLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ along with this program, also can be found at
#ifndef GEOM_LIB_H
#define GEOM_LIB_H

// 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 "BasicTypes.h" //For uint, XYZ
#include "XYZArray.h"
#include <limits> //for double limits
Expand Down Expand Up @@ -43,9 +37,6 @@ 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
2 changes: 0 additions & 2 deletions src/FFAngles.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef FF_ANGLES_H
#define FF_ANGLES_H

#include <cmath>

#include "BasicTypes.h" //For "uint"
#include "FFSetup.h" //For initialization data
#include "NumLib.h" //For "Sq" function
Expand Down
2 changes: 0 additions & 2 deletions src/FFDihedrals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef FF_DIHEDRALS_H
#define FF_DIHEDRALS_H

#include <cmath> //cos, pow

#include "BasicTypes.h" //For "uint"
#include "FFConst.h" //GetRot
#include "NumLib.h" //Sq
Expand Down
2 changes: 0 additions & 2 deletions src/Forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ along with this program, also can be found at
#include "FFSwitch.h"
#include "FFSwitchMartini.h"
#include "Setup.h"
#define _USE_MATH_DEFINES
#include <cmath>

Forcefield::Forcefield() {
particles = NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/MersenneTwister.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
#ifndef MERSENNETWISTER_H
#define MERSENNETWISTER_H

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

// Not thread safe (unless auto-initialization is avoided and each thread has
// its own MTRand object)

Expand Down
3 changes: 0 additions & 3 deletions src/MoveSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#include "MoveSettings.h" //header spec

#include <cmath>

#include "BoxDimensions.h" //For axis sizes
#include "BoxDimensionsNonOrth.h"
#include "GeomLib.h" //For M_PI
Expand Down
2 changes: 0 additions & 2 deletions src/PRNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ along with this program, also can be found at
#include <cstdlib>
#include <fstream>
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion src/XYZArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ along with this program, also can be found at
#include <string.h> //for memset, memcpy, etc.

#include <algorithm> //for swap pre-c++11 compilers
#include <cmath>
#include <utility> //for swap (most modern compilers)

#include "BasicTypes.h"
Expand Down
4 changes: 0 additions & 4 deletions src/cbmc/DCFreeCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCFreeCycle.h"

#include <cmath>

#include "DCData.h"
#include "Forcefield.h"
#include "MolSetup.h"
Expand Down
4 changes: 0 additions & 4 deletions src/cbmc/DCFreeCycleSeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCFreeCycleSeed.h"

#include <cmath>

#include "DCData.h"
#include "Forcefield.h"
#include "MolSetup.h"
Expand Down
4 changes: 0 additions & 4 deletions src/cbmc/DCFreeHedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCFreeHedron.h"

#include <cmath>

#include "DCData.h"
#include "Forcefield.h"
#include "MolSetup.h"
Expand Down
4 changes: 0 additions & 4 deletions src/cbmc/DCFreeHedronSeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCFreeHedronSeed.h"

#include <cmath>

#include "DCData.h"
#include "Forcefield.h"
#include "MolSetup.h"
Expand Down
4 changes: 1 addition & 3 deletions src/cbmc/DCHedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCHedron.h"

#include <cassert>
#include <cmath>
#include <numeric>

#include "DCData.h"
Expand Down Expand Up @@ -91,7 +89,7 @@ void DCHedron::SetBondOld(double const *bondLen, double const &anchBond) {
anchorBondOld = anchBond;
}

double DCHedron::GetWeight() {
double DCHedron::GetWeight() const {
double result = 1;
for (uint i = 0; i < nBonds; ++i) {
result *= thetaWeight[i];
Expand Down
12 changes: 6 additions & 6 deletions src/cbmc/DCHedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class DCHedron {
uint Bonded(uint i) const { return bonded[i]; }
double Theta(uint i) const { return theta[i]; }
double Phi(uint i) const { return phi[i]; }
double GetWeight();
double GetEnergy() { return bendEnergy; }
double GetNonBondedEn() { return oneThree; }
uint NumBond() { return nBonds; }
uint Focus() { return focus; }
uint Prev() { return prev; }
double GetWeight() const;
double GetEnergy() const { return bendEnergy; }
double GetNonBondedEn() const { return oneThree; }
uint NumBond() const { return nBonds; }
uint Focus() const { return focus; }
uint Prev() const { return prev; }

// need to go to private
uint bonded[MAX_BONDS];
Expand Down
2 changes: 0 additions & 2 deletions src/cbmc/DCHedronCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCHedronCycle.h"

#include <cassert>
#include <cmath>
#include <numeric>

#include "DCData.h"
Expand Down
2 changes: 0 additions & 2 deletions src/cbmc/DCLinkedCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCLinkedCycle.h"

#include <cassert>
#include <cmath>
#include <numeric>

#include "DCData.h"
Expand Down
2 changes: 0 additions & 2 deletions src/cbmc/DCLinkedHedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCLinkedHedron.h"

#include <cassert>
#include <cmath>
#include <numeric>

#include "DCData.h"
Expand Down
4 changes: 0 additions & 4 deletions src/cbmc/DCRotateCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ A copy of the MIT License can be found in License.txt
along with this program, also can be found at
<https://opensource.org/licenses/MIT>.
********************************************************************************/
#define _USE_MATH_DEFINES
#include "DCRotateCOM.h"

#include <cmath>

#include "DCData.h"
#include "Forcefield.h"
#include "MolSetup.h"
Expand Down
5 changes: 0 additions & 5 deletions src/cbmc/TrialMol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ along with this program, also can be found at
#include "TrialMol.h"

#include <algorithm>
#include <cmath> //for sin, cos, atan2
#include <utility> //swap

#include "BasicTypes.h"
#include "BoxDimensions.h"
#include "EnergyTypes.h"
#include "GeomLib.h" //for Theta
#include "MoleculeKind.h"
#include "XYZArray.h"
#ifndef NDEBUG
#include <iostream>
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/moves/IntraMoleculeExchange1.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef INTRAMOLECULEEXCHANGE1_H
#define INTRAMOLECULEEXCHANGE1_H

#include <cmath>

#include "GeomLib.h"
#include "MoveBase.h"
#include "TrialMol.h"
Expand Down
2 changes: 0 additions & 2 deletions src/moves/IntraMoleculeExchange2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef INTRAMOLECULEEXCHANGE2_H
#define INTRAMOLECULEEXCHANGE2_H

#include <cmath>

#include "GeomLib.h"
#include "IntraMoleculeExchange1.h"
#include "TrialMol.h"
Expand Down
2 changes: 0 additions & 2 deletions src/moves/IntraMoleculeExchange3.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef INTRAMOLECULEEXCHANGE3_H
#define INTRAMOLECULEEXCHANGE3_H

#include <cmath>

#include "GeomLib.h"
#include "IntraMoleculeExchange1.h"
#include "TrialMol.h"
Expand Down
5 changes: 2 additions & 3 deletions src/moves/IntraTargetedSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ along with this program, also can be found at
#ifndef INTRATARGETEDSWAP_H
#define INTRATARGETEDSWAP_H

#include <cmath>
#include <queue>

#include "ConfigSetup.h"
#include "FloydWarshallCycle.h"
#include "GeomLib.h"
Expand All @@ -19,6 +16,8 @@ along with this program, also can be found at
#include "TargetedSwap.h" // for enum PBC Struct TSwapParam defined in there
#include "TrialMol.h"

#include <queue>

struct BondList;

class IntraTargetedSwap : public MoveBase {
Expand Down
3 changes: 0 additions & 3 deletions src/moves/MoleculeExchange1.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ along with this program, also can be found at
#define MOLECULEEXCHANGE1_H

#if ENSEMBLE == GCMC || ENSEMBLE == GEMC

#include <cmath>

#include "GeomLib.h"
#include "MoveBase.h"
#include "TrialMol.h"
Expand Down
3 changes: 0 additions & 3 deletions src/moves/MoleculeExchange2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ along with this program, also can be found at
#define MOLECULEEXCHANGE2_H

#if ENSEMBLE == GCMC || ENSEMBLE == GEMC

#include <cmath>

#include "GeomLib.h"
#include "MoleculeExchange1.h"
#include "TrialMol.h"
Expand Down
3 changes: 0 additions & 3 deletions src/moves/MoleculeExchange3.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ along with this program, also can be found at
#define MOLECULEEXCHANGE3_H

#if ENSEMBLE == GCMC || ENSEMBLE == GEMC

#include <cmath>

#include "GeomLib.h"
#include "MoleculeExchange1.h"
#include "TrialMol.h"
Expand Down
4 changes: 1 addition & 3 deletions src/moves/MultiParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ along with this program, also can be found at
#ifndef MULTIPARTICLE_H
#define MULTIPARTICLE_H

#include <cmath>
#include <fstream>

#include "MoveBase.h"
#include "Random123Wrapper.h"
#include "StaticVals.h"
Expand All @@ -19,6 +16,7 @@ along with this program, also can be found at
#include "TransformParticlesCUDAKernel.cuh"
#include "VariablesCUDA.cuh"
#endif
#include <fstream>

#define MIN_FORCE 1E-12
#define MAX_FORCE 30
Expand Down
2 changes: 0 additions & 2 deletions src/moves/MultiParticleBrownianMotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ along with this program, also can be found at
#ifndef MULTIPARTICLEBROWNIANMOTION_H
#define MULTIPARTICLEBROWNIANMOTION_H

#include <cmath>

#include "MoveBase.h"
#include "Random123Wrapper.h"
#include "StaticVals.h"
Expand Down
1 change: 0 additions & 1 deletion src/moves/TargetedSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct TSwapParam {

#if ENSEMBLE == GCMC || ENSEMBLE == GEMC

#include <cmath>
#include <queue>

#include "ConfigSetup.h"
Expand Down

0 comments on commit 713622a

Please sign in to comment.