Dear Itomas,

I would recommend going the route suggested in this recent post 
<https://groups.google.com/forum/#!topic/dealii/kToGg5lNhFE>, namely 
creating a vector of shared pointers of PETSc vectors, i.e. 
std::vector<std::shared<PETScWrappers::MPI::Vector> >. Using shared 
pointers means that you safeguard against memory leaks, and can be stored 
as entries in a vector. That would give you the flexibility that you 
require with a minimal interface change to your code (apart from how you 
create the vectors initially, you would need to dereference these vector 
entries with the "->" operator instead of the "." operator). 

I hope that this helps.
Best regards,
Jean-Paul

On Friday, March 24, 2017 at 2:37:07 AM UTC+1, [email protected] wrote:
>
> Dear everybody:
>
> I don't have any particular problem, just trying to streamline a code. I 
> am have a mess with the interfaces of my code, in particular with the 
> functions and classes I have created, primarily because I have to handle a 
> ''packet'' of vectors, say 
>
>     PETScWrappers::MPI::Vector  Vect1;
>     PETScWrappers::MPI::Vector  Vect2;
>     PETScWrappers::MPI::Vector  Vect3;
>     PETScWrappers::MPI::Vector  Vect4;
>     …
>     PETScWrappers::MPI::Vector  Vect7;
>
> and use them either as input or output arguments of some functions, 
> solvers, complementary computations, etc. This is quite cumbersome, and as 
> solution I naively thought I could do the following
>
>     std::vector<PETScWrappers::MPI::Vector >  VectorPacket ;
>     VectorPacket.resize(7) ;
>     for (int i=0; i<7 ; ++i) 
>       VectorPacket[i].reinit (locally_owned_dofs, mpi_communicator ) ;
>
> So, now VectorPacket is really a packet, rather than seven isolated 
> vectors. It is almost needless to say that this is bad idea, std::vector 
> will demand quite a few things from the class PETScWrappers::MPI::Vector 
> which are just not there (in particular some operators). In reality the 
> size of the packet of vector is not always seven, which means that I really 
> need to use a proper container for which I can change it's size. Do you 
> have any suggestion (a.k.a. creative approach) on how to deal with an issue 
> like this one? Which container from the STL would be appropriate?
>
> Many thanks.
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to