Commit 55081e21 authored by Peter Eastman's avatar Peter Eastman
Browse files

Tony's changes to error handling in the CUDA platform so it throws exceptions...

Tony's changes to error handling in the CUDA platform so it throws exceptions instead of calling exit()
parent 832794f5
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include <iostream>
#include <sstream>
#include "openmm/OpenMMException.h"
#include "ValidateOpenMMForces.h" #include "ValidateOpenMMForces.h"
using namespace OpenMM; using namespace OpenMM;
...@@ -547,8 +550,10 @@ ForceValidationResult* ValidateOpenMMForces::compareForce(Context& context, std: ...@@ -547,8 +550,10 @@ ForceValidationResult* ValidateOpenMMForces::compareForce(Context& context, std:
for( int ii = 0; ii < system.getNumForces(); ii++ ){ for( int ii = 0; ii < system.getNumForces(); ii++ ){
std::string forceName = getForceName( system.getForce( ii ) ); std::string forceName = getForceName( system.getForce( ii ) );
if( forceName.compare( "NA" ) == 0 ){ if( forceName.compare( "NA" ) == 0 ){
(void) fprintf( stderr, "Force at index=%d not found -- aborting!\n", ii ); std::stringstream message;
exit(-1); message << "Force at index=" << ii << " not found -- aborting!";
std::cerr << message << std::endl;
throw OpenMM::OpenMMException(message.str());
} }
systemForceNameMap[forceName] = ii; systemForceNameMap[forceName] = ii;
systemForceNameIndex[ii] = forceName; systemForceNameIndex[ii] = forceName;
......
...@@ -11,6 +11,7 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS}) ...@@ -11,6 +11,7 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/${subdir}/src) CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/${subdir}/src)
ENDFOREACH(subdir) ENDFOREACH(subdir)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/jama/include) CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/jama/include)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/openmmapi/include)
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug) IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME}_d) SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME}_d)
......
...@@ -38,19 +38,18 @@ ...@@ -38,19 +38,18 @@
#include <cufft.h> #include <cufft.h>
#include <builtin_types.h> #include <builtin_types.h>
#include <vector_functions.h> #include <vector_functions.h>
#include "openmm/OpenMMException.h"
#define RTERROR(status, s) \ #define RTERROR(status, s) \
if (status != cudaSuccess) { \ if (status != cudaSuccess) { \
printf("%s %s\n", s, cudaGetErrorString(status)); \ throw OpenMM::OpenMMException(std::string(s) + " " + cudaGetErrorString(status)); \
exit(-1); \
} }
#define LAUNCHERROR(s) \ #define LAUNCHERROR(s) \
{ \ { \
cudaError_t status = cudaGetLastError(); \ cudaError_t status = cudaGetLastError(); \
if (status != cudaSuccess) { \ if (status != cudaSuccess) { \
printf("Error: %s launching kernel %s\n", cudaGetErrorString(status), s); \ throw OpenMM::OpenMMException(std::string("Error: ") + cudaGetErrorString(status) + " launching kernel " + s); \
exit(-1); \
} \ } \
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "SimTKOpenMMLog.h" #include "SimTKOpenMMLog.h"
#include <stdlib.h> #include <stdlib.h>
#include "openmm/OpenMMException.h"
// static settings // static settings
...@@ -291,13 +292,13 @@ void SimTKOpenMMLog::printError( const std::stringstream& message ){ ...@@ -291,13 +292,13 @@ void SimTKOpenMMLog::printError( const std::stringstream& message ){
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
if( _simTKOpenMMLog ){
std::stringstream messageWithHeader; std::stringstream messageWithHeader;
messageWithHeader << "Error: " << message.str(); messageWithHeader << "Error: " << message.str();
if( _simTKOpenMMLog ){
_simTKOpenMMLog->logMessage( messageWithHeader ); _simTKOpenMMLog->logMessage( messageWithHeader );
} else { } else {
(void) fprintf( stderr, "Error: %s", message.str().c_str() ); (void) fprintf( stderr, "%s", messageWithHeader.str().c_str() );
(void) fflush( stderr ); (void) fflush( stderr );
} }
exit(-1); throw OpenMM::OpenMMException(messageWithHeader.str());
} }
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