-
Notifications
You must be signed in to change notification settings - Fork 48
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
Create a view for std_vector input #1022
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fbcbce
Create a view for std_vector input
Prasanna-Ponnusamy 1d98463
create a view of sc_array
Prasanna-Ponnusamy c7ee3e8
revised version with wrappers for forest search and ghost exchange
Prasanna-Ponnusamy c69421a
Update t8_forest_partition.cxx
Prasanna-Ponnusamy f878708
Update t8_forest_partition.cxx
Prasanna-Ponnusamy bbe995d
Example with vector input
Prasanna-Ponnusamy 59f89bf
Merge branch 'sc_array-view' of github.com:DLR-AMR/t8code into sc_arr…
Prasanna-Ponnusamy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"files.associations": { | ||
"array": "cpp", | ||
"bitset": "cpp", | ||
"string_view": "cpp", | ||
"initializer_list": "cpp", | ||
"utility": "cpp", | ||
"vector": "cpp", | ||
"atomic": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"cctype": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"deque": "cpp", | ||
"list": "cpp", | ||
"map": "cpp", | ||
"set": "cpp", | ||
"unordered_map": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"optional": "cpp", | ||
"random": "cpp", | ||
"string": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"fstream": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"new": "cpp", | ||
"ostream": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"cinttypes": "cpp", | ||
"typeinfo": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
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 <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; | ||
} | ||
/* 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 () == forest_from->local_num_elements); | ||
T8_ASSERT (data_out_vec.size () == forest_to->local_num_elements); | ||
|
||
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); | ||
} | ||
/* 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_debugf("Entering ghost_exchange_data_with_vector\n"); | ||
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); | ||
} | ||
/*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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hope it is clear now. If not please let me know.