Sorry,
I realized I replied to Feng and not to the list. Below is my previous email.
Feng,
Your class is fine as long as the constructor of your solver is called AFTER
MPI_Init, and the destructor BEFORE MPI_Finalize.
This means that you cannot have something like
int main (int argc, char**argv)
{
MPI_Init();
solverpetsc S(argc,argv);
MPI_Finalize();
return 0;
}
as the destructor for S will be called after MPI_Finalize().
If you call PetscInitialize before MPI_Init, PETSc will call it for you. But
then, it will also call MPI_Finalize during PetscFinalize().
so, the following code will abort at any_MPI_call()
int main (int argc, char**argv)
{
solverpetsc *S;
S = new solverpetsc(argc,argv);
….
<here you can use MPI>
….
delete S;
any_MPI_call();
return 0;
}
On Oct 6, 2016, at 11:42 AM, Stefano Zampini <[email protected]> wrote:
>>
>> Long story short: I'd encourage you not to initialize PETSc in a
>> constructor, unless you know exactly what you are doing and can control the
>> possible side effects.
>>
>
> completely agree on that.
>