[petsc-users] Assignement operator overloading for vectors

Barry Smith bsmith at mcs.anl.gov
Thu Jun 19 08:16:18 CDT 2014


  Write a tiny standalone code that only does the one thing of trying to do the copy constructor and send that (there is no need to send the entire complicated code).

   Barry

On Jun 19, 2014, at 8:13 AM, Cedric Doucet <cedric.doucet at inria.fr> wrote:

> 
> Hello,
> 
> thank you for your answer.
> 
> It is difficult to send the code as it is very big and difficult to read without some documentation.
> 
> The problem appears in the copy contructor of class like this :
> 
> class Foo {
> public:
>  Foo(){}
>  Foo(Foo const & copy)
>  {
>    VecDuplicate(copy.m_vec,&m_vec);
>    VecCopy(copy.m_vec,m_vec);
>  }
> private:
>  Vec m_vec;
> }
> 
> The copy constructor of Foo is implicitly called in the code during the copy of some std::vector<Foo>.
> 
> Here is the error message:
> 
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Invalid argument!
> [0]PETSC ERROR: Wrong type of object: Parameter # 1!
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: Petsc Release Version 3.4.4, unknown 
> [0]PETSC ERROR: See docs/changes/index.html for recent updates.
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [0]PETSC ERROR: See docs/index.html for manual pages.
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: ./main on a debug-openmpi-1.6.5 named pl-59031 by cdoucet Thu Jun 19 14:59:33 2014
> [0]PETSC ERROR: Libraries linked from /home/cdoucet/local/petsc/master/debug-openmpi-1.6.5/lib
> [0]PETSC ERROR: Configure run at Fri May 23 17:21:26 2014
> [0]PETSC ERROR: Configure options CXXFLAGS=-m64 CFLAGS=-m64 FCFLAGS=-m64 FFLAGS=-m64 LDFLAGS=-m64 --with-debugging=yes --with-dynamic-loading --with-shared-libraries --download-metis=1 --download-parmetis=1 --download-superlu_dist=1 --download-scalapack=1 --download-blacs=1 --download-mumps=1 --with-mpi-dir=/home/cdoucet/local/openmpi/1.6.5
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: VecDuplicate() line 511 in /home/cdoucet/local/petsc/master/src/vec/vec/interface/vector.c
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Invalid argument!
> [0]PETSC ERROR: Wrong type of object: Parameter # 1!
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: Petsc Release Version 3.4.4, unknown 
> [0]PETSC ERROR: See docs/changes/index.html for recent updates.
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [0]PETSC ERROR: See docs/index.html for manual pages.
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: ./main on a debug-openmpi-1.6.5 named pl-59031 by cdoucet Thu Jun 19 14:59:33 2014
> [0]PETSC ERROR: Libraries linked from /home/cdoucet/local/petsc/master/debug-openmpi-1.6.5/lib
> [0]PETSC ERROR: Configure run at Fri May 23 17:21:26 2014
> [0]PETSC ERROR: Configure options CXXFLAGS=-m64 CFLAGS=-m64 FCFLAGS=-m64 FFLAGS=-m64 LDFLAGS=-m64 --with-debugging=yes --with-dynamic-loading --with-shared-libraries --download-metis=1 --download-parmetis=1 --download-superlu_dist=1 --download-scalapack=1 --download-blacs=1 --download-mumps=1 --with-mpi-dir=/home/cdoucet/local/openmpi/1.6.5
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: VecCopy() line 1681 in /home/cdoucet/local/petsc/master/src/vec/vec/interface/vector.c
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Corrupt argument:
> see http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind!
> [0]PETSC ERROR: Invalid Pointer to Object: Parameter # 1!
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: Petsc Release Version 3.4.4, unknown 
> [0]PETSC ERROR: See docs/changes/index.html for recent updates.
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [0]PETSC ERROR: See docs/index.html for manual pages.
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: ./main on a debug-openmpi-1.6.5 named pl-59031 by cdoucet Thu Jun 19 14:59:33 2014
> [0]PETSC ERROR: Libraries linked from /home/cdoucet/local/petsc/master/debug-openmpi-1.6.5/lib
> [0]PETSC ERROR: Configure run at Fri May 23 17:21:26 2014
> [0]PETSC ERROR: Configure options CXXFLAGS=-m64 CFLAGS=-m64 FCFLAGS=-m64 FFLAGS=-m64 LDFLAGS=-m64 --with-debugging=yes --with-dynamic-loading --with-shared-libraries --download-metis=1 --download-parmetis=1 --download-superlu_dist=1 --download-scalapack=1 --download-blacs=1 --download-mumps=1 --with-mpi-dir=/home/cdoucet/local/openmpi/1.6.5
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: VecDuplicate() line 511 in /home/cdoucet/local/petsc/master/src/vec/vec/interface/vector.c
> Erreur de segmentation (core dumped)
> 
> 
> ----- Mail original -----
>> De: "Barry Smith" <bsmith at mcs.anl.gov>
>> À: "Cedric Doucet" <cedric.doucet at inria.fr>
>> Cc: petsc-users at mcs.anl.gov
>> Envoyé: Jeudi 19 Juin 2014 15:06:57
>> Objet: Re: [petsc-users] Assignement operator overloading for vectors
>> 
>> 
>>  “an error” is not very informative. Always send all possible information
>>  about errors you get; cut and paste all error messages etc.Also better to
>>  send the entire (hopefully small) code that reproduces the problem, than
>>  abstract snippets.
>> 
>>   Barry
>> 
>> On Jun 19, 2014, at 7:14 AM, Cedric Doucet <cedric.doucet at inria.fr> wrote:
>> 
>>> Hello,
>>> 
>>> I need to overload the assignement operator for a C++ class which has a
>>> Petsc vector as a data member:
>>> 
>>> class Foo
>>> {
>>> public:
>>> Foo & operator=(Foo const & copy);
>>> private:
>>> Vec m_vec;
>>> };
>>> 
>>> The algorithm for overloading the assignement operator should look like
>>> this :
>>> 
>>> Foo & Foo::operator=(Foo const & copy)
>>> {
>>> if ( this != copy )
>>> {
>>>   // destroy this->m_vec
>>>   // allocate this->m_vec with the same size as copy.m_vec's size
>>>   // copy the content of copy.m_vec into this->m_vec
>>> }
>>> return *this;
>>> }
>>> 
>>> I thought that VecCopy(copy.m_vec,m_vec) does everything I need but I have
>>> an error during the execution.
>>> So I tried to call first VecDuplicate(copy.m_vec,&m_vec) and then
>>> VecCopy(copy.m_vec,m_vec) but I still have an error.
>>> How shoud assignement operator overloading be implemented?
>>> Do I have to call VecDestroy before calling VecDuplicate?
>>> Must input vectors have the same size in VecCopy?
>>> 
>>> Thank you very much for your help!
>>> 
>>> Best regards,
>>> 
>>> Cédric Doucet
>> 
>> 



More information about the petsc-users mailing list