[petsc-users] petsc init in class constructor

Feng Xing snakexf at gmail.com
Thu Oct 6 02:12:25 CDT 2016


Hello everyone, 

I would like to write a c++ class which solve a linear system with petsc (code as following). 
Petsc is used only in this class. So I call MPI_Init in main.cpp, but PetscInitialize and PetscFinalise are in constructor/destructor of class.
I am wondering if this way is safe? 

class solvepetsc{

	solvepetsc(int argc, char** argv){
		PetscInitialize(&argc, &argv, NULL, NULL);
	};

	~solvepetsc(){
		PetscFinalize();
	};

	// ...
}

Thanks a lot and best regards,

Feng Xing 
Postdoc INRIA France


More information about the petsc-users mailing list