diff --git a/.gitignore b/.gitignore index cf51a794a..4b1d9c762 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,6 @@ src/TAGS hypre/ cmbuild/ install/ -test/ AUTOTEST/*.dir .vscode diff --git a/src/IJ_mv/HYPRE_IJMatrix.c b/src/IJ_mv/HYPRE_IJMatrix.c index e2b367a0e..041fc9b8b 100644 --- a/src/IJ_mv/HYPRE_IJMatrix.c +++ b/src/IJ_mv/HYPRE_IJMatrix.c @@ -1101,6 +1101,48 @@ HYPRE_IJMatrixGetLocalRange( HYPRE_IJMatrix matrix, return hypre_error_flag; } +/*-------------------------------------------------------------------------- + *--------------------------------------------------------------------------*/ + +HYPRE_Int +HYPRE_IJMatrixGetGlobalInfo( HYPRE_IJMatrix matrix, + HYPRE_BigInt *global_num_rows, + HYPRE_BigInt *global_num_cols, + HYPRE_BigInt *global_num_nonzeros ) +{ + hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix; + + if (!ijmatrix) + { + hypre_error_in_arg(1); + return hypre_error_flag; + } + + *global_num_rows = hypre_IJMatrixGlobalNumRows(ijmatrix); + *global_num_cols = hypre_IJMatrixGlobalNumCols(ijmatrix); + + if (hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR) + { + hypre_ParCSRMatrix *par_matrix = (hypre_ParCSRMatrix *) hypre_IJMatrixObject(ijmatrix); + + if (!par_matrix) + { + hypre_error_in_arg(1); + return hypre_error_flag; + } + + hypre_ParCSRMatrixSetNumNonzeros(par_matrix); + *global_num_nonzeros = hypre_ParCSRMatrixNumNonzeros(par_matrix); + } + else + { + hypre_error_in_arg(1); + return hypre_error_flag; + } + + return hypre_error_flag; +} + /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ @@ -1276,6 +1318,8 @@ HYPRE_Int HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix, const char *filename ) { + void *object; + if (!matrix) { hypre_error_in_arg(1); @@ -1288,11 +1332,8 @@ HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix, return hypre_error_flag; } - void *object; HYPRE_IJMatrixGetObject(matrix, &object); - hypre_ParCSRMatrix *par_csr = (hypre_ParCSRMatrix*) object; - - hypre_ParCSRMatrixPrintIJ(par_csr, 0, 0, filename); + hypre_ParCSRMatrixPrintIJ((hypre_ParCSRMatrix*) object, 0, 0, filename); return hypre_error_flag; } diff --git a/src/IJ_mv/HYPRE_IJ_mv.h b/src/IJ_mv/HYPRE_IJ_mv.h index 9505a63f6..f6cda553f 100644 --- a/src/IJ_mv/HYPRE_IJ_mv.h +++ b/src/IJ_mv/HYPRE_IJ_mv.h @@ -280,6 +280,24 @@ HYPRE_Int HYPRE_IJMatrixGetLocalRange(HYPRE_IJMatrix matrix, HYPRE_BigInt *jlower, HYPRE_BigInt *jupper); +/** + * Gets global information about the matrix, including the total number of rows, + * columns, and nonzero elements across all processes. + * + * @param matrix The IJMatrix object to query. + * @param global_num_rows Pointer to store the total number of rows in the matrix. + * @param global_num_cols Pointer to store the total number of columns in the matrix. + * @param global_num_nonzeros Pointer to store the total number of nonzero elements in the matrix. + * + * @return HYPRE_Int Error code. + * + * Collective (must be called by all processes). + **/ +HYPRE_Int HYPRE_IJMatrixGetGlobalInfo(HYPRE_IJMatrix matrix, + HYPRE_BigInt *global_num_rows, + HYPRE_BigInt *global_num_cols, + HYPRE_BigInt *global_num_nonzeros); + /** * Get a reference to the constructed matrix object. * diff --git a/src/parcsr_ls/par_nongalerkin.c b/src/parcsr_ls/par_nongalerkin.c index 760e4ef57..d052dc128 100644 --- a/src/parcsr_ls/par_nongalerkin.c +++ b/src/parcsr_ls/par_nongalerkin.c @@ -1019,6 +1019,8 @@ hypre_NonGalerkinSparsityPattern(hypre_ParCSRMatrix *R_IAP, HYPRE_Int i, j, Cpt, row_start, row_end; HYPRE_BigInt global_row, global_col; + HYPRE_ANNOTATE_FUNC_BEGIN; + /* Other Setup */ if (num_cols_RAP_offd) { @@ -1233,6 +1235,8 @@ hypre_NonGalerkinSparsityPattern(hypre_ParCSRMatrix *R_IAP, hypre_TFree(ijbuf_sym_numcols, memory_location_RAP); } + HYPRE_ANNOTATE_FUNC_END; + return Pattern_CSR; } @@ -1368,6 +1372,8 @@ hypre_BoomerAMGBuildNonGalerkinCoarseOperator( hypre_ParCSRMatrix **RAP_ptr, HYPRE_BigInt *ijbuf_sym_cols, *ijbuf_sym_rownums; HYPRE_Int *ijbuf_sym_numcols; + HYPRE_ANNOTATE_FUNC_BEGIN; + /* Further Initializations */ if (num_cols_RAP_offd) { RAP_offd_data = hypre_CSRMatrixData(RAP_offd); } @@ -2352,5 +2358,7 @@ hypre_BoomerAMGBuildNonGalerkinCoarseOperator( hypre_ParCSRMatrix **RAP_ptr, HYPRE_IJMatrixSetObjectType(ijmatrix, -1); HYPRE_IJMatrixDestroy(ijmatrix); + HYPRE_ANNOTATE_FUNC_END; + return hypre_error_flag; } diff --git a/src/parcsr_mv/par_csr_filter.c b/src/parcsr_mv/par_csr_filter.c index f579f9796..ae433d639 100644 --- a/src/parcsr_mv/par_csr_filter.c +++ b/src/parcsr_mv/par_csr_filter.c @@ -199,6 +199,8 @@ hypre_ParCSRMatrixBlkFilter( hypre_ParCSRMatrix *A, HYPRE_Int block_size, hypre_ParCSRMatrix **B_ptr ) { + HYPRE_ANNOTATE_FUNC_BEGIN; + #if defined(HYPRE_USING_GPU) if (hypre_GetExecPolicy1(hypre_ParCSRMatrixMemoryLocation(A)) == HYPRE_EXEC_DEVICE) { @@ -210,5 +212,7 @@ hypre_ParCSRMatrixBlkFilter( hypre_ParCSRMatrix *A, hypre_ParCSRMatrixBlkFilterHost(A, block_size, B_ptr); } + HYPRE_ANNOTATE_FUNC_END; + return hypre_error_flag; } diff --git a/src/test/ij.c b/src/test/ij.c index d8a7ec15b..b7d6d7d8f 100644 --- a/src/test/ij.c +++ b/src/test/ij.c @@ -141,6 +141,7 @@ main( hypre_int argc, HYPRE_Int ioutdat; HYPRE_Int poutdat; HYPRE_Int poutusr = 0; /* if user selects pout */ + HYPRE_Int print_matrix_info = 0; HYPRE_Int debug_flag; HYPRE_Int ierr = 0; HYPRE_Int i, j, c; @@ -805,6 +806,11 @@ main( hypre_int argc, build_funcs_type = 2; build_funcs_arg_index = arg_index; } + else if ( strcmp(argv[arg_index], "-mat-info") == 0 ) + { + arg_index++; + print_matrix_info = 1; + } else if ( strcmp(argv[arg_index], "-exact_size") == 0 ) { arg_index++; @@ -3334,6 +3340,42 @@ main( hypre_int argc, } } + /* Print matrix information */ + if (print_matrix_info) + { + HYPRE_BigInt global_num_rows, global_num_cols, global_num_nonzeros; + + if (parcsr_A) + { + HYPRE_BigInt ilower, iupper, jlower, jupper; + + HYPRE_ParCSRMatrixGetLocalRange(parcsr_A, &ilower, &iupper, &jlower, &jupper); + HYPRE_IJMatrixCreate(comm, ilower, iupper, jlower, jupper, &ij_A); + HYPRE_IJMatrixSetObjectType(ij_A, HYPRE_PARCSR); + hypre_IJMatrixObject(ij_A) = parcsr_A; + hypre_IJMatrixAssembleFlag(ij_A) = 1; + } + + HYPRE_IJMatrixGetGlobalInfo(ij_A, + &global_num_rows, + &global_num_cols, + &global_num_nonzeros); + + if (parcsr_A) + { + hypre_IJMatrixObject(ij_A) = NULL; + HYPRE_IJMatrixDestroy(ij_A); + } + + if (myid == 0) + { + hypre_printf(" Matrix Information:\n"); + hypre_printf(" Global number of rows: %b\n", global_num_rows); + hypre_printf(" Global number of columns: %b\n", global_num_cols); + hypre_printf(" Global number of nonzeros: %b\n", global_num_nonzeros); + } + } + /*----------------------------------------------------------- * Set up the RHS and initial guess *-----------------------------------------------------------*/ @@ -4387,6 +4429,8 @@ main( hypre_int argc, if (solver_id == 0 || solver_id == 90) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); + if (solver_id == 0) { if (myid == 0) { hypre_printf("Solver: AMG\n"); } @@ -4640,9 +4684,11 @@ main( hypre_int argc, hypre_PrintTiming("Solve phase times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); HYPRE_SetExecutionPolicy(exec2_policy); /* run a second time [for timings, to check for memory leaks] */ @@ -4698,6 +4744,7 @@ main( hypre_int argc, hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); #if defined(HYPRE_USING_CUDA) cudaProfilerStop(); #endif @@ -4952,6 +4999,7 @@ main( hypre_int argc, solver_id == 43 || solver_id == 71)) /*end lobpcg */ { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("PCG Setup"); hypre_BeginTiming(time_index); @@ -5505,9 +5553,11 @@ main( hypre_int argc, hypre_PrintTiming("Solve phase times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); HYPRE_SetExecutionPolicy(exec2_policy); /* run a second time [for timings, to check for memory leaks] */ @@ -5551,6 +5601,7 @@ main( hypre_int argc, hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); #if defined(HYPRE_USING_CUDA) cudaProfilerStop(); #endif @@ -6650,6 +6701,7 @@ main( hypre_int argc, solver_id == 15 || solver_id == 18 || solver_id == 44 || solver_id == 81 || solver_id == 91) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("GMRES Setup"); hypre_BeginTiming(time_index); @@ -7204,9 +7256,11 @@ main( hypre_int argc, hypre_TFree(indices_d, memory_location); hypre_TFree(values_d, memory_location); } + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); /* run a second time [for timings, to check for memory leaks] */ HYPRE_ParVectorSetRandomValues(x, 775); #if defined(HYPRE_USING_CURAND) || defined(HYPRE_USING_ROCRAND) @@ -7214,10 +7268,15 @@ main( hypre_int argc, #endif hypre_ParVectorCopy(x0_save, x); - HYPRE_GMRESSetup(pcg_solver, (HYPRE_Matrix)parcsr_M, (HYPRE_Vector)b, - (HYPRE_Vector)x); - HYPRE_GMRESSolve(pcg_solver, (HYPRE_Matrix)parcsr_A, (HYPRE_Vector)b, - (HYPRE_Vector)x); + HYPRE_GMRESSetup(pcg_solver, + (HYPRE_Matrix) parcsr_M, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_GMRESSolve(pcg_solver, + (HYPRE_Matrix) parcsr_A, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); } HYPRE_GMRESGetNumIterations(pcg_solver, &num_iterations); @@ -7268,6 +7327,7 @@ main( hypre_int argc, if (solver_id == 50 || solver_id == 51 ) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("LGMRES Setup"); hypre_BeginTiming(time_index); @@ -7485,6 +7545,7 @@ main( hypre_int argc, hypre_printf("Final LGMRES Relative Residual Norm = %e\n", final_res_norm); hypre_printf("\n"); } + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); } /*----------------------------------------------------------- @@ -7493,6 +7554,7 @@ main( hypre_int argc, if (solver_id == 60 || solver_id == 61 || solver_id == 72 || solver_id == 82 || solver_id == 47) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("FlexGMRES Setup"); hypre_BeginTiming(time_index); @@ -7920,6 +7982,7 @@ main( hypre_int argc, hypre_printf("Final FlexGMRES Relative Residual Norm = %e\n", final_res_norm); hypre_printf("\n"); } + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); } /*----------------------------------------------------------- @@ -7928,6 +7991,7 @@ main( hypre_int argc, if (solver_id == 9 || solver_id == 10 || solver_id == 11 || solver_id == 45 || solver_id == 73) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("BiCGSTAB Setup"); hypre_BeginTiming(time_index); @@ -8265,20 +8329,27 @@ main( hypre_int argc, hypre_PrintTiming("Solve phase times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { /* run a second time [for timings, to check for memory leaks] */ + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); HYPRE_ParVectorSetRandomValues(x, 775); #if defined(HYPRE_USING_CURAND) || defined(HYPRE_USING_ROCRAND) hypre_ResetDeviceRandGenerator(1234ULL, 0ULL); #endif hypre_ParVectorCopy(x0_save, x); - HYPRE_BiCGSTABSetup(pcg_solver, (HYPRE_Matrix) parcsr_M, - (HYPRE_Vector) b, (HYPRE_Vector) x); - HYPRE_BiCGSTABSolve(pcg_solver, (HYPRE_Matrix) parcsr_A, - (HYPRE_Vector) b, (HYPRE_Vector) x); + HYPRE_BiCGSTABSetup(pcg_solver, + (HYPRE_Matrix) parcsr_M, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_BiCGSTABSolve(pcg_solver, + (HYPRE_Matrix) parcsr_A, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); } HYPRE_BiCGSTABGetNumIterations(pcg_solver, &num_iterations); @@ -8344,6 +8415,7 @@ main( hypre_int argc, if (solver_id == 16 || solver_id == 17 || solver_id == 46 || solver_id == 74) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("COGMRES Setup"); hypre_BeginTiming(time_index); @@ -8643,20 +8715,27 @@ main( hypre_int argc, hypre_PrintTiming("Solve phase times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { /* run a second time [for timings, to check for memory leaks] */ + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); HYPRE_ParVectorSetRandomValues(x, 775); #if defined(HYPRE_USING_CURAND) || defined(HYPRE_USING_ROCRAND) hypre_ResetDeviceRandGenerator(1234ULL, 0ULL); #endif hypre_ParVectorCopy(x0_save, x); - HYPRE_COGMRESSetup(pcg_solver, (HYPRE_Matrix) parcsr_M, - (HYPRE_Vector) b, (HYPRE_Vector) x); - HYPRE_COGMRESSolve(pcg_solver, (HYPRE_Matrix) parcsr_A, - (HYPRE_Vector) b, (HYPRE_Vector) x); + HYPRE_COGMRESSetup(pcg_solver, + (HYPRE_Matrix) parcsr_M, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_COGMRESSolve(pcg_solver, + (HYPRE_Matrix) parcsr_A, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); } HYPRE_COGMRESGetNumIterations(pcg_solver, &num_iterations); @@ -8717,6 +8796,7 @@ main( hypre_int argc, if (solver_id == 5 || solver_id == 6) { + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-1"); time_index = hypre_InitializeTiming("CGNR Setup"); hypre_BeginTiming(time_index); @@ -8879,20 +8959,27 @@ main( hypre_int argc, hypre_PrintTiming("Solve phase times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); + HYPRE_ANNOTATE_REGION_END("%s", "Run-1"); if (second_time) { /* run a second time [for timings, to check for memory leaks] */ + HYPRE_ANNOTATE_REGION_BEGIN("%s", "Run-2"); HYPRE_ParVectorSetRandomValues(x, 775); #if defined(HYPRE_USING_CURAND) || defined(HYPRE_USING_ROCRAND) hypre_ResetDeviceRandGenerator(1234ULL, 0ULL); #endif hypre_ParVectorCopy(x0_save, x); - HYPRE_CGNRSetup(pcg_solver, (HYPRE_Matrix) parcsr_M, - (HYPRE_Vector) b, (HYPRE_Vector) x); - HYPRE_CGNRSolve(pcg_solver, (HYPRE_Matrix) parcsr_A, - (HYPRE_Vector) b, (HYPRE_Vector) x); + HYPRE_CGNRSetup(pcg_solver, + (HYPRE_Matrix) parcsr_M, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_CGNRSolve(pcg_solver, + (HYPRE_Matrix) parcsr_A, + (HYPRE_Vector) b, + (HYPRE_Vector) x); + HYPRE_ANNOTATE_REGION_END("%s", "Run-2"); } HYPRE_CGNRGetNumIterations(pcg_solver, &num_iterations);