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

Free communicator #44

Draft
wants to merge 2 commits into
base: vlasiator-version
Choose a base branch
from
Draft
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
104 changes: 12 additions & 92 deletions dccrg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,98 +309,8 @@ template <
Dccrg():geometry_rw(length, mapping, topology){}


/*!
Creates an instance of the grid based on another instance of the grid.

Call this with all processes unless you really know what you are doing.
Must not be used while the instance being copied is updating remote
neighbor data or balancing the load.
The Cell_Data class can differ between the two grids.
The geometry of this grid must be compatible with the other
grid's geometry (it must have a copy contructor taking the
other grid's geometry as an argument).

The following data is not included in the new dccrg instance:
- Other_Cell_Data, in other words the other grid's cell data
- refined/unrefined cells
- everything related to load balancing or remote neighbor updates

A dccrg instance created this way is already initialized.
*/
template<
class Other_Cell_Data,
class Other_Geometry
> Dccrg(const Dccrg<Other_Cell_Data, Other_Geometry>& other) :
topology_rw(other.topology),
mapping_rw(other.mapping),
geometry_rw(length, mapping, topology),
mapping_initialized(other.get_mapping_initialized()),
grid_initialized(other.get_initialized()),
neighborhood_length(other.get_neighborhood_length()),
max_tag(other.get_max_tag()),
send_single_cells(other.get_send_single_cells()),
comm(other.get_communicator()),
rank(uint64_t(other.get_rank())),
comm_size(uint64_t(other.get_comm_size())),
neighborhood_of(other.get_neighborhood_of()),
neighborhood_to(other.get_neighborhood_to()),
user_hood_of(other.get_user_hood_of()),
user_hood_to(other.get_user_hood_to()),
neighbors_to(other.get_all_neighbors_to()),
user_neigh_of(other.get_all_user_neigh_of()),
user_neigh_to(other.get_all_user_neigh_to()),
cell_process(other.get_cell_process()),
local_cells_on_process_boundary(other.get_local_cells_on_process_boundary_internal()),
remote_cells_on_process_boundary(other.get_remote_cells_on_process_boundary_internal()),
user_local_cells_on_process_boundary(other.get_user_local_cells_on_process_boundary()),
user_remote_cells_on_process_boundary(other.get_user_remote_cells_on_process_boundary()),
cells_to_send(other.get_cells_to_send()),
cells_to_receive(other.get_cells_to_receive()),
user_neigh_cells_to_send(other.get_user_neigh_cells_to_send()),
user_neigh_cells_to_receive(other.get_user_neigh_cells_to_receive()),
pin_requests(other.get_pin_requests()),
new_pin_requests(other.get_new_pin_requests()),
processes_per_part(other.get_processes_per_part()),
partitioning_options(other.get_partitioning_options()),
no_load_balancing(other.get_no_load_balancing()),
reserved_options(other.get_reserved_options()),
cell_weights(other.get_cell_weights()),
neighbor_processes(other.get_neighbor_processes()),
balancing_load(other.get_balancing_load())
{
if (other.get_balancing_load()) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Copy constructor called while the instance being copied is balancing load"
<< std::endl;
abort();
}

if (!this->geometry_rw.set(other.geometry)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Couldn't set geometry while copy constructing"
<< std::endl;
abort();
}

if (!this->mapping_rw.set_maximum_refinement_level(other.mapping.get_maximum_refinement_level())) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Couldn't set maximum refinement level when copy constructing"
<< std::endl;
abort();
}

this->zoltan = Zoltan_Copy(other.get_zoltan());

// default construct Other_Cell_Data of local cells
for (typename std::unordered_map<uint64_t, Other_Cell_Data>::const_iterator
cell_item = other.get_cell_data().begin();
cell_item != other.get_cell_data().end();
cell_item++
) {
this->cell_data[cell_item->first];
}
}

// Copy constructor is deleted, since copying the entire grid is typically a mistake
template< class Other_Cell_Data, class Other_Geometry > Dccrg(const Dccrg<Other_Cell_Data, Other_Geometry>& other) = delete;

/*!
Initializes the instance of the grid with given parameters.
Expand Down Expand Up @@ -503,6 +413,16 @@ template <
return *this;
}

void finalize() {
if (comm != MPI_COMM_NULL) {
MPI_Comm_free(&comm);
comm = MPI_COMM_NULL;
}
}

~Dccrg() {
finalize();
}

/*!
Sets the geometry of the grid to given values.
Expand Down