Skip to content

Commit

Permalink
Added explicit tests that arguments (like number of elements), which …
Browse files Browse the repository at this point in the history
…have to be passed to MPI functions as int, do not exceed INT_MAX. Otherwise (improbable on modern hardware), error message will be produced. Addresses issue 137.
  • Loading branch information
myurkin committed May 16, 2012
1 parent eee9736 commit 75241f1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static MPI_Datatype MPIVarType(var_type type,bool reduce,int *mult)
}
else res=mpi_dcomplex3;
}
else LogError(ONE_POS,"Variable type %u is not supported",type);
else LogError(ONE_POS,"Variable type %d is not supported",(int)type);

return res;
}
Expand All @@ -193,6 +193,8 @@ void InitDispls(void)
// initialize arrays recvcounts and displs once, further calls have no effect
{
if (!displs_init) {
if (nvoid_Ndip>INT_MAX) LogError(ONE_POS,
"int overflow in MPI function for number of non-void dipoles (%zu)",nvoid_Ndip);
MALLOC_VECTOR(recvcounts,int,nprocs,ALL);
MALLOC_VECTOR(displs,int,nprocs,ALL);
// !!! TODO: check for overflow of int
Expand Down Expand Up @@ -334,11 +336,9 @@ void MyBcast(void * restrict data UOIP,const var_type type UOIP,const size_t n_e
*/
{
#ifdef ADDA_MPI
TIME_TYPE tstart;

// redundant initialization to remove warnings
tstart=0;
TIME_TYPE tstart=0; // redundant initialization to remove warnings

if (n_elem>INT_MAX) LogError(ONE_POS,"int overflow in MPI function (%zu)",n_elem);
if (timing!=NULL) {
#ifdef SYNCHRONIZE_TIMING
MPI_Barrier(MPI_COMM_WORLD); // synchronize to get correct timing
Expand Down Expand Up @@ -401,6 +401,7 @@ void Accumulate(double * restrict vector UOIP,const size_t n UOIP,double * restr
#ifdef ADDA_MPI
TIME_TYPE tstart;

if (n>INT_MAX) LogError(ONE_POS,"int overflow in MPI function (%zu)",n);
#ifdef SYNCHRONIZE_TIMING
MPI_Barrier(MPI_COMM_WORLD); // synchronize to get correct timing
#endif
Expand All @@ -423,11 +424,9 @@ void MyInnerProduct(void * restrict data UOIP,const var_type type UOIP,size_t n_
#ifdef ADDA_MPI
MPI_Datatype mes_type;
int mult;
TIME_TYPE tstart;

// redundant initialization to remove warnings
tstart=0;
TIME_TYPE tstart=0; // redundant initialization to remove warnings

if (n_elem>INT_MAX) LogError(ONE_POS,"int overflow in MPI function (%zu)",n_elem);
if (timing!=NULL) {
#ifdef SYNCHRONIZE_TIMING
MPI_Barrier(MPI_COMM_WORLD); // synchronize to get correct timing
Expand Down Expand Up @@ -470,6 +469,8 @@ void BlockTranspose(doublecomplex * restrict X UOIP,TIME_TYPE *timing UOIP)
step=2*local_Nx;
msize=local_Nx*sizeof(doublecomplex);
bufsize=6*local_Nz*smallY*local_Nx;
if (bufsize>INT_MAX)
LogError(ALL_POS,"int overflow in MPI function for BT buffer (%zu)",bufsize);

for(transmission=1;transmission<=Ntrans;transmission++) {
// if part==nprocs then skip this transmission
Expand Down Expand Up @@ -519,6 +520,8 @@ void BlockTranspose_Dm(doublecomplex * restrict X UOIP,const size_t lengthY UOIP
step=2*local_Nx;
msize=local_Nx*sizeof(doublecomplex);
bufsize = 2*lengthZ*lengthY*local_Nx;
if (bufsize>INT_MAX)
LogError(ALL_POS,"int overflow in MPI function for BT buffer (%zu)",bufsize);

for(transmission=1;transmission<=Ntrans;transmission++) {
if ((part=CalcPartner(transmission))!=nprocs) {
Expand Down Expand Up @@ -722,7 +725,10 @@ void CollectDomainGranul(unsigned char * restrict dom UOIP,const size_t gXY UOIP
}
}
else if (locgZ!=0) {
MPI_Send(dom,unit*locgZ,MPI_UNSIGNED_CHAR,ADDA_ROOT,0,MPI_COMM_WORLD);
// the test here implies the test for above MPI_Recv as well
size_t size=(size_t)unit*(size_t)locgZ;
if (size>INT_MAX) LogError(ALL_POS,"int overflow in MPI function (%zu)",size);
MPI_Send(dom,size,MPI_UNSIGNED_CHAR,ADDA_ROOT,0,MPI_COMM_WORLD);
}
(*timing)+=GET_TIME()-tstart;
#endif
Expand Down Expand Up @@ -758,6 +764,7 @@ void ExchangeFits(char * restrict data UOIP,const size_t n UOIP,TIME_TYPE *timin
#ifdef ADDA_MPI
TIME_TYPE tstart;

if (n>INT_MAX) LogError(ONE_POS,"int overflow in MPI function (%zu)",n);
#ifdef SYNCHRONIZE_TIMING
MPI_Barrier(MPI_COMM_WORLD); // synchronize to get correct timing
#endif
Expand Down Expand Up @@ -786,6 +793,7 @@ bool ExchangePhaseShifts(doublecomplex * restrict bottom, doublecomplex * restri
TIME_TYPE tstart;
size_t i;

if (2*boxXY>INT_MAX) LogError(ONE_POS,"int overflow in MPI function (%zu)",2*boxXY);
#ifdef SYNCHRONIZE_TIMING
MPI_Barrier(MPI_COMM_WORLD); // synchronize to get correct timing
#endif
Expand Down

0 comments on commit 75241f1

Please sign in to comment.