Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnose gatherv overflow #113

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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