Hi I have a program written in C++ in which one or two functions out of many are using PETSc.
When I’m calling these functions which would be the proper approach while using PETSc
1) a)change all MPI_COMM_WORLD to PETSC_COMM_WORLD for my entire program
b)change MPI_Init to PetscInitialize
..
2) create a separate comm world for petsc and pass that on to the function
MPI_Init(&argc, &argv);
..
//some many line of code
..
MPI_Comm_split(MPI_COMM_WORLD, rank, 0, &PETSC_COMM_WORLD);
petsc_function(PETSC_COMM_WORLD,.....
//some how reverting the comm_split here to continue as normal so all the non petsc functions work
..
3) or can i simply get by just using MPI_COMM_WORLD with the Petsc function
..
4) or is there another approach I am unaware of?
You need to call
PetscInitializefirst. You can replace the call toMPI_Initwith it.There is no need to set
PETSC_COMM_WORLDunless you only want to use PETSc on a subset of the ranks. If you do not setPETSC_COMM_WORLDyourself, it will be set automatically byPetscInitializeto be a copy ofMPI_COMM_WORLD.Then, when you call PETSc functions you can use
PETSC_COMM_WORLD. At the end of the program callPetscFinalize, which will callMPI_Finalizefor you unless you calledMPI_Initmanually instead of usingPetscInitializealone.There is no need to change
MPI_COMM_WORLDtoPETSC_COMM_WORLDin the rest of the program.