Skip to content

Commit

Permalink
New options (#67)
Browse files Browse the repository at this point in the history
* Fix off-by-one issue on HYPRE_CHECK_MIN_VERSION macro
* Add filter_functions option to AMG
* Add support to HYPRE_LOG_LEVEL
  • Loading branch information
victorapm authored Aug 23, 2024
1 parent 6de515e commit bf229fc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
8 changes: 7 additions & 1 deletion docs/usrman-src/input_file_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,13 @@ following optional keywords:
are any non-negative integer. Default value is `25`.

- ``num_functions`` - size of the system of PDEs, when using the systems
version. Available values are any positive integer. Default value is `1`.
version. Available values are any positive integer. Default value is `off`.

- ``filter_functions`` - turn on/off filtering based on inter-variable couplings for
systems of equations. For more information, see
`HYPRE_BoomerAMGSetFilterFunctions
<https://hypre.readthedocs.io/en/latest/api-sol-parcsr.html#_CPPv433HYPRE_BoomerAMGSetFilterFunctions12HYPRE_Solver9HYPRE_Int>`_.
Default value is `off`.

- ``rap2`` - whether or not to use two matrix products to compute coarse
level matrices. Available values are any non-negative integer. Default value is `0`.
Expand Down
1 change: 1 addition & 0 deletions include/amg.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct AMGcsn_args_struct {
HYPRE_Int mod_rap2;
HYPRE_Int keep_transpose;
HYPRE_Int num_functions;
HYPRE_Int filter_functions;
HYPRE_Int seq_amg_th;
HYPRE_Int min_coarse_size;
HYPRE_Int max_coarse_size;
Expand Down
14 changes: 7 additions & 7 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ void CombineFilename(const char*, const char*, char**);
#define HYPRE_DEVELOP_NUMBER_EXISTS 0
#endif

/* Check if HYPRE_DEVELOP_NUMBER is greater than a given value */
#define HYPRE_DEVELOP_NUMBER_GT(develop) \
(HYPRE_DEVELOP_NUMBER > (develop))
/* Check if HYPRE_DEVELOP_NUMBER is greater or equal than a given value */
#define HYPRE_DEVELOP_NUMBER_GE(develop) \
(HYPRE_DEVELOP_NUMBER >= (develop))

/* Check if HYPRE_RELEASE_NUMBER is greater than a given value */
#define HYPRE_RELEASE_NUMBER_GT(release) \
(HYPRE_RELEASE_NUMBER > (release))

/* Check for a specific hypre release number and whether
HYPRE_DEVELOP_NUMBER is defined and greater than a given value */
#define HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GT(release, develop) \
HYPRE_DEVELOP_NUMBER is defined and greater or equal than a given value */
#define HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GE(release, develop) \
(HYPRE_RELEASE_NUMBER == (release) &&\
HYPRE_DEVELOP_NUMBER_EXISTS &&\
HYPRE_DEVELOP_NUMBER_GT(develop))
HYPRE_DEVELOP_NUMBER_GE(develop))

/* Check for minimum HYPRE version in order to allow certain features */
#define HYPRE_CHECK_MIN_VERSION(release, develop) \
(HYPRE_RELEASE_NUMBER_GT(release) ||\
HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GT(release, develop))
HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GE(release, develop))

#define GB_TO_BYTES (1 << 30)
#define MAX_DIVISOR_LENGTH 84
Expand Down
9 changes: 9 additions & 0 deletions src/HYPREDRV.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ HYPREDRV_Initialize()
HYPRE_Initialize();
HYPRE_DeviceInitialize();

#if HYPRE_CHECK_MIN_VERSION(23100, 16)
/* Check for environment variables */
const char* env_log_level = getenv("HYPRE_LOG_LEVEL");
HYPRE_Int log_level = (env_log_level) ? (HYPRE_Int) atoi(env_log_level) : 0;

HYPRE_SetLogLevel(log_level);
#endif

