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

Add hypre_MGRSetGlobalSmootherAtLevel to MGR #1091

Merged
merged 13 commits into from May 8, 2024
13 changes: 13 additions & 0 deletions src/parcsr_ls/HYPRE_parcsr_ls.h
Expand Up @@ -4443,6 +4443,19 @@ HYPRE_Int
HYPRE_MGRSetLevelSmoothType( HYPRE_Solver solver,
HYPRE_Int *smooth_type );

/**
* (Optional) Set the global smoother solver at a given level.
*
* @param level [IN] MGR solver level
* @param solver [IN] MGR solver/preconditioner object
* @param fsolver [IN] Global smoother solver object
**/

HYPRE_Int
HYPRE_MGRSetGlobalSmootherAtLevel( HYPRE_Int level,
HYPRE_Solver solver,
HYPRE_Solver smoother );

/**
* (Optional) Return the number of MGR iterations.
**/
Expand Down
19 changes: 19 additions & 0 deletions src/parcsr_ls/HYPRE_parcsr_mgr.c
Expand Up @@ -533,9 +533,11 @@ HYPRE_MGRSetMaxGlobalSmoothIters( HYPRE_Solver solver, HYPRE_Int max_iter )
{
return hypre_MGRSetMaxGlobalSmoothIters(solver, max_iter);
}

/*--------------------------------------------------------------------------
* HYPRE_MGRSetLevelsmoothIters
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_MGRSetLevelSmoothIters( HYPRE_Solver solver,
HYPRE_Int *smooth_iters )
Expand All @@ -546,30 +548,47 @@ HYPRE_MGRSetLevelSmoothIters( HYPRE_Solver solver,
/*--------------------------------------------------------------------------
* HYPRE_MGRSetGlobalsmoothType
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_MGRSetGlobalSmoothType( HYPRE_Solver solver, HYPRE_Int smooth_type )
{
return hypre_MGRSetGlobalSmoothType(solver, smooth_type);
}

/*--------------------------------------------------------------------------
* HYPRE_MGRSetLevelsmoothType
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_MGRSetLevelSmoothType( HYPRE_Solver solver,
HYPRE_Int *smooth_type )
{
return hypre_MGRSetLevelSmoothType(solver, smooth_type);
}

/*--------------------------------------------------------------------------
* HYPRE_MGRSetGlobalSmoothCycle
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_MGRSetGlobalSmoothCycle( HYPRE_Solver solver,
HYPRE_Int global_smooth_cycle )
{
return hypre_MGRSetGlobalSmoothCycle(solver, global_smooth_cycle);
}

/*--------------------------------------------------------------------------
* HYPRE_MGRSetGlobalSmootherAtLevel
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_MGRSetGlobalSmootherAtLevel( HYPRE_Int level,
HYPRE_Solver solver,
HYPRE_Solver smoother )
{
return hypre_MGRSetGlobalSmootherAtLevel(level, (void*) solver, smoother);
}

/*--------------------------------------------------------------------------
* HYPRE_MGRSetPMaxElmts
*--------------------------------------------------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions src/parcsr_ls/_hypre_parcsr_ls.h
Expand Up @@ -3680,6 +3680,8 @@ HYPRE_Int hypre_MGRSetNumRestrictSweeps( void *mgr_vdata, HYPRE_Int nsweeps );
HYPRE_Int hypre_MGRSetLevelSmoothType( void *mgr_vdata, HYPRE_Int *level_smooth_type );
HYPRE_Int hypre_MGRSetLevelSmoothIters( void *mgr_vdata, HYPRE_Int *level_smooth_iters );
HYPRE_Int hypre_MGRSetGlobalSmoothCycle( void *mgr_vdata, HYPRE_Int global_smooth_cycle );
HYPRE_Int hypre_MGRSetGlobalSmootherAtLevel( HYPRE_Int level, void*mgr_vdata,
HYPRE_Solver smoother );
HYPRE_Int hypre_MGRSetPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
HYPRE_Int hypre_MGRSetFrelaxPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
HYPRE_Int hypre_MGRSetCoarseGridPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
Expand Down
48 changes: 48 additions & 0 deletions src/parcsr_ls/par_mgr.c
Expand Up @@ -444,6 +444,11 @@ hypre_MGRDestroy( void *data )
{
HYPRE_ILUDestroy((mgr_data -> level_smoother)[i]);
}
else if ((mgr_data -> level_smoother)[i])
{
hypre_Solver *smoother_base = (hypre_Solver*) (mgr_data -> level_smoother)[i];
hypre_SolverDestroy(smoother_base)((mgr_data -> level_smoother)[i]);
}
}
}
hypre_TFree(mgr_data -> level_smoother, HYPRE_MEMORY_HOST);
Expand Down Expand Up @@ -3537,6 +3542,49 @@ hypre_MGRSetLevelSmoothIters( void *mgr_vdata, HYPRE_Int *gsmooth_iters )
return hypre_error_flag;
}

/*--------------------------------------------------------------------------
* MGRSetGlobalSmootherAtLevel
*
* Set global smoother solver for a given MGR level.
*
* Note this function asks for a level identifier and doesn't expect an array
* of function pointers for each level (as done by SetLevel functions).
*--------------------------------------------------------------------------*/

