MPI in C++ Shared Libraries

I have been working on a compiled C++ multi-physics library that utilizes FEniCS. It has a Python interface that is typically used to access its methods. I would like to set up the shared object to automatically run with MPI so I can take advantage of multithreading. Typically, I see Python scripts using the “mpirun” command when calling the interpreter. This does not work in my case since my Python scripts call a compiled library. Also I do not want the end user to have to prepend “mpirun” to their interpreter call.

Is there a programmatic way in the C++ interface to instruct FEniCS to use MPI? In the library’s shared object, I would like to have it automatically use MPI when certain criteria are met. I haven’t been able to find anything on this.