Skip to content

Commit

Permalink
Deal with a circular dependency problem.
Browse files Browse the repository at this point in the history
We can't ask a default-created vector for its MPI communicator
if we only later initialize it.
  • Loading branch information
bangerth committed Apr 20, 2023
1 parent ba261cb commit d717b6c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions include/deal.II/sundials/n_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace SUNDIALS
*
* @note This constructor is intended for the N_VClone() call of SUNDIALS.
*/
NVectorContent();
NVectorContent(const MPI_Comm comm);

/**
* Non-const access to the stored vector. Only allowed if a constructor
Expand Down Expand Up @@ -361,9 +361,9 @@ namespace SUNDIALS


template <typename VectorType>
NVectorContent<VectorType>::NVectorContent()
NVectorContent<VectorType>::NVectorContent(const MPI_Comm comm)
: vector(typename VectorMemory<VectorType>::Pointer(mem))
, comm(get_mpi_communicator_from_vector(*vector))
, comm(comm)
, is_const(false)
{}

Expand Down Expand Up @@ -565,14 +565,17 @@ namespace SUNDIALS
{
N_Vector v = clone_empty(w);

// the corresponding delete is called in destroy()
auto cloned = new NVectorContent<VectorType>();
auto *w_dealii = unwrap_nvector_const<VectorType>(w);

// reinit the cloned vector based on the layout of the source vector
cloned->get()->reinit(*w_dealii);
v->content = cloned;
// Create the vector; the corresponding delete is called in destroy()
auto cloned = new NVectorContent<VectorType>(
get_mpi_communicator_from_vector(*w_dealii));

// Then also copy the structure and values:
*cloned->get() = *w_dealii;

// Finally set the cloned object in 'v':
v->content = cloned;
return v;
}

Expand Down

0 comments on commit d717b6c

Please sign in to comment.