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

Test find owner #479

Merged
merged 6 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
#Included from toplevel directory

t8code_test_programs = \
test/t8_forest/t8_test_find_owner \
test/t8_forest/t8_test_ghost_exchange \
test/t8_forest/t8_test_ghost_and_owner \
test/t8_forest/t8_test_forest_commit \
test/t8_forest/t8_test_transform \
test/t8_forest/t8_test_user_data

test_t8_forest_t8_test_find_owner_SOURCES = test/t8_forest/t8_test_find_owner.cxx
test_t8_forest_t8_test_ghost_exchange_SOURCES = test/t8_forest/t8_test_ghost_exchange.cxx
test_t8_forest_t8_test_ghost_and_owner_SOURCES = test/t8_forest/t8_test_ghost_and_owner.cxx
test_t8_forest_t8_test_forest_commit_SOURCES = test/t8_forest/t8_test_forest_commit.cxx
Expand Down Expand Up @@ -50,6 +48,7 @@ test_t8_gtest_main_SOURCES = test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_element_general_function.cxx \
test/t8_gtest_vtk_linkage.cxx \
test/t8_data/t8_gtest_shmem.cxx \
test/t8_forest/t8_gtest_find_owner.cxx \
test/t8_schemes/t8_gtest_pyra_face_descendant.cxx \
test/t8_geometry/t8_gtest_point_inside.cxx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <gtest/gtest.h>
#include <t8_eclass.h>
#include <t8_cmesh.h>
#include <t8_forest.h>
Expand All @@ -31,6 +32,22 @@
#include <t8_forest/t8_forest_partition.h>
#include <t8_forest/t8_forest_private.h>

/* *INDENT-OFF* */
class forest_find_owner:public testing::TestWithParam <t8_eclass > {
protected:
void SetUp () override {
eclass = GetParam();

default_scheme = t8_scheme_new_default_cxx ();
/* Construct a coarse mesh of one tree */
cmesh = t8_cmesh_new_from_class (eclass, sc_MPI_COMM_WORLD);
}
t8_eclass_t eclass;
t8_cmesh_t cmesh;
t8_scheme_cxx_t *default_scheme;
};
/* *INDENT-ON* */

#if 0
/* Depending on an integer i create a different cmesh.
* i = 0: cmesh_new_class
Expand All @@ -53,106 +70,92 @@ t8_test_create_cmesh (int i, t8_eclass_t eclass, sc_MPI_Comm comm)
}
}

static void
t8_test_find_owner (sc_MPI_Comm comm, t8_eclass_t eclass)
TEST_P (forest_find_owner, find_owner)
{
int i;
t8_cmesh_t cmesh;
t8_forest_t forest;
t8_element_t *element;
t8_scheme_cxx *scheme;
t8_eclass_scheme_c *ts;
t8_gloidx_t ielement, itree, global_elem_num;
t8_gloidx_t elements_per_tree;
int level = 5;
int owner, owner_alter;

T8_ASSERT (eclass != T8_ECLASS_PYRAMID);

t8_global_productionf ("Testing find_owner with eclass %s\n",
t8_eclass_to_string[eclass]);
t8_debugf ("Testing find_owner with eclass %s\n",
t8_eclass_to_string[eclass]);

scheme = t8_scheme_new_default_cxx ();
/* allocate the element */
ts = scheme->eclass_schemes[eclass];
t8_eclass_scheme_c ts = scheme->eclass_schemes[eclass];
ts->t8_element_new (1, &element);
/* Compute the number of elements per tree */
ts->t8_element_set_linear_id (element, 0, 0);
/* TODO: This computation fails with pyramids */
elements_per_tree = pow (ts->t8_element_num_children (element), level);
t8_gloidx_t elements_per_tree =
pow (ts->t8_element_num_children (element), level);

