Add a version of MPI_InitFinalize that adaptively determines the number of threads

Add an option to MPI_InitFinalize to choose the number of threads adaptively in such a way that all cores are used.