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 with vector as input #1059

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4fbcbce
Create a view for std_vector input
Prasanna-Ponnusamy Apr 10, 2024
1d98463
create a view of sc_array
Prasanna-Ponnusamy Apr 11, 2024
c7ee3e8
revised version with wrappers for forest search and ghost exchange
Prasanna-Ponnusamy Apr 11, 2024
c69421a
Update t8_forest_partition.cxx
Prasanna-Ponnusamy Apr 11, 2024
f878708
Update t8_forest_partition.cxx
Prasanna-Ponnusamy Apr 11, 2024
bbe995d
Example with vector input
Prasanna-Ponnusamy May 2, 2024
59f89bf
Merge branch 'sc_array-view' of github.com:DLR-AMR/t8code into sc_arr…
Prasanna-Ponnusamy May 2, 2024
6d54516
test for ghost exchange using std vector as input
Prasanna-Ponnusamy May 3, 2024
a301b5f
Delete .vscode/settings.json
Prasanna-Ponnusamy May 8, 2024
c167a8b
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy May 8, 2024
0615a3c
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Jun 5, 2024
a9559cb
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Jun 5, 2024
6fb9f94
Update src/t8_forest/t8_forest_partition.cxx
Prasanna-Ponnusamy Jun 5, 2024
d9d26d6
made a test to compare parameters between std vector and array
Prasanna-Ponnusamy Jun 24, 2024
443eca4
Revert "made a test to compare parameters between std vector and array"
Prasanna-Ponnusamy Jun 24, 2024
4651ca7
comparing parameters between stdvector and sc_array
Prasanna-Ponnusamy Jun 24, 2024
90b3527
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jun 25, 2024
e5602b1
Merge remote-tracking branch 'origin/main' into test-with-vector-as-i…
Prasanna-Ponnusamy Jul 10, 2024
12c59d3
indented files
Prasanna-Ponnusamy Jul 10, 2024
f39f2a0
modified makefile
Prasanna-Ponnusamy Jul 10, 2024
fdd9b50
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
Prasanna-Ponnusamy Jul 10, 2024
aed1e8b
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 12, 2024
01f7148
renamed t8_default header due to Sandro's recent PR
Prasanna-Ponnusamy Jul 16, 2024
cd61488
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 16, 2024
f9fd0a6
indented files again
Prasanna-Ponnusamy Jul 16, 2024
42225d0
Updated t8_gtest_ghost_exchange_stdvector file
Prasanna-Ponnusamy Jul 16, 2024
5c3f71b
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 16, 2024
a5ae2dd
fixed errors
Prasanna-Ponnusamy Jul 17, 2024
1a177eb
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 17, 2024
81fa33a
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
Prasanna-Ponnusamy Jul 17, 2024
50a4a36
Remove warnings
lukasdreyer Jul 17, 2024
ebfba6c
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 17, 2024
1a6b92f
Add empty parameter to variadic macro in order to satisfy ISO C standard
lukasdreyer Jul 17, 2024
56a5eb4
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
lukasdreyer Jul 17, 2024
0fcfc7f
Update test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx
Prasanna-Ponnusamy Aug 14, 2024
1bf3f46
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Aug 14, 2024
13919cd
license statements for stdvectortest.cxx
Prasanna-Ponnusamy Aug 14, 2024
bf43faa
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Aug 14, 2024
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: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ libt8_installed_headers_cmesh = \
src/t8_cmesh/t8_cmesh_types.h \
src/t8_cmesh/t8_cmesh_stash.h
libt8_installed_headers_data = \
src/t8_data/t8_shmem.h src/t8_data/t8_containers.h
src/t8_data/t8_shmem.h src/t8_data/t8_containers.h \
src/t8_data/t8_stdvector_conversion.hxx
libt8_installed_headers_forest = \
src/t8_forest/t8_forest.h \
src/t8_forest/t8_forest_general.h \
Expand Down
101 changes: 101 additions & 0 deletions src/t8_data/t8_stdvector_conversion.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
This file is part of t8code.
t8code is a C library to manage a collection (a forest) of multiple
connected adaptive space-trees of general element classes in parallel.

Copyright (C) 2024 the developers

t8code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

t8code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with t8code; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** \file t8_stdvector_conversion.hxx
* Basic conversion routines for std::vector to t8code data types.
*/

#ifndef T8_STDVECTOR_CONVERSION_H
#define T8_STDVECTOR_CONVERSION_H
#include <t8_forest/t8_forest_partition.h>
#include <t8_forest/t8_forest_iterate.h>
#include <t8_forest/t8_forest_general.h>
#include <vector>