/* Set library state to initialized */
is_initialized = true;
}
}
Expand Down
41 changes: 24 additions & 17 deletions src/amg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ADD_FIELD_OFFSET_ENTRY(_prefix, mod_rap2, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, keep_transpose, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, num_functions, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, filter_functions, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, seq_amg_th, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, min_coarse_size, FieldTypeIntSet) \
ADD_FIELD_OFFSET_ENTRY(_prefix, max_coarse_size, FieldTypeIntSet) \
Expand Down Expand Up @@ -118,25 +119,26 @@ AMGintSetDefaultArgs(AMGint_args *args)
void
AMGcsnSetDefaultArgs(AMGcsn_args *args)
{
args->rap2 = 0;
args->rap2 = 0;
#if defined (HYPRE_USING_GPU)
args->type = 8;
args->mod_rap2 = 1;
args->keep_transpose = 1;
args->type = 8;
args->type = 8;
args->mod_rap2 = 1;
args->keep_transpose = 1;
args->type = 8;
#else
args->type = 10;
args->mod_rap2 = 0;
args->keep_transpose = 0;
args->type = 10;
args->type = 10;
args->mod_rap2 = 0;
args->keep_transpose = 0;
args->type = 10;
#endif
args->num_functions = 1;
args->seq_amg_th = 0;
args->min_coarse_size = 0;
args->max_coarse_size = 64;
args->max_levels = 25;
args->max_row_sum = 0.9;
args->strong_th = 0.25;
args->num_functions = 1;
args->filter_functions = 0;
args->seq_amg_th = 0;
args->min_coarse_size = 0;
args->max_coarse_size = 64;
args->max_levels = 25;
args->max_row_sum = 0.9;
args->strong_th = 0.25;
}

/*-----------------------------------------------------------------------------
Expand Down Expand Up @@ -280,7 +282,8 @@ AMGcsnGetValidValues(const char* key)

return STR_INT_MAP_ARRAY_CREATE(map);
}
else if (!strcmp(key, "rap2") ||
else if (!strcmp(key, "filter_functions") ||
!strcmp(key, "rap2") ||
!strcmp(key, "mod_rap2") ||
!strcmp(key, "keep_transpose"))
{
Expand Down Expand Up @@ -506,5 +509,9 @@ AMGCreate(AMG_args *args, HYPRE_Solver *precon_ptr)
HYPRE_BoomerAMGSetCycleNumSweeps(precon, args->relaxation.num_sweeps, 3);
}

#if HYPRE_CHECK_MIN_VERSION(23100, 16)
HYPRE_BoomerAMGSetFilterFunctions(precon, args->coarsening.filter_functions);
#endif

*precon_ptr = precon;
}
4 changes: 2 additions & 2 deletions src/mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ MGRCreate(MGR_args *args, HYPRE_Solver *precon_ptr, HYPRE_Solver *csolver_ptr)
if (args->level[i].f_relaxation.type == 2)
{
AMGCreate(&args->level[i].f_relaxation.amg, &frelax);
#if HYPRE_CHECK_MIN_VERSION(23100, 8)
#if HYPRE_CHECK_MIN_VERSION(23100, 9)
HYPRE_MGRSetFSolverAtLevel(precon, frelax, i);
#else
HYPRE_MGRSetFSolverAtLevel(i, precon, frelax);
Expand All @@ -502,7 +502,7 @@ MGRCreate(MGR_args *args, HYPRE_Solver *precon_ptr, HYPRE_Solver *csolver_ptr)
}

/* Config global relaxation at level >= 0 */
#if HYPRE_CHECK_MIN_VERSION(23100, 8)
#if HYPRE_CHECK_MIN_VERSION(23100, 9)
for (i = 0; i < num_levels; i++)
{
if (args->level[i].g_relaxation.type == 16)
Expand Down

0 comments on commit bf229fc

Please sign in to comment.