From 3e56e6e590dbbd55dd63b88d270a9c2ef5ebe104 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" <50467563+victorapm@users.noreply.github.com> Date: Tue, 10 Oct 2023 08:28:24 -0400 Subject: [PATCH] Fix MSVC build (#978) * Allocate buffer on heap memory * Fix Pragma definition for MSVC * Fix uninitiliazed variable * Loop counter cannot be non-negative for MSVC --- src/IJ_mv/IJMatrix.c | 4 +-- src/parcsr_ls/par_fsai_solve.c | 2 +- src/struct_ls/red_black_gs.h | 4 ++- src/struct_mv/_hypre_struct_mv.h | 2 +- src/struct_mv/boxloop_host.h | 2 +- src/utilities/error.c | 43 ++++++++++++++++++++------------ 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/IJ_mv/IJMatrix.c b/src/IJ_mv/IJMatrix.c index 1cdb524b3..8d3c77d0e 100644 --- a/src/IJ_mv/IJMatrix.c +++ b/src/IJ_mv/IJMatrix.c @@ -274,8 +274,8 @@ hypre_IJMatrixReadBinary( const char *prefixname, HYPRE_Int one = 1; HYPRE_Int myid; char filename[1024], msg[1024]; - HYPRE_BigInt ilower, iupper, jlower, jupper; - size_t i, count; + HYPRE_BigInt i, ilower, iupper, jlower, jupper; + size_t count; hypre_uint64 header[11]; FILE *fp; diff --git a/src/parcsr_ls/par_fsai_solve.c b/src/parcsr_ls/par_fsai_solve.c index 54de0724d..58d5a12e8 100644 --- a/src/parcsr_ls/par_fsai_solve.c +++ b/src/parcsr_ls/par_fsai_solve.c @@ -64,7 +64,7 @@ hypre_FSAISolve( void *fsai_vdata, } iter = 0; - rel_resnorm = 1.0; + rel_resnorm = resnorm = 1.0; if (my_id == 0 && print_level > 1) { diff --git a/src/struct_ls/red_black_gs.h b/src/struct_ls/red_black_gs.h index 5f2c3e12d..41c4008fe 100644 --- a/src/struct_ls/red_black_gs.h +++ b/src/struct_ls/red_black_gs.h @@ -357,11 +357,13 @@ typedef struct #ifdef HYPRE_USING_OPENMP #define HYPRE_BOX_REDUCTION +#ifndef Pragma #if defined(WIN32) && defined(_MSC_VER) -#define Pragma(x) __pragma(HYPRE_XSTR(x)) +#define Pragma(x) __pragma(x) #else #define Pragma(x) _Pragma(HYPRE_XSTR(x)) #endif +#endif #define OMPRB1 Pragma(omp parallel for private(HYPRE_REDBLACK_PRIVATE) HYPRE_BOX_REDUCTION HYPRE_SMP_SCHEDULE) #else #define OMPRB1 diff --git a/src/struct_mv/_hypre_struct_mv.h b/src/struct_mv/_hypre_struct_mv.h index fe10e2d4b..42d51c4a4 100644 --- a/src/struct_mv/_hypre_struct_mv.h +++ b/src/struct_mv/_hypre_struct_mv.h @@ -2355,7 +2355,7 @@ hypre__J = hypre__thread; i1 = i2 = 0; \ #define HYPRE_BOX_REDUCTION #define HYPRE_OMP_CLAUSE #if defined(WIN32) && defined(_MSC_VER) -#define Pragma(x) __pragma(HYPRE_XSTR(x)) +#define Pragma(x) __pragma(x) #else #define Pragma(x) _Pragma(HYPRE_XSTR(x)) #endif diff --git a/src/struct_mv/boxloop_host.h b/src/struct_mv/boxloop_host.h index 1c93cd79f..6b4672c32 100644 --- a/src/struct_mv/boxloop_host.h +++ b/src/struct_mv/boxloop_host.h @@ -22,7 +22,7 @@ #define HYPRE_BOX_REDUCTION #define HYPRE_OMP_CLAUSE #if defined(WIN32) && defined(_MSC_VER) -#define Pragma(x) __pragma(HYPRE_XSTR(x)) +#define Pragma(x) __pragma(x) #else #define Pragma(x) _Pragma(HYPRE_XSTR(x)) #endif diff --git a/src/utilities/error.c b/src/utilities/error.c index e2d2df9c0..865ae5f23 100644 --- a/src/utilities/error.c +++ b/src/utilities/error.c @@ -14,7 +14,8 @@ hypre_Error hypre__global_error = {0, 0, NULL, 0, 0}; * Process the error raised on the given line of the given source file *--------------------------------------------------------------------------*/ -void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, const char *msg) +void +hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, const char *msg) { /* Copy global struct into a short name and copy changes back before exiting */ hypre_Error err = hypre__global_error; @@ -25,10 +26,10 @@ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, c #ifdef HYPRE_PRINT_ERRORS /* Error format strings without and with a message */ - const char fmt_wo[] = "hypre error in file \"%s\", line %d, error code = %d\n"; - const char fmt_wm[] = "hypre error in file \"%s\", line %d, error code = %d - %s\n"; - - HYPRE_Int bufsz = 0; + const char fmt_wo[] = "hypre error in file \"%s\", line %d, error code = %d\n"; + const char fmt_wm[] = "hypre error in file \"%s\", line %d, error code = %d - %s\n"; + char *buffer; + HYPRE_Int bufsz; /* Print error message to local buffer first */ @@ -42,7 +43,7 @@ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, c } bufsz += 1; - char buffer[bufsz]; + buffer = hypre_TAlloc(char, bufsz, HYPRE_MEMORY_HOST); if (msg) { @@ -54,7 +55,6 @@ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, c } /* Now print buffer to either memory or stderr */ - if (err.print_to_memory) { HYPRE_Int msg_sz = err.msg_sz; /* Store msg_sz for snprintf below */ @@ -74,6 +74,8 @@ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, c hypre_fprintf(stderr, "%s", buffer); } + /* Free buffer */ + hypre_TFree(buffer, HYPRE_MEMORY_HOST); #endif hypre__global_error = err; @@ -82,7 +84,8 @@ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, c /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_GetError(void) +HYPRE_Int +HYPRE_GetError(void) { return hypre_error_flag; } @@ -90,7 +93,8 @@ HYPRE_Int HYPRE_GetError(void) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_CheckError(HYPRE_Int ierr, HYPRE_Int hypre_error_code) +HYPRE_Int +HYPRE_CheckError(HYPRE_Int ierr, HYPRE_Int hypre_error_code) { return ierr & hypre_error_code; } @@ -98,7 +102,8 @@ HYPRE_Int HYPRE_CheckError(HYPRE_Int ierr, HYPRE_Int hypre_error_code) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -void HYPRE_DescribeError(HYPRE_Int ierr, char *msg) +void +HYPRE_DescribeError(HYPRE_Int ierr, char *msg) { if (ierr == 0) { @@ -129,7 +134,8 @@ void HYPRE_DescribeError(HYPRE_Int ierr, char *msg) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_GetErrorArg(void) +HYPRE_Int +HYPRE_GetErrorArg(void) { return (hypre_error_flag >> 3 & 31); } @@ -137,7 +143,8 @@ HYPRE_Int HYPRE_GetErrorArg(void) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_ClearAllErrors(void) +HYPRE_Int +HYPRE_ClearAllErrors(void) { hypre_error_flag = 0; return (hypre_error_flag != 0); @@ -146,7 +153,8 @@ HYPRE_Int HYPRE_ClearAllErrors(void) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_ClearError(HYPRE_Int hypre_error_code) +HYPRE_Int +HYPRE_ClearError(HYPRE_Int hypre_error_code) { hypre_error_flag &= ~hypre_error_code; return (hypre_error_flag & hypre_error_code); @@ -155,7 +163,8 @@ HYPRE_Int HYPRE_ClearError(HYPRE_Int hypre_error_code) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_SetPrintErrorMode(HYPRE_Int mode) +HYPRE_Int +HYPRE_SetPrintErrorMode(HYPRE_Int mode) { hypre__global_error.print_to_memory = mode; return hypre_error_flag; @@ -164,7 +173,8 @@ HYPRE_Int HYPRE_SetPrintErrorMode(HYPRE_Int mode) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_GetErrorMessages(char **buffer, HYPRE_Int *bufsz) +HYPRE_Int +HYPRE_GetErrorMessages(char **buffer, HYPRE_Int *bufsz) { hypre_Error err = hypre__global_error; @@ -183,7 +193,8 @@ HYPRE_Int HYPRE_GetErrorMessages(char **buffer, HYPRE_Int *bufsz) /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_PrintErrorMessages(MPI_Comm comm) +HYPRE_Int +HYPRE_PrintErrorMessages(MPI_Comm comm) { hypre_Error err = hypre__global_error;