Adding check on Array to ensure it is within bounds (debug mode only)
This commit is contained in:
parent
1f212e2b68
commit
197b788330
|
@ -32,7 +32,7 @@ ENDFUNCTION()
|
|||
# Macro to configure CUDA
|
||||
MACRO( CONFIGURE_CUDA )
|
||||
CHECK_ENABLE_FLAG( USE_CUDA 0 )
|
||||
IF( USE_CUDA )
|
||||
IF ( USE_CUDA )
|
||||
# Include FindCUDA
|
||||
INCLUDE( FindCUDA )
|
||||
IF ( NOT CUDA_FOUND )
|
||||
|
@ -91,7 +91,7 @@ MACRO( CONFIGURE_MPI )
|
|||
SET ( MPI_INCLUDE_PATH ${MPI_DIRECTORY}/include )
|
||||
VERIFY_PATH ( ${MPI_INCLUDE_PATH} )
|
||||
IF ( NOT EXISTS ${MPI_INCLUDE_PATH}/mpi.h )
|
||||
MESSAGE ( FATAL_ERROR "mpi.h not found in ${MPI_INCLUDE_PATH}/include" )
|
||||
MESSAGE( FATAL_ERROR "mpi.h not found in ${MPI_INCLUDE_PATH}" )
|
||||
ENDIF ()
|
||||
INCLUDE_DIRECTORIES ( ${MPI_INCLUDE_PATH} )
|
||||
SET ( MPI_INCLUDE ${MPI_INCLUDE_PATH} )
|
||||
|
@ -116,20 +116,14 @@ MACRO( CONFIGURE_MPI )
|
|||
ENDIF()
|
||||
ELSEIF ( MPI_COMPILER )
|
||||
# The mpi compiler should take care of everything
|
||||
IF ( NOT MPIEXEC )
|
||||
MESSAGE( FATAL_ERROR "MPIEXEC should be set" )
|
||||
ENDIF()
|
||||
ELSE()
|
||||
# Perform the default search for MPI
|
||||
INCLUDE ( FindMPI )
|
||||
IF ( NOT MPI_FOUND )
|
||||
MESSAGE( " MPI_INCLUDE = ${MPI_INCLUDE}" )
|
||||
MESSAGE( " MPI_LINK_FLAGS = ${MPI_LINK_FLAGS}" )
|
||||
MESSAGE( " MPI_LIBRARIES = ${MPI_LIBRARIES}" )
|
||||
MESSAGE( FATAL_ERROR "Did not find MPI" )
|
||||
ENDIF ()
|
||||
INCLUDE_DIRECTORIES( "${MPI_INCLUDE_PATH}" )
|
||||
SET( MPI_INCLUDE "${MPI_INCLUDE_PATH}" )
|
||||
INCLUDE_DIRECTORIES ( ${MPI_INCLUDE_PATH} )
|
||||
SET ( MPI_INCLUDE ${MPI_INCLUDE_PATH} )
|
||||
ENDIF()
|
||||
# Check if we need to use MPI for serial tests
|
||||
CHECK_ENABLE_FLAG( USE_MPI_FOR_SERIAL_TESTS 0 )
|
||||
|
|
|
@ -4,6 +4,25 @@
|
|||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// Define a macro to check if the index is valid
|
||||
// Only perform the check if we are compiling in debug mode
|
||||
#ifdef DEBUG
|
||||
#ifdef USE_CUDA
|
||||
#define CHECK_INDEX(i,j,k) \
|
||||
if ( (i+j*m+k*m*n)<0 || (i+j*m+k*m*n)>=Length ) { \
|
||||
printf("Index is out of bounds\n"); }
|
||||
#else
|
||||
#include "common/Utilities.h"
|
||||
#define CHECK_INDEX(i,j,k) \
|
||||
if ( (i+j*m+k*m*n)<0 || (i+j*m+k*m*n)>=Length ) { \
|
||||
ERROR("Index is out of bounds\n"); }
|
||||
#endif
|
||||
#else
|
||||
#define CHECK_INDEX(i,j,k)
|
||||
#endif
|
||||
|
||||
|
||||
// ********** ARRAY CLASS INFO **************************************
|
||||
/*
|
||||
//..............................................................
|
||||
|
@ -45,12 +64,12 @@ public:
|
|||
void New(int nx, int ny);
|
||||
void New(int nx, int ny, int nz);
|
||||
|
||||
int & operator()(int index)
|
||||
{return data[index];}
|
||||
int & operator()(int i)
|
||||
{ CHECK_INDEX(i,0,0) return data[i];}
|
||||
int & operator()(int i, int j)
|
||||
{ return data[j*m+i];}
|
||||
{ CHECK_INDEX(i,j,0) return data[j*m+i];}
|
||||
int & operator()(int i, int j, int k)
|
||||
{ return data[k*m*n+j*m+i];}
|
||||
{ CHECK_INDEX(i,j,k) return data[k*m*n+j*m+i];}
|
||||
|
||||
int e(int i);
|
||||
int e(int i, int j);
|
||||
|
@ -78,12 +97,12 @@ public:
|
|||
void New(int nx, int ny);
|
||||
void New(int nx, int ny, int nz);
|
||||
|
||||
double & operator()(int index)
|
||||
{return data[index];}
|
||||
double & operator()(int i)
|
||||
{ CHECK_INDEX(i,0,0) return data[i];}
|
||||
double & operator()(int i, int j)
|
||||
{return data[j*m+i];}
|
||||
{ CHECK_INDEX(i,j,0) return data[j*m+i];}
|
||||
double & operator()(int i, int j, int k)
|
||||
{return data[k*m*n+j*m+i];}
|
||||
{ CHECK_INDEX(i,j,k) return data[k*m*n+j*m+i];}
|
||||
double e(int i);
|
||||
double e(int i, int j);
|
||||
double e(int i, int j, int k);
|
||||
|
|
|
@ -1136,8 +1136,8 @@ inline void WriteCheckpoint(char *FILENAME, double *cDen, double *cDistEven, dou
|
|||
|
||||
inline void ReadCheckpoint(char *FILENAME, double *cDen, double *cDistEven, double *cDistOdd, int N)
|
||||
{
|
||||
int q,n;
|
||||
double value;
|
||||
int q=0, n=0;
|
||||
double value=0;
|
||||
ifstream File(FILENAME,ios::binary);
|
||||
for (n=0; n<N; n++){
|
||||
// Write the two density values
|
||||
|
|
Loading…
Reference in New Issue
Block a user