Skip to content

Commit

Permalink
Update hypre tests.
Browse files Browse the repository at this point in the history
This updates the hypre tests to hypre v2.28.
  • Loading branch information
andrewreisner authored and lukeolson committed Dec 12, 2023
1 parent 5eb710f commit a34610b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 135 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

enable_language(CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wredundant-decls -Wcast-align -Wshadow")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -funroll-loops")
Expand Down
38 changes: 14 additions & 24 deletions raptor/ruge_stuben/tests/test_hypre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void form_hypre_weights(double** weight_ptr, int n_rows)
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
hypre_SeedRand(2747 + rank);
double* weights;
double* weights = nullptr;
if (n_rows)
{
weights = new double[n_rows];
Expand All @@ -39,17 +39,14 @@ int main(int argc, char** argv)
} // end of main() //

TEST(TestHypre, TestsInRuge_Stuben)
{
{
int rank, num_procs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

FILE* f;
int cf;

double strong_threshold = 0.25;
int hyp_coarsen_type = 0; // CLJP
int hyp_interp_type = 0; // ModClassical
int hyp_coarsen_type = 0; // CLJP
int hyp_interp_type = 0; // ModClassical
int p_max_elmts = 0;
int agg_num_levels = 0;
ParCSRMatrix* A;
Expand All @@ -63,7 +60,7 @@ TEST(TestHypre, TestsInRuge_Stuben)


/************************************
**** Test Laplacian
**** Test Laplacian
***********************************/
n = 25;
grid.resize(3);
Expand Down Expand Up @@ -91,27 +88,27 @@ TEST(TestHypre, TestsInRuge_Stuben)
HYPRE_IJVectorGetObject(b_h_ij, (void **) &b_hyp);

// Setup Hypre Hierarchy
HYPRE_Solver solver_data = hypre_create_hierarchy(A_hyp, x_hyp, b_hyp,
hyp_coarsen_type, hyp_interp_type, p_max_elmts, agg_num_levels,
HYPRE_Solver solver_data = hypre_create_hierarchy(A_hyp, x_hyp, b_hyp,
hyp_coarsen_type, hyp_interp_type, p_max_elmts, agg_num_levels,
strong_threshold, 0.0);

hypre_ParCSRMatrix** A_array = hypre_ParAMGDataAArray((hypre_ParAMGData*) solver_data);
hypre_ParCSRMatrix** P_array = hypre_ParAMGDataPArray((hypre_ParAMGData*) solver_data);

for (int level = 0; level < ml->num_levels - 1; level++)
for (int level = 0; level < ml->num_levels - 1; level++)
{
compare(ml->levels[level]->P, P_array[level]);
compare(ml->levels[level+1]->A, A_array[level+1]);
}

hypre_BoomerAMGDestroy(solver_data);
hypre_BoomerAMGDestroy(solver_data);
HYPRE_IJMatrixDestroy(Aij);
delete ml;
delete A;


/************************************
**** Test Anisotropic Diffusion
**** Test Anisotropic Diffusion
***********************************/
n = 100;
grid.resize(2);
Expand All @@ -137,30 +134,23 @@ TEST(TestHypre, TestsInRuge_Stuben)
HYPRE_IJVectorGetObject(b_h_ij, (void **) &b_hyp);

// Setup Hypre Hierarchy
solver_data = hypre_create_hierarchy(A_hyp, x_hyp, b_hyp,
hyp_coarsen_type, hyp_interp_type, p_max_elmts, agg_num_levels,
solver_data = hypre_create_hierarchy(A_hyp, x_hyp, b_hyp,
hyp_coarsen_type, hyp_interp_type, p_max_elmts, agg_num_levels,
strong_threshold, 0.0);

A_array = hypre_ParAMGDataAArray((hypre_ParAMGData*) solver_data);
P_array = hypre_ParAMGDataPArray((hypre_ParAMGData*) solver_data);

for (int level = 0; level < ml->num_levels - 1; level++)
for (int level = 0; level < ml->num_levels - 1; level++)
{
compare(ml->levels[level]->P, P_array[level]);
compare(ml->levels[level+1]->A, A_array[level+1]);
}

hypre_BoomerAMGDestroy(solver_data);
hypre_BoomerAMGDestroy(solver_data);
HYPRE_IJMatrixDestroy(Aij);
delete ml;
delete A;


} // end of TEST(TestHypre, TestsInRuge_Stuben) //







73 changes: 29 additions & 44 deletions raptor/ruge_stuben/tests/test_hypre_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@

using namespace raptor;

void form_hypre_weights(double** weight_ptr, int n_rows)
void form_hypre_weights(std::vector<double> & weights, int n_rows)
{
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
hypre_SeedRand(2747 + rank);
double* weights;
if (n_rows)
weights.resize(n_rows);
for (int i = 0; i < n_rows; i++)
{
weights = new double[n_rows];
for (int i = 0; i < n_rows; i++)
{
weights[i] = hypre_Rand();
}
weights[i] = hypre_Rand();
}

*weight_ptr = weights;
}

int main(int argc, char** argv)
Expand All @@ -39,16 +33,14 @@ int main(int argc, char** argv)
} // end of main() //

TEST(TestHypreInterpolation, TestsInRuge_Stuben)
{
{
int rank, num_procs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

FILE* f;
std::vector<int> states;
std::vector<int> off_proc_states;
double* weights;
int cf;
std::vector<double> weights;

ParCSRMatrix* A;
ParCSRMatrix* S;
Expand All @@ -57,92 +49,85 @@ TEST(TestHypreInterpolation, TestsInRuge_Stuben)
hypre_ParCSRMatrix* A_hyp;
hypre_ParCSRMatrix* S_hyp;
hypre_ParCSRMatrix* P_hyp;
int* states_hypre;
int* coarse_dof_func;
int* coarse_pnts_gbl;
hypre_IntArray* states_hypre = NULL;
hypre_IntArray* coarse_dof_func = NULL;
std::vector<HYPRE_BigInt> coarse_pnts_gbl;
coarse_pnts_gbl.resize(num_procs + 1);

const char* A0_fn = "../../../../test_data/rss_A0.pm";
const char* A1_fn = "../../../../test_data/rss_A1.pm";


// TEST LEVEL 0
A = readParMatrix(A0_fn);
form_hypre_weights(&weights, A->local_num_rows);
form_hypre_weights(weights, A->local_num_rows);
Aij = convert(A);
HYPRE_IJMatrixGetObject(Aij, (void**) &A_hyp);
S = A->strength(Classical, 0.25);
hypre_BoomerAMGCreateS(A_hyp, 0.25, 1.0, 1, NULL, &S_hyp);
compareS(S, S_hyp);

split_pmis(S, states, off_proc_states, false, weights);
split_pmis(S, states, off_proc_states, false, weights.data());
hypre_BoomerAMGCoarsenPMIS(S_hyp, A_hyp, 0, 0, &states_hypre);
compare_states(A->local_num_rows, states, states_hypre);

// Modified Classical Interpolation
hypre_BoomerAMGCoarseParms(MPI_COMM_WORLD, A->local_num_rows, 1, NULL, states_hypre,
&coarse_dof_func, &coarse_pnts_gbl);
&coarse_dof_func, coarse_pnts_gbl.data());
P = mod_classical_interpolation(A, S, states, off_proc_states, false);
hypre_BoomerAMGBuildInterp(A_hyp, states_hypre, S_hyp, coarse_pnts_gbl, 1, NULL, 0, 0.0, 0.0, NULL, &P_hyp);
hypre_BoomerAMGBuildInterp(A_hyp, hypre_IntArrayData(states_hypre), S_hyp, coarse_pnts_gbl.data(), 1, NULL, 0, 0.0, 0, &P_hyp);
compare(P, P_hyp);
hypre_ParCSRMatrixDestroy(P_hyp);
delete P;

// Extended+i Interpolation
hypre_BoomerAMGCoarseParms(MPI_COMM_WORLD, A->local_num_rows, 1, NULL, states_hypre,
&coarse_dof_func, &coarse_pnts_gbl);
&coarse_dof_func, coarse_pnts_gbl.data());
P = extended_interpolation(A, S, states, off_proc_states, 0.3, false);
hypre_BoomerAMGBuildExtPIInterp(A_hyp, states_hypre, S_hyp, coarse_pnts_gbl, 1, NULL, 0, 0.3, 0, NULL, &P_hyp);
hypre_BoomerAMGBuildExtPIInterp(A_hyp, hypre_IntArrayData(states_hypre), S_hyp, coarse_pnts_gbl.data(), 1, NULL, 0, 0.3, 0, &P_hyp);
compare(P, P_hyp);
hypre_ParCSRMatrixDestroy(P_hyp);
delete P;

hypre_TFree(states_hypre, HYPRE_MEMORY_HOST);
hypre_IntArrayDestroy(states_hypre);
states_hypre = NULL;
HYPRE_IJMatrixDestroy(Aij);
hypre_ParCSRMatrixDestroy(S_hyp);
delete[] weights;
delete S;
delete A;


// TEST LEVEL 1
A = readParMatrix(A1_fn);
form_hypre_weights(&weights, A->local_num_rows);
form_hypre_weights(weights, A->local_num_rows);
Aij = convert(A);
HYPRE_IJMatrixGetObject(Aij, (void**) &A_hyp);
S = A->strength(Classical, 0.25);
hypre_BoomerAMGCreateS(A_hyp, 0.25, 1.0, 1, NULL, &S_hyp);
split_pmis(S, states, off_proc_states, false, weights);
split_pmis(S, states, off_proc_states, false, weights.data());
hypre_BoomerAMGCoarsenPMIS(S_hyp, A_hyp, 0, 0, &states_hypre);

// Modified Classical Interpolation
hypre_BoomerAMGCoarseParms(MPI_COMM_WORLD, A->local_num_rows, 1, NULL, states_hypre,
&coarse_dof_func, &coarse_pnts_gbl);
&coarse_dof_func, coarse_pnts_gbl.data());
P = mod_classical_interpolation(A, S, states, off_proc_states, false);
hypre_BoomerAMGBuildInterp(A_hyp, states_hypre, S_hyp, coarse_pnts_gbl, 1, NULL, 0, 0.0, 0, NULL, &P_hyp);
hypre_BoomerAMGBuildInterp(A_hyp, hypre_IntArrayData(states_hypre), S_hyp, coarse_pnts_gbl.data(), 1, NULL, 0, 0.0, 0, &P_hyp);
compare(P, P_hyp);
hypre_ParCSRMatrixDestroy(P_hyp);
delete P;

// Extended+i Interpolation
hypre_BoomerAMGCoarseParms(MPI_COMM_WORLD, A->local_num_rows, 1, NULL, states_hypre,
&coarse_dof_func, &coarse_pnts_gbl);
&coarse_dof_func, coarse_pnts_gbl.data());
P = extended_interpolation(A, S, states, off_proc_states, 0.3, false);
hypre_BoomerAMGBuildExtPIInterp(A_hyp, states_hypre, S_hyp, coarse_pnts_gbl, 1, NULL, 0, 0.3, 0, NULL, &P_hyp);
hypre_BoomerAMGBuildExtPIInterp(A_hyp, hypre_IntArrayData(states_hypre), S_hyp, coarse_pnts_gbl.data(), 1, NULL, 0, 0.3, 0, &P_hyp);
compare(P, P_hyp);
hypre_ParCSRMatrixDestroy(P_hyp);
delete P;

hypre_TFree(states_hypre, HYPRE_MEMORY_HOST);
hypre_IntArrayDestroy(states_hypre);
HYPRE_IJMatrixDestroy(Aij);
hypre_ParCSRMatrixDestroy(S_hyp);
delete[] weights;
delete S;
delete A;



} // end of TEST(TestParSplitting, TestsInRuge_Stuben) //




Loading

0 comments on commit a34610b

Please sign in to comment.