HYPRE_Int
hypre_MGRSetGlobalSmootherAtLevel( HYPRE_Int level,
void *mgr_vdata,
HYPRE_Solver smoother )
{
hypre_ParMGRData *mgr_data = (hypre_ParMGRData*) mgr_vdata;

if (!mgr_data)
{
hypre_error_in_arg(1);
return hypre_error_flag;
}
HYPRE_Int max_num_coarse_levels = (mgr_data -> max_num_coarse_levels);

/* Allocate level_smoother if needed */
if (!(mgr_data -> level_smoother))
{
(mgr_data -> level_smoother) = hypre_CTAlloc(HYPRE_Solver,
max_num_coarse_levels,
HYPRE_MEMORY_HOST);
}

/* Check if the requested level makes sense */
if (level < 0 || level >= max_num_coarse_levels)
{
hypre_error_in_arg(2);
return hypre_error_flag;
}

(mgr_data -> level_smoother)[level] = smoother;

return hypre_error_flag;
}

/* Set the maximum number of non-zero entries for interpolation operators */
HYPRE_Int
hypre_MGRSetPMaxElmts(void *mgr_vdata, HYPRE_Int P_max_elmts)
Expand Down
16 changes: 13 additions & 3 deletions src/parcsr_ls/par_mgr_setup.c
Expand Up @@ -1020,11 +1020,21 @@ hypre_MGRSetup( void *mgr_vdata,
hypre_sprintf(region_name, "Global-Relax");
hypre_GpuProfilingPushRange(region_name);
HYPRE_ANNOTATE_REGION_BEGIN("%s", region_name);

/* TODO (VPM): Change option types for block-Jacobi and block-GS to 30 and 31 and
make them accessible through hypre_BoomerAMGRelax? */
if (level_smooth_iters[lev] > 0)
{
/* TODO (VPM): Change option types for block-Jacobi and block-GS to 30 and 31 and
make them accessible through hypre_BoomerAMGRelax? */
if (level_smooth_type[lev] == 0 || level_smooth_type[lev] == 1)
if (level_smoother[lev])
{
hypre_Solver *smoother_base = (hypre_Solver*) level_smoother[lev];

/* Call setup function */
hypre_SolverSetup(smoother_base)((HYPRE_Solver) level_smoother[lev],
(HYPRE_Matrix) A_array[lev],
NULL, NULL);
}
else if (level_smooth_type[lev] == 0 || level_smooth_type[lev] == 1)
{
/* TODO (VPM): move this to hypre_MGRBlockRelaxSetup and change its declaration */
#if defined (HYPRE_USING_GPU)
Expand Down
2 changes: 2 additions & 0 deletions src/parcsr_ls/protos.h
Expand Up @@ -2227,6 +2227,8 @@ HYPRE_Int hypre_MGRSetNumRestrictSweeps( void *mgr_vdata, HYPRE_Int nsweeps );
HYPRE_Int hypre_MGRSetLevelSmoothType( void *mgr_vdata, HYPRE_Int *level_smooth_type );
HYPRE_Int hypre_MGRSetLevelSmoothIters( void *mgr_vdata, HYPRE_Int *level_smooth_iters );
HYPRE_Int hypre_MGRSetGlobalSmoothCycle( void *mgr_vdata, HYPRE_Int global_smooth_cycle );
HYPRE_Int hypre_MGRSetGlobalSmootherAtLevel( HYPRE_Int level, void*mgr_vdata,
HYPRE_Solver smoother );
HYPRE_Int hypre_MGRSetPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
HYPRE_Int hypre_MGRSetFrelaxPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
HYPRE_Int hypre_MGRSetCoarseGridPrintLevel( void *mgr_vdata, HYPRE_Int print_level );
Expand Down