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