Commit 36f6f9e6 authored by Mark Friedrichs's avatar Mark Friedrichs
Browse files

Replaced exit() with exceptions

parent 591c5f92
...@@ -1303,7 +1303,6 @@ void gpuSetAmoebaTorsionTorsionGrids(amoebaGpuContext amoebaGpu, const std::vect ...@@ -1303,7 +1303,6 @@ void gpuSetAmoebaTorsionTorsionGrids(amoebaGpuContext amoebaGpu, const std::vect
values[0], values[1], values[2], values[3] ); values[0], values[1], values[2], values[3] );
if( errors++ > 10 ){ if( errors++ > 10 ){
(void) fflush( amoebaGpu->log ); (void) fflush( amoebaGpu->log );
exit(0);
} }
} }
} }
...@@ -1312,7 +1311,6 @@ void gpuSetAmoebaTorsionTorsionGrids(amoebaGpuContext amoebaGpu, const std::vect ...@@ -1312,7 +1311,6 @@ void gpuSetAmoebaTorsionTorsionGrids(amoebaGpuContext amoebaGpu, const std::vect
if( !errors ){ if( !errors ){
(void) fprintf( amoebaGpu->log, "No errors in grid readback\n" ); (void) fprintf( amoebaGpu->log, "No errors in grid readback\n" );
} }
exit(0);
#endif #endif
psTorsionTorsionGrids->Upload(); psTorsionTorsionGrids->Upload();
...@@ -2391,8 +2389,9 @@ void gpuSetAmoebaVdwParameters( amoebaGpuContext amoebaGpu, ...@@ -2391,8 +2389,9 @@ void gpuSetAmoebaVdwParameters( amoebaGpuContext amoebaGpu,
psVdwReductionID->_pSysData[count].w = ii; psVdwReductionID->_pSysData[count].w = ii;
} }
if( ivMapping[ii].size() > 3 ){ if( ivMapping[ii].size() > 3 ){
(void) fprintf( stderr, "Atom %u has %u reductions -- invalid -- aborting", ii, static_cast<unsigned int>(ivMapping[ii].size()) ); std::stringstream buffer;
exit(1); buffer << "Atom " << ii << " has " << ivMapping[ii].size() << " reductions: value should be < 3.";
throw OpenMM::OpenMMException( buffer.str() );
} }
count++; count++;
} }
...@@ -3776,22 +3775,23 @@ unsigned int getThreadsPerBlock( amoebaGpuContext amoebaGpu, unsigned int shared ...@@ -3776,22 +3775,23 @@ unsigned int getThreadsPerBlock( amoebaGpuContext amoebaGpu, unsigned int shared
FILE* getWriteToFilePtr( const std::string& fname, int step ) FILE* getWriteToFilePtr( const std::string& fname, int step )
{ {
std::stringstream fileName; std::stringstream fileName;
fileName << fname; fileName << fname;
fileName << "_" << step; fileName << "_" << step;
fileName << ".txt"; fileName << ".txt";
#ifdef WIN32 #ifdef WIN32
FILE* filePtr; FILE* filePtr;
fopen_s( &filePtr, fileName.str().c_str(), "w" ); fopen_s( &filePtr, fileName.str().c_str(), "w" );
#else #else
FILE* filePtr = fopen( fileName.str().c_str(), "w" ); FILE* filePtr = fopen( fileName.str().c_str(), "w" );
#endif #endif
if( filePtr == NULL ){ if( filePtr == NULL ){
(void) fprintf( stderr, "Could not open file=<%s> for writitng.", fileName.str().c_str() ); std::stringstream buffer;
exit(-1); buffer << "Could not open file " << fileName.str() << " for writitng.";
} throw OpenMM::OpenMMException( buffer.str() );
return filePtr; }
return filePtr;
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -3820,8 +3820,9 @@ FILE* getWriteToFilePtrV( const std::string& fname, std::vector<int>& fileId ) ...@@ -3820,8 +3820,9 @@ FILE* getWriteToFilePtrV( const std::string& fname, std::vector<int>& fileId )
FILE* filePtr = fopen( fileName.str().c_str(), "w" ); FILE* filePtr = fopen( fileName.str().c_str(), "w" );
#endif #endif
if( filePtr == NULL ){ if( filePtr == NULL ){
(void) fprintf( stderr, "Could not open file=<%s> for writing.", fileName.str().c_str() ); std::stringstream buffer;
exit(-1); buffer << "Could not open file " << fileName.str() << " for writitng.";
throw OpenMM::OpenMMException( buffer.str() );
} }
return filePtr; return filePtr;
} }
...@@ -4077,7 +4078,7 @@ void cudaLoadCudaFloatArray( int numberOfParticles, int entriesPerParticle, ...@@ -4077,7 +4078,7 @@ void cudaLoadCudaFloatArray( int numberOfParticles, int entriesPerParticle,
Check for nans in Cuda array Check for nans in Cuda array
(1) download data from gpu (1) download data from gpu
(2) check for nans and large values (> 1.0e+08) in array, and report if any found and exit (2) check for nans and large values (> 1.0e+08) in array, and report if any found
(3) report largest entry in absolute value, if no problems detected (3) report largest entry in absolute value, if no problems detected
(4) also by editing 'targetParticle', can track values around that index (4) also by editing 'targetParticle', can track values around that index
...@@ -4133,7 +4134,6 @@ void checkForNans( int numberOfParticles, int entriesPerParticle, ...@@ -4133,7 +4134,6 @@ void checkForNans( int numberOfParticles, int entriesPerParticle,
(void) fprintf( log, "%s %6d no errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex ); (void) fprintf( log, "%s %6d no errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex );
} else { } else {
(void) fprintf( log, "%s %6d errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex ); (void) fprintf( log, "%s %6d errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex );
exit(-1);
} }
} }
...@@ -4143,7 +4143,7 @@ void checkForNans( int numberOfParticles, int entriesPerParticle, ...@@ -4143,7 +4143,7 @@ void checkForNans( int numberOfParticles, int entriesPerParticle,
Check for nans in Cuda<float4> array Check for nans in Cuda<float4> array
(1) download data from gpu (1) download data from gpu
(2) check for nans and large values (> 1.0e+08) in array, and report if any found and exit (2) check for nans and large values (> 1.0e+08) in array, and report if any found
(3) report largest entry in absolute value, if no problems detected (3) report largest entry in absolute value, if no problems detected
(4) also by editing 'targetParticle', can track values around that index (4) also by editing 'targetParticle', can track values around that index
...@@ -4203,7 +4203,6 @@ void checkForNansFloat4( int numberOfParticles, CUDAStream<float4>* array, int* ...@@ -4203,7 +4203,6 @@ void checkForNansFloat4( int numberOfParticles, CUDAStream<float4>* array, int*
(void) fprintf( log, "%s %6d no errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex ); (void) fprintf( log, "%s %6d no errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex );
} else { } else {
(void) fprintf( log, "%s %6d errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex ); (void) fprintf( log, "%s %6d errors detected maxValue=%15.7e %6d.\n", idString.c_str(), iteration, maxValue, maxIndex );
exit(-1);
} }
} }
...@@ -4615,9 +4614,9 @@ void trackMutualInducedIterations( amoebaGpuContext amoebaGpu, int iteration){ ...@@ -4615,9 +4614,9 @@ void trackMutualInducedIterations( amoebaGpuContext amoebaGpu, int iteration){
} }
} }
if( nansPresent ){ if( nansPresent ){
(void) fprintf( amoebaGpu->log, "epsilon nan - exiting\n" ); std::stringstream buffer;
(void) fflush( amoebaGpu->log ); buffer << "epsilon nan exiting.";
exit(-1); throw OpenMM::OpenMMException( buffer.str() );
} }
} }
......
...@@ -423,7 +423,7 @@ void kCalculateGrycukGbsaForces2( amoebaGpuContext amoebaGpu ) ...@@ -423,7 +423,7 @@ void kCalculateGrycukGbsaForces2( amoebaGpuContext amoebaGpu )
cudaLoadCudaFloatArray( gpu->natoms, 1, gpu->psBornRadii, outputVector, gpu->psAtomIndex->_pSysData, 1.0f ); cudaLoadCudaFloatArray( gpu->natoms, 1, gpu->psBornRadii, outputVector, gpu->psAtomIndex->_pSysData, 1.0f );
cudaWriteVectorOfDoubleVectorsToFile( "GryF", fileId, outputVector ); cudaWriteVectorOfDoubleVectorsToFile( "GryF", fileId, outputVector );
delete temp; delete temp;
exit(0); //exit(0);
} }
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "amoebaGpuTypes.h" #include "amoebaGpuTypes.h"
#include "amoebaCudaKernels.h" #include "amoebaCudaKernels.h"
#include "kCalculateAmoebaCudaUtilities.h" #include "kCalculateAmoebaCudaUtilities.h"
#include "openmm/OpenMMException.h"
#include <stdio.h> #include <stdio.h>
...@@ -586,10 +587,7 @@ static void cudaComputeAmoebaMutualInducedAndGkFieldBySOR( amoebaGpuContext amoe ...@@ -586,10 +587,7 @@ static void cudaComputeAmoebaMutualInducedAndGkFieldBySOR( amoebaGpuContext amoe
// check for nans // check for nans
if( currentEpsilon != currentEpsilon ){ if( currentEpsilon != currentEpsilon ){
(void) fprintf( stderr, "cudaComputeAmoebaMutualInducedAndGkFieldBySOR at timestep=%d iteration=%3d eps is nan -- exiting.\n", throw OpenMM::OpenMMException("GkFieldBySOR: Nans detected in induced dipole calculation.");
timestep, iteration );
(void) fflush( NULL );
exit(-1);
} }
// converged? // converged?
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "amoebaGpuTypes.h" #include "amoebaGpuTypes.h"
#include "amoebaCudaKernels.h" #include "amoebaCudaKernels.h"
#include "kCalculateAmoebaCudaUtilities.h" #include "kCalculateAmoebaCudaUtilities.h"
#include "openmm/OpenMMException.h"
#include <stdio.h> #include <stdio.h>
...@@ -549,11 +550,10 @@ static void cudaComputeAmoebaPmeMutualInducedFieldBySOR( amoebaGpuContext amoeba ...@@ -549,11 +550,10 @@ static void cudaComputeAmoebaPmeMutualInducedFieldBySOR( amoebaGpuContext amoeba
done = 1; done = 1;
} }
// exit if nan // throw exception if nan detected
if( amoebaGpu->mutualInducedCurrentEpsilon != amoebaGpu->mutualInducedCurrentEpsilon ){ if( amoebaGpu->mutualInducedCurrentEpsilon != amoebaGpu->mutualInducedCurrentEpsilon ){
(void) fprintf( stderr, "PME MI iteration=%3d eps is nan -- exiting.\n", iteration ); throw OpenMM::OpenMMException("PME induced dipole calculation detected nans." );
exit(0);
} }
iteration++; iteration++;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "cudaKernels.h" #include "cudaKernels.h"
#include "amoebaCudaKernels.h" #include "amoebaCudaKernels.h"
#include "kCalculateAmoebaCudaUtilities.h" #include "kCalculateAmoebaCudaUtilities.h"
#include "openmm/OpenMMException.h"
#include <stdio.h> #include <stdio.h>
#include <cuda.h> #include <cuda.h>
...@@ -480,9 +481,7 @@ void kCalculateAmoebaMultipoleForces(amoebaGpuContext amoebaGpu, bool hasAmoebaG ...@@ -480,9 +481,7 @@ void kCalculateAmoebaMultipoleForces(amoebaGpuContext amoebaGpu, bool hasAmoebaG
// check if induce dipole calculation converged -- abort if it did not // check if induce dipole calculation converged -- abort if it did not
if( amoebaGpu->mutualInducedDone == 0 ){ if( amoebaGpu->mutualInducedDone == 0 ){
(void) fprintf( stderr, "%s induced dipole calculation did not converge -- aborting!\n", methodName.c_str() ); throw OpenMM::OpenMMException("Induced dipole calculation did not converge" );
(void) fflush( stderr );
exit(-1);
} }
// calculate electrostatic forces // calculate electrostatic forces
......
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