[petsc-users] question about contexts

Dominik Szczerba dominik at itis.ethz.ch
Fri Sep 30 10:54:18 CDT 2011


Yes, I only have one instance of my solver class, if this is what you
mean by a singleton.
I did not mean to cast my context, I meant to avoid any contexts and
just access the members. I so far use the context only to pass KSP,
Mat and Vec objects around a few functions. I am asking, because I
have not seen anyone doing it, while it appears natural to me. Also, I
am doubting if #define __FUNCT__ "StiffnessMatrixMultiplication" will
continue to work for static functions.

Thanks,
Dominik

On Fri, Sep 30, 2011 at 4:44 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> On Fri, Sep 30, 2011 at 09:34, Dominik Szczerba <dominik at itis.ethz.ch>
> wrote:
>>
>> I am currently declaring functions outside my C++ solver class to be
>> used by via MatShellSetOperation like:
>>
>> #undef __FUNCT__
>> #define __FUNCT__ "StiffnessMatrixMultiplication"
>> PetscErrorCode StiffnessMatrixMultiplication(Mat A, Vec x, Vec y)
>> {
>>        // ...
>>        ierr = MatShellGetContext(A, (void**) &ctx);CHKERRQ(ierr);
>>        Mat foo;
>>        foo = ctx->foo;
>>        // ...
>> }
>>
>> and I set/get contexts to e.g. pass 'foo' around. Is it possible in
>> Petsc / is it a good idea / to instead declare such functions as
>> static class member functions and then use the class members directly
>> without any contexts shuffled around?
>
> You have to go through the context unless your class is a singleton. Or do
> you still mean casting the ctx to your class type and accessing members
> through it (explicit "this")? That should work, if you prefer.


More information about the petsc-users mailing list