Report error on hypre calls outside of HYPRE_Init() - HYPRE_Finalize() (#837)

When hypre handle is not initialized and a call to hypre_handle() is made, report an error and call HYPRE_Init() rather than just calling hypre_HandleCreate() with no error reporting.
This commit is contained in:
Wayne Mitchell 2023-03-21 14:31:52 -07:00 committed by GitHub
parent 9e84e35bf4
commit 1eabaf5f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 27 deletions

View File

@ -475,6 +475,31 @@ main( hypre_int argc,
char mem_tracker_name[HYPRE_MAX_FILE_NAME_LEN] = {0};
#endif
/* Initialize MPI */
hypre_MPI_Init(&argc, &argv);
hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs );
hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid );
/*-----------------------------------------------------------------
* GPU Device binding
* Must be done before HYPRE_Init() and should not be changed after
*-----------------------------------------------------------------*/
hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD);
time_index = hypre_InitializeTiming("Hypre init");
hypre_BeginTiming(time_index);
/*-----------------------------------------------------------
* Initialize : must be the first HYPRE function to call
*-----------------------------------------------------------*/
HYPRE_Init();
hypre_EndTiming(time_index);
hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD);
hypre_FinalizeTiming(time_index);
hypre_ClearTiming();
/* default execution policy and memory space */
#if defined(HYPRE_TEST_USING_HOST)
HYPRE_MemoryLocation memory_location = HYPRE_MEMORY_HOST;
@ -529,12 +554,6 @@ main( hypre_int argc,
size_t mempool_max_cached_bytes = 2000LL * 1024 * 1024;
#endif
/* Initialize MPI */
hypre_MPI_Init(&argc, &argv);
hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs );
hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid );
/*-----------------------------------------------------------
* Set defaults
*-----------------------------------------------------------*/
@ -2429,25 +2448,6 @@ main( hypre_int argc,
hypre_printf(" solver ID = %d\n\n", solver_id);
}
/*-----------------------------------------------------------------
* GPU Device binding
* Must be done before HYPRE_Init() and should not be changed after
*-----------------------------------------------------------------*/
hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD);
time_index = hypre_InitializeTiming("Hypre init");
hypre_BeginTiming(time_index);
/*-----------------------------------------------------------
* Initialize : must be the first HYPRE function to call
*-----------------------------------------------------------*/
HYPRE_Init();
hypre_EndTiming(time_index);
hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD);
hypre_FinalizeTiming(time_index);
hypre_ClearTiming();
#ifdef HYPRE_USING_DEVICE_POOL
/* To be effective, hypre_SetCubMemPoolSize must immediately follow HYPRE_Init */
HYPRE_SetGPUMemoryPoolSize( mempool_bin_growth, mempool_min_bin,

View File

@ -35,7 +35,8 @@ hypre_handle(void)
{
if (!_hypre_handle)
{
_hypre_handle = hypre_HandleCreate();
hypre_error_w_msg(HYPRE_ERROR_GENERIC, "ERROR - _hypre_handle is not initialized. Calling HYPRE_Init(). All HYPRE_* or hypre_* function calls should occur between HYPRE_Init() and HYPRE_Finalize().\n");
HYPRE_Init();
}
return _hypre_handle;
@ -354,12 +355,16 @@ HYPRE_Finalize(void)
hypre_UmpireFinalize(_hypre_handle);
#endif
#if defined(HYPRE_USING_SYCL)
/* With sycl, cannot call hypre_GetDeviceLastError() after destroying the handle, so do it here */
hypre_GetDeviceLastError();
#endif
hypre_HandleDestroy(_hypre_handle);
_hypre_handle = NULL;
#if !defined(HYPRE_USING_SYCL)
/* With sycl, cannot call hypre_GetDeviceLastError() after destroying the handle */
hypre_GetDeviceLastError();
#endif