diff --git a/dune/alugrid/impl/parallel/mpAccess_MPI_inline.h b/dune/alugrid/impl/parallel/mpAccess_MPI_inline.h index d008c7f3258985d4deef3fa355091d0885399389..dc38b07394fe7ae9d0e60d7eb36942064ffa11ec 100644 --- a/dune/alugrid/impl/parallel/mpAccess_MPI_inline.h +++ b/dune/alugrid/impl/parallel/mpAccess_MPI_inline.h @@ -13,6 +13,17 @@ namespace ALUGrid { inline MpAccessMPI::MinMaxSumIF* MpAccessMPI::copyMPIComm ( MPI_Comm mpicomm ) { + int wasInitialized = 0; + // check if MPI was initialized, otherwise exit + MPI_Initialized( &wasInitialized ); + if( ! wasInitialized ) + { + std::cerr << "ERROR: MPI was not initialized at the beginning of the program." + << " Please add the corresponding call to MPI_Init, e.g. by adding `Dune::MPIHelper::instance( argc, argv );`" + << " as a first line of the main routine." << std::endl; + std::abort(); + } + // duplicate mpi communicator MY_INT_TEST MPI_Comm_dup ( mpicomm, &_mpiComm); alugrid_assert (test == MPI_SUCCESS);