/* Template to create sc_array view from vector*/
template <typename T>
sc_array_t *
t8_create_sc_array_view_from_vector (const std::vector<T> &vector)
{
void *vector_data = (void *) vector.data ();
sc_array_t *new_view = sc_array_new_data (vector_data, sizeof (T), vector.size ());
return new_view;
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/* Wrapper function for partition data */
template <typename T>
void
t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, const std::vector<T> &data_in_vec,
std::vector<T> &data_out_vec)
{
/* Create temporary sc array. */
sc_array_t *data_in_view, *data_out_view;

T8_ASSERT (data_in_vec.size () == t8_forest_get_local_num_elements (forest_from));
T8_ASSERT (data_out_vec.size () == t8_forest_get_local_num_elements (forest_to));

data_in_view = t8_create_sc_array_view_from_vector (data_in_vec);
data_out_view = t8_create_sc_array_view_from_vector (data_out_vec);
/* calling the original function with the sc_array_t view */
t8_forest_partition_data (forest_from, forest_to, data_in_view, data_out_view);

/* Clean-up memory */
sc_array_destroy (data_in_view);
sc_array_destroy (data_out_view);
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/* Wrapper function for ghost exchange function */
template <typename T>
void
t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector<T> &element_vector)
{
T8_ASSERT (t8_forest_is_committed (forest));

/*Create sc_array_t view from the vector*/
sc_array_t *element_data = t8_create_sc_array_view_from_vector (element_vector);

/* calling the original function with the sc_array_t view */
t8_forest_ghost_exchange_data (forest, element_data);

/*Clean up the sc_array_t view*/
sc_array_destroy (element_data);
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/*Wrapper function to handle std::vector directly for t8_forest_search*/
template <typename T>
void
t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_query_fn search_fn,
t8_forest_search_query_fn query_fn, const std::vector<T> &query_vector)
{
t8_debugf ("Entering t8_forest_search_with_vector\n");
T8_ASSERT (t8_forest_is_committed (forest));

/*Create sc_array_t view from the vector*/
sc_array_t *queries = t8_create_sc_array_view_from_vector (query_vector);

/*calling the original t8_forest_search function with the sc_array_t view */
t8_forest_search (forest, search_fn, query_fn, queries);

/* Clean up the sc_array_t view */
sc_array_destroy (queries);
}
#endif // T8_STDVECTOR_CONVERSION_H
24 changes: 24 additions & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ t8code_googletest_programs = \
test/t8_forest/t8_gtest_user_data \
test/t8_forest/t8_gtest_transform \
test/t8_forest/t8_gtest_ghost_exchange \
test/t8_forest/t8_gtest_ghost_exchange_stdvector \
test/t8_forest/stdvectortest \
test/t8_forest/t8_gtest_ghost_delete \
test/t8_forest/t8_gtest_ghost_and_owner \
test/t8_forest/t8_gtest_forest_commit \
Expand Down Expand Up @@ -281,10 +283,20 @@ test_t8_forest_t8_gtest_ghost_exchange_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_exchange.cxx


test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx

test_t8_forest_stdvectortest_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/stdvectortest.cxx

test_t8_forest_t8_gtest_ghost_delete_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_delete.cxx


test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_and_owner.cxx
Expand Down Expand Up @@ -545,6 +557,14 @@ test_t8_forest_t8_gtest_ghost_exchange_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_exchange_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_forest_stdvectortest_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_stdvectortest_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_stdvectortest_CPPFLAGS = $(t8_gtest_target_cpp_flags)

test_t8_forest_t8_gtest_ghost_delete_LDADD = $(t8_gtest_target_ld_add)
test_t8_forest_t8_gtest_ghost_delete_LDFLAGS = $(t8_gtest_target_ld_flags)
test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS = $(t8_gtest_target_cpp_flags)
Expand Down Expand Up @@ -668,7 +688,11 @@ test_t8_geometry_t8_gtest_point_inside_CPPFLAGS += $(t8_gtest_target_mpi_cpp_fla
test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)

test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)

test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_forest_commit_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_balance_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
Expand Down
86 changes: 86 additions & 0 deletions test/t8_forest/stdvectortest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
This file is part of t8code.
t8code is a C library to manage a collection (a forest) of multiple
connected adaptive space-trees of general element classes in parallel.

Copyright (C) 2024 the developers

t8code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

t8code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with t8code; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <gtest/gtest.h>
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved
#include <vector>
#include <typeinfo>
#include <t8_data/t8_stdvector_conversion.hxx> // header for sc_array conversion
#include "sc_containers.h" // header for sc_array_t and related functions

// Define sc_array_count function
size_t
sc_array_count (const sc_array_t* sc_arr)
{
return sc_arr->elem_count; // Access the count member
}

template <typename T>
class VectorTest: public ::testing::Test {
protected:
void
SetUp () override
{
// Initialize the vector with some test values
vec = { T (1), T (2), T (3), T (4), T (5) };
arr = vec.data ();
// Convert std::vector to sc_array
sc_arr = t8_create_sc_array_view_from_vector (vec);
}

void
TearDown () override
{
// Clean up the sc_array to prevent memory leaks
sc_array_destroy (sc_arr);
}

std::vector<T> vec; // Standard vector
const T* arr; // Raw pointer to the vector data
sc_array_t* sc_arr; // Converted sc_array
};

TYPED_TEST_SUITE_P (VectorTest);

TYPED_TEST_P (VectorTest, LengthTest)
{
// Test that the vector length is as expected
ASSERT_EQ (this->vec.size (), 5u) << "Vector length should be 5 for testing purposes";
// Test that the sc_array length matches the vector length
ASSERT_EQ (sc_array_count (this->sc_arr), this->vec.size ()) << "sc_array length should match vector length";
}

TYPED_TEST_P (VectorTest, ElementComparisonTest)
{
for (size_t i = 0; i < this->vec.size (); ++i) {
// Compare elements in the vector
EXPECT_EQ (this->vec[i], this->arr[i]) << "Element mismatch at index " << i;
// Compare elements between the vector and sc_array
EXPECT_EQ (this->vec[i], *(reinterpret_cast<const TypeParam*> (sc_array_index (this->sc_arr, i))))
<< "Element mismatch between vector and sc_array at index " << i;
}
}

REGISTER_TYPED_TEST_SUITE_P (VectorTest, LengthTest, ElementComparisonTest);

using MyTypes = ::testing::Types<int, double, float, char, short, long, long long, unsigned int, unsigned char,
unsigned short, unsigned long, unsigned long long>;

INSTANTIATE_TYPED_TEST_SUITE_P (MyVectorTests, VectorTest, MyTypes, );
Loading
Loading