for (i = 0; i < 3; i++) {
t8_global_productionf ("\tTesting cmesh type %i\n", i);
for (int itype = 0; itype < 3; itype++) {
t8_debugf ("\tTesting cmesh type %i\n", itype);
/* build the cmesh */
cmesh = t8_test_create_cmesh (i, eclass, comm);
cmesh = t8_test_create_cmesh (itype, eclass, sc_MPI_COMM_WORLD);
/* We reuse the scheme for all forests and thus ref it */
t8_scheme_cxx_ref (scheme);
t8_scheme_cxx_ref (default_scheme);
/* build the forest */
forest = t8_forest_new_uniform (cmesh, scheme, level, 0, comm);
for (itree = 0, global_elem_num = 0;
t8_forest_t forest =
t8_forest_new_uniform (cmesh, default_scheme, level, 0,
sc_MPI_COMM_WORLD);
for (int itree = 0, t8_gloidx_t global_elem_num = 0;
itree < t8_forest_get_num_global_trees (forest); itree++) {
/* Iterate over all trees */
for (ielement = 0; ielement < elements_per_tree;
for (t8_gloidx_t ielement = 0; ielement < elements_per_tree;
ielement++, global_elem_num++) {
/* Compute the ielement's elements in the tree */
ts->t8_element_set_linear_id (element, level, (uint64_t) ielement);
/* Find the owner of the element */
owner = t8_forest_element_find_owner (forest, itree, element, eclass);
int owner =
t8_forest_element_find_owner (forest, itree, element, eclass);
/* Find the owner in a different way via the element offset array.
* This is only possible since we have a uniform refinement. */
if (forest->element_offsets == NULL) {
t8_forest_partition_create_offsets (forest);
}
owner_alter = -1;
int owner_alter = -1;
t8_offset_first_owner_of_tree (forest->mpisize, global_elem_num,
t8_shmem_array_get_gloidx_array
(forest->element_offsets),
&owner_alter);
/* Check if both owners are the same */
SC_CHECK_ABORTF (owner == owner_alter,
"Finding owner for element %lli in tree %lli failed.\n",
(long long) ielement, (long long) itree);
ASSERT_EQ (owner,
owner_alter) << "Finding owner for element " << (long long)
ielement << " in tree " << (long long) itree << " failed.\n";
}
}
t8_forest_unref (&forest);
}
/* clean-up */
ts->t8_element_destroy (1, &element);
t8_scheme_cxx_unref (&scheme);
t8_scheme_cxx_unref (&default_scheme);
}
#endif

static void
t8_test_find_multiple_owners (sc_MPI_Comm comm, t8_eclass_t eclass)
TEST_P (forest_find_owner, find_multiple_owners)
{
t8_cmesh_t cmesh;
t8_forest_t forest;
t8_scheme_cxx_t *default_scheme;
t8_eclass_scheme_c *ts;
t8_element_t *root_element;
sc_array_t owners;
int iowner;
int face;
int level = 1;
char buffer[BUFSIZ];

default_scheme = t8_scheme_new_default_cxx ();
/* Construct a coarse mesh of one tree */
cmesh = t8_cmesh_new_from_class (eclass, comm);
/* initialize the array of owners to store ints */
sc_array_init (&owners, sizeof (int));
/* Build a uniform forest */
forest = t8_forest_new_uniform (cmesh, default_scheme, level, 0, comm);
ts = t8_forest_get_eclass_scheme (forest, eclass);
t8_forest_t forest =
t8_forest_new_uniform (cmesh, default_scheme, level, 0,
sc_MPI_COMM_WORLD);
t8_eclass_scheme_c *ts = t8_forest_get_eclass_scheme (forest, eclass);
/* Construct the root element */
ts->t8_element_new (1, &root_element);
ts->t8_element_set_linear_id (root_element, 0, 0);
/* For each face determine its owners */
for (face = 0; face < t8_eclass_num_faces[eclass]; face++) {

for (int face = 0; face < t8_eclass_num_faces[eclass]; face++) {
t8_forest_element_owners_at_face (forest, 0, root_element, eclass, face,
&owners);
snprintf (buffer, BUFSIZ, "Owners of root at face %i:", face);
for (iowner = 0; iowner < (int) owners.elem_count; iowner++) {
for (int iowner = 0; iowner < (int) owners.elem_count; iowner++) {
snprintf (buffer + strlen (buffer), BUFSIZ - strlen (buffer),
" %i,", *(int *) sc_array_index_int (&owners, iowner));
}
Expand All @@ -168,28 +171,6 @@ t8_test_find_multiple_owners (sc_MPI_Comm comm, t8_eclass_t eclass)
sc_array_reset (&owners);
}

int
main (int argc, char **argv)
{
int mpiret;
sc_MPI_Comm mpic;
int ieclass;

mpiret = sc_MPI_Init (&argc, &argv);
SC_CHECK_MPI (mpiret);

mpic = sc_MPI_COMM_WORLD;
sc_init (mpic, 1, 1, NULL, SC_LP_PRODUCTION);
t8_init (SC_LP_DEFAULT);

for (ieclass = T8_ECLASS_VERTEX; ieclass < T8_ECLASS_COUNT; ieclass++) {
t8_test_find_multiple_owners (mpic, (t8_eclass_t) ieclass);
}

sc_finalize ();

mpiret = sc_MPI_Finalize ();
SC_CHECK_MPI (mpiret);

return 0;
}
/* *INDENT-OFF* */
INSTANTIATE_TEST_SUITE_P (t8_gtest_find_owner, forest_find_owner,testing::Range(T8_ECLASS_VERTEX, T8_ECLASS_COUNT));
/* *INDENT-ON* */