Commit 90f31a68 authored by Christopher Bruns's avatar Christopher Bruns
Browse files

Many changes to build OpenMM on Windows:

1) Added DLL export macros to many classes; enough to get tests to compile
2) Cosmetic changes to reduce warnings in Visual Studio:
   a) change many "for (int i ="... to "for (size_t i ="... to avoid unsigned mismatch warnings
   b) included many explicit static_cast<OpenMMReal>() casts to document places where double->float conversion warnings occur
parent 3353081f
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "KernelImpl.h" #include "KernelImpl.h"
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -54,7 +55,7 @@ namespace OpenMM { ...@@ -54,7 +55,7 @@ namespace OpenMM {
* </pre> * </pre>
*/ */
class Kernel { class OPENMM_EXPORT Kernel {
public: public:
Kernel(); Kernel();
Kernel(const Kernel& copy); Kernel(const Kernel& copy);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "Platform.h" #include "Platform.h"
#include <string> #include <string>
#include <cassert> #include <cassert>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -44,7 +45,7 @@ namespace OpenMM { ...@@ -44,7 +45,7 @@ namespace OpenMM {
* will in turn subclass it and provide concrete implementations of the execute() method. * will in turn subclass it and provide concrete implementations of the execute() method.
*/ */
class KernelImpl { class OPENMM_EXPORT KernelImpl {
public: public:
/** /**
* Create a KernelImpl. * Create a KernelImpl.
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "Stream.h" #include "Stream.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -60,7 +61,7 @@ class StreamFactory; ...@@ -60,7 +61,7 @@ class StreamFactory;
* You can then call createKernel() and createStream() to construct particular kernels and streams as needed. * You can then call createKernel() and createStream() to construct particular kernels and streams as needed.
*/ */
class Platform { class OPENMM_EXPORT Platform {
public: public:
virtual ~Platform(); virtual ~Platform();
/** /**
...@@ -168,9 +169,23 @@ public: ...@@ -168,9 +169,23 @@ public:
*/ */
static Platform& findPlatform(std::vector<std::string> kernelNames); static Platform& findPlatform(std::vector<std::string> kernelNames);
private: private:
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::map<std::string, KernelFactory*> kernelFactories; std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, StreamFactory*> streamFactories; std::map<std::string, StreamFactory*> streamFactories;
static std::vector<Platform*> platforms; static std::vector<Platform*> platforms;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include <string> #include <string>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
class StreamImpl; class OPENMM_EXPORT StreamImpl;
/** /**
* A Stream encapsulates a particular implementation of a stream of data elements. A Stream has three * A Stream encapsulates a particular implementation of a stream of data elements. A Stream has three
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "StreamImpl.h" #include "StreamImpl.h"
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -42,7 +43,7 @@ namespace OpenMM { ...@@ -42,7 +43,7 @@ namespace OpenMM {
* StreamImpls as needed. * StreamImpls as needed.
*/ */
class StreamFactory { class OPENMM_EXPORT StreamFactory {
public: public:
/** /**
* Create a StreamImpl. * Create a StreamImpl.
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Force.h" #include "Force.h"
#include <string> #include <string>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,7 +42,7 @@ namespace OpenMM { ...@@ -41,7 +42,7 @@ namespace OpenMM {
* This class uses the Andersen method to maintain constant temperature. * This class uses the Andersen method to maintain constant temperature.
*/ */
class AndersenThermostat : public Force { class OPENMM_EXPORT AndersenThermostat : public Force {
public: public:
/** /**
* This is the name of the parameter which stores the current temperature of the * This is the name of the parameter which stores the current temperature of the
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Integrator.h" #include "Integrator.h"
#include "Kernel.h" #include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,7 +42,7 @@ namespace OpenMM { ...@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using Brownian dynamics. * This is an Integrator which simulates a System using Brownian dynamics.
*/ */
class BrownianIntegrator : public Integrator { class OPENMM_EXPORT BrownianIntegrator : public Integrator {
public: public:
/** /**
* Create a BrownianIntegrator. * Create a BrownianIntegrator.
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Force.h" #include "Force.h"
#include <string> #include <string>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -42,7 +43,7 @@ namespace OpenMM { ...@@ -42,7 +43,7 @@ namespace OpenMM {
* center of mass momentum, then adjusts the individual atom velocities to make it zero. * center of mass momentum, then adjusts the individual atom velocities to make it zero.
*/ */
class CMMotionRemover : public Force { class OPENMM_EXPORT CMMotionRemover : public Force {
public: public:
/** /**
* Create a CMMotionRemover. * Create a CMMotionRemover.
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
class ForceImpl; class ForceImpl;
...@@ -51,7 +53,7 @@ class ForceImpl; ...@@ -51,7 +53,7 @@ class ForceImpl;
* </ul> * </ul>
*/ */
class Force { class OPENMM_EXPORT Force {
public: public:
Force() {} Force() {}
virtual ~Force() { virtual ~Force() {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Force.h" #include "Force.h"
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,7 +42,7 @@ namespace OpenMM { ...@@ -41,7 +42,7 @@ namespace OpenMM {
* This class implements an implicit solvation force using the GBSA-OBC model. * This class implements an implicit solvation force using the GBSA-OBC model.
*/ */
class GBSAOBCForceField : public Force { class OPENMM_EXPORT GBSAOBCForceField : public Force {
public: public:
/* /*
* Create a GBSAOBCForceField. * Create a GBSAOBCForceField.
...@@ -102,7 +103,21 @@ protected: ...@@ -102,7 +103,21 @@ protected:
private: private:
class AtomInfo; class AtomInfo;
double solventDielectric, soluteDielectric; double solventDielectric, soluteDielectric;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<AtomInfo> atoms; std::vector<AtomInfo> atoms;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; };
class GBSAOBCForceField::AtomInfo { class GBSAOBCForceField::AtomInfo {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "Vec3.h" #include "Vec3.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -49,7 +50,7 @@ class OpenMMContextImpl; ...@@ -49,7 +50,7 @@ class OpenMMContextImpl;
* is specified by passing the Integrator as an argument to the constructor of the OpenMMContext. * is specified by passing the Integrator as an argument to the constructor of the OpenMMContext.
*/ */
class Integrator { class OPENMM_EXPORT Integrator {
public: public:
virtual ~Integrator() { virtual ~Integrator() {
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Integrator.h" #include "Integrator.h"
#include "Kernel.h" #include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,7 +42,7 @@ namespace OpenMM { ...@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using Langevin dynamics. * This is an Integrator which simulates a System using Langevin dynamics.
*/ */
class LangevinIntegrator : public Integrator { class OPENMM_EXPORT LangevinIntegrator : public Integrator {
public: public:
/** /**
* Create a LangevinIntegrator. * Create a LangevinIntegrator.
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "System.h" #include "System.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -60,7 +61,7 @@ class Platform; ...@@ -60,7 +61,7 @@ class Platform;
* atom and the current energy of the System. * atom and the current energy of the System.
*/ */
class OpenMMContext { class OPENMM_EXPORT OpenMMContext {
public: public:
/** /**
* Construct a new OpenMMContext in which to run a simulation. * Construct a new OpenMMContext in which to run a simulation.
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "Force.h" #include "Force.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -48,7 +49,7 @@ namespace OpenMM { ...@@ -48,7 +49,7 @@ namespace OpenMM {
* method to set the force field parameters for each one. * method to set the force field parameters for each one.
*/ */
class StandardMMForceField : public Force { class OPENMM_EXPORT StandardMMForceField : public Force {
public: public:
/** /**
* Create a StandardMMForceField. * Create a StandardMMForceField.
...@@ -216,11 +217,25 @@ private: ...@@ -216,11 +217,25 @@ private:
class AngleInfo; class AngleInfo;
class PeriodicTorsionInfo; class PeriodicTorsionInfo;
class RBTorsionInfo; class RBTorsionInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<AtomInfo> atoms; std::vector<AtomInfo> atoms;
std::vector<BondInfo> bonds; std::vector<BondInfo> bonds;
std::vector<AngleInfo> angles; std::vector<AngleInfo> angles;
std::vector<PeriodicTorsionInfo> periodicTorsions; std::vector<PeriodicTorsionInfo> periodicTorsions;
std::vector<RBTorsionInfo> rbTorsions; std::vector<RBTorsionInfo> rbTorsions;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; };
class StandardMMForceField::AtomInfo { class StandardMMForceField::AtomInfo {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "Vec3.h" #include "Vec3.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -49,7 +50,7 @@ namespace OpenMM { ...@@ -49,7 +50,7 @@ namespace OpenMM {
* when the State was created), it will throw an exception. * when the State was created), it will throw an exception.
*/ */
class State { class OPENMM_EXPORT State {
public: public:
/** /**
* This is an enumeration of the types of data which may be stored in a State. When you create * This is an enumeration of the types of data which may be stored in a State. When you create
...@@ -87,6 +88,15 @@ public: ...@@ -87,6 +88,15 @@ public:
private: private:
friend class OpenMMContext; friend class OpenMMContext;
State(double time, int numAtoms, DataType types); State(double time, int numAtoms, DataType types);
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<Vec3>& updPositions(); std::vector<Vec3>& updPositions();
std::vector<Vec3>& updVelocities(); std::vector<Vec3>& updVelocities();
std::vector<Vec3>& updForces(); std::vector<Vec3>& updForces();
...@@ -98,6 +108,10 @@ private: ...@@ -98,6 +108,10 @@ private:
std::vector<Vec3> velocities; std::vector<Vec3> velocities;
std::vector<Vec3> forces; std::vector<Vec3> forces;
std::map<std::string, double> parameters; std::map<std::string, double> parameters;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; };
......
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include <vector> #include <vector>
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
class Force; class OPENMM_EXPORT Force;
/** /**
* This class represents a molecular system. The definition of a System involves * This class represents a molecular system. The definition of a System involves
...@@ -53,7 +54,7 @@ class Force; ...@@ -53,7 +54,7 @@ class Force;
* stores a list of Force objects that determine the motion of the atoms. * stores a list of Force objects that determine the motion of the atoms.
*/ */
class System { class OPENMM_EXPORT System {
public: public:
/** /**
* Create a new System. * Create a new System.
...@@ -134,9 +135,23 @@ public: ...@@ -134,9 +135,23 @@ public:
} }
private: private:
class ConstraintInfo; class ConstraintInfo;
std::vector<double> masses;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<double> masses;
std::vector<ConstraintInfo> constraints; std::vector<ConstraintInfo> constraints;
std::vector<Force*> forces; std::vector<Force*> forces;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; };
class System::ConstraintInfo { class System::ConstraintInfo {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "Integrator.h" #include "Integrator.h"
#include "Kernel.h" #include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,7 +42,7 @@ namespace OpenMM { ...@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using the leap-frog Verlet algorithm. * This is an Integrator which simulates a System using the leap-frog Verlet algorithm.
*/ */
class VerletIntegrator : public Integrator { class OPENMM_EXPORT VerletIntegrator : public Integrator {
public: public:
/** /**
* Create a VerletIntegrator. * Create a VerletIntegrator.
......
#ifndef OPENMM_WINDOWSEXPORT_H_
#define OPENMM_WINDOWSEXPORT_H_
/*
* Shared libraries are messy in Visual Studio. We have to distinguish three
* cases:
* (1) this header is being used to build the SimTKcommon shared library (dllexport)
* (2) this header is being used by a *client* of the SimTKcommon shared
* library (dllimport)
* (3) we are building the SimTKcommon static library, or the client is
* being compiled with the expectation of linking with the
* SimTKcommon static library (nothing special needed)
* In the CMake script for building this library, we define one of the symbols
* SimTK_SimTKCOMMON_BUILDING_{SHARED|STATIC}_LIBRARY
* Client code normally has no special symbol defined, in which case we'll
* assume it wants to use the shared library. However, if the client defines
* the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so
* that the client code can be linked with static libraries. Note that
* the client symbol is not library dependent, while the library symbols
* affect only the SimTKcommon library, meaning that other libraries can
* be clients of this one. However, we are assuming all-static or all-shared.
*/
#ifdef _MSC_VER
#if defined(OPENMM_BUILDING_SHARED_LIBRARY)
#define OPENMM_EXPORT __declspec(dllexport)
#elif defined(OPENMM_BUILDING_STATIC_LIBRARY) || defined(OPENMM_USE_STATIC_LIBRARIES)
#define OPENMM_EXPORT
#else
#define OPENMM_EXPORT __declspec(dllimport) // i.e., a client of a shared library
#endif
#else
#define OPENMM_EXPORT // Linux, Mac
#endif
#endif // OPENMM_WINDOWSEXPORT_H_
...@@ -45,7 +45,11 @@ using std::vector; ...@@ -45,7 +45,11 @@ using std::vector;
using std::string; using std::string;
OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform) : OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform) :
owner(owner), system(system), integrator(integrator), platform(platform), platformData(NULL) { owner(owner), system(system),
integrator(integrator), platform(platform),
platformData(NULL),
time(0)
{
vector<string> kernelNames; vector<string> kernelNames;
kernelNames.push_back(CalcKineticEnergyKernel::Name()); kernelNames.push_back(CalcKineticEnergyKernel::Name());
for (int i = 0; i < system.getNumForces(); ++i) { for (int i = 0; i < system.getNumForces(); ++i) {
...@@ -69,10 +73,10 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ ...@@ -69,10 +73,10 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ
velocities.fillWithValue(&zero); velocities.fillWithValue(&zero);
kineticEnergyKernel = platform->createKernel(CalcKineticEnergyKernel::Name(), *this); kineticEnergyKernel = platform->createKernel(CalcKineticEnergyKernel::Name(), *this);
vector<double> masses(system.getNumAtoms()); vector<double> masses(system.getNumAtoms());
for (int i = 0; i < masses.size(); ++i) for (size_t i = 0; i < masses.size(); ++i)
masses[i] = system.getAtomMass(i); masses[i] = system.getAtomMass(i);
dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).initialize(masses); dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).initialize(masses);
for (int i = 0; i < forceImpls.size(); ++i) for (size_t i = 0; i < forceImpls.size(); ++i)
forceImpls[i]->initialize(*this); forceImpls[i]->initialize(*this);
integrator.initialize(*this); integrator.initialize(*this);
} }
......
...@@ -69,8 +69,8 @@ const map<string, double>& State::getParameters() const { ...@@ -69,8 +69,8 @@ const map<string, double>& State::getParameters() const {
return parameters; return parameters;
} }
State::State(double time, int numAtoms, DataType types) : types(types), time(time), ke(0), pe(0), State::State(double time, int numAtoms, DataType types) : types(types), time(time), ke(0), pe(0),
positions(types&Positions == 0 ? 0 : numAtoms), velocities(types&Velocities== 0 ? 0 : numAtoms), positions( (types & Positions) == 0 ? 0 : numAtoms), velocities( (types & Velocities) == 0 ? 0 : numAtoms),
forces(types&Forces== 0 ? 0 : numAtoms) { forces( (types & Forces) == 0 ? 0 : numAtoms) {
} }
vector<Vec3>& State::updPositions() { vector<Vec3>& State::updPositions() {
return positions; return positions;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment