Skip to content

Commit

Permalink
write a specific error message when the number of elements to gather …
Browse files Browse the repository at this point in the history
…in PMMG_gather_parmesh exceeds INT_MAX

  This problem occurs when the size of the first np-1 of the compressed mesh parts exceeds INT_MAX.
  This commit introduces an error message for this circumstance, which replaces an error on a negative allocation size.
  It also shows the allocation size in the error message for allocation failur so that this kind of problem is easier to diagnose.
  • Loading branch information
mpotse committed May 18, 2024
1 parent 4706e63 commit dd37e48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/mergemesh_pmmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ int PMMG_gather_parmesh( PMMG_pParMesh parmesh,
int **rcv_next_node_comm,
PMMG_pExt_comm **rcv_ext_node_comm ) {

size_t pack_size_tot;
size_t pack_size_tot,next_disp;
int *rcv_pack_size,ier,ier_glob,k,*displs,ier_pack;
int nprocs,root,pack_size;
char *rcv_buffer,*buffer,*ptr;
Expand Down Expand Up @@ -1145,7 +1145,17 @@ int PMMG_gather_parmesh( PMMG_pParMesh parmesh,
displs[0] = 0;
for ( k=1; k<nprocs; ++k ) {
assert ( displs[k-1] <= INT_MAX - rcv_pack_size[k-1] && "INT_MAX overflow");
displs[k] = displs[k-1] + rcv_pack_size[k-1];
next_disp = displs[k-1] + rcv_pack_size[k-1];
if(next_disp>INT_MAX){
/* The displacements argument to MPI_Gatherv() is an array of int
* (signed) so the number of elements must be smaller than 2^31.
* To get around this we must pack more data in a single element
* or use multiple messages.
*/
fprintf(stderr, " ## Error: too many elements for MPI_Gatherv()\n");
MPI_Abort(parmesh->comm, 1); /* error detected only on root */
}
displs[k] = next_disp;
}
pack_size_tot = (size_t)(displs[nprocs-1])+(size_t)(rcv_pack_size[nprocs-1]);
assert ( pack_size_tot < SIZE_MAX && "SIZE_MAX overflow" );
Expand Down
8 changes: 5 additions & 3 deletions src/parmmg.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,14 @@ static const int PMMG_MVIFCS_NLAYERS = 2;


#define ERROR_AT(msg1,msg2) \
fprintf( stderr, msg1 msg2 " function: %s, file: %s, line: %d \n", \
__func__, __FILE__, __LINE__ )
fprintf( stderr, "%s %s function: %s, file: %s, line: %d \n", \
msg1, msg2, __func__, __FILE__, __LINE__ )

#define MEM_CHK_AVAIL(mesh,bytes,msg) do { \
if ( (mesh)->memCur + (bytes) > (mesh)->memMax ) { \
ERROR_AT(msg," Exceeded max memory allowed: "); \
char diag[1024]; \
snprintf(diag, 1024, " Allocation of %ld bytes exceeds max %ld: ", bytes, (mesh)->memMax); \
ERROR_AT(msg, diag); \
stat = PMMG_FAILURE; \
} else if ( (mesh)->memCur + (bytes) < 0 ) { \
ERROR_AT(msg," Tried to free more mem than allocated: " ); \
Expand Down

0 comments on commit dd37e48

Please sign in to comment.