Commit 3fa88060 authored by peastman's avatar peastman
Browse files

Created OPENMM_DEFAULT_PLATFORM environment variable

parent 9a3877b9
...@@ -675,11 +675,17 @@ Platforms ...@@ -675,11 +675,17 @@ Platforms
When creating a :class:`Simulation`, you can optionally tell it what :class:`Platform` to use. When creating a :class:`Simulation`, you can optionally tell it what :class:`Platform` to use.
OpenMM includes four platforms: :class:`Reference`, :class:`CPU`, :class:`CUDA`, and :class:`OpenCL`. For a OpenMM includes four platforms: :class:`Reference`, :class:`CPU`, :class:`CUDA`, and :class:`OpenCL`. For a
description of the differences between them, see Section :ref:`platforms`. If you do not description of the differences between them, see Section :ref:`platforms`. There are three ways in which
specify a :class:`Platform`, it will select one automatically. Usually its choice will the :class:`Platform` can be chosen:
be reasonable, but you may want to change it.
The following lines specify to use the :class:`CUDA` platform: 1. By default, OpenMM will try to select the fastest available :class:`Platform`. Usually its choice will
be reasonable, but sometimes you may want to change it.
2. Alternatively, you can set the :envvar:`OPENMM_DEFAULT_PLATFORM` environment variable to the name
of the :class:`Platform` to use. This overrides the default logic.
3. Finally, you can explicitly specify a :class:`Platform` object in your script when you create the
:class:`Simulation`. The following lines specify to use the :class:`CUDA` platform:
:: ::
platform = Platform.getPlatformByName('CUDA') platform = Platform.getPlatformByName('CUDA')
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "openmm/Context.h" #include "openmm/Context.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdlib>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <utility> #include <utility>
...@@ -115,6 +116,11 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ ...@@ -115,6 +116,11 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
// Select a platform to use. // Select a platform to use.
vector<pair<double, Platform*> > candidatePlatforms; vector<pair<double, Platform*> > candidatePlatforms;
if (platform == NULL) {
char* defaultPlatform = getenv("OPENMM_DEFAULT_PLATFORM");
if (defaultPlatform != NULL)
platform = &Platform::getPlatformByName(string(defaultPlatform));
}
if (platform == NULL) { if (platform == NULL) {
for (int i = 0; i < Platform::getNumPlatforms(); i++) { for (int i = 0; i < Platform::getNumPlatforms(); i++) {
Platform& p = Platform::getPlatform(i); Platform& p = Platform::getPlatform(i);
......
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