diff --git a/configure b/configure
index 9b82b903f977ce4ee6d630bad6b7c33df6461007..4cbcd21be071dd45665fad13cf1ccd4d95736135 100755
--- a/configure
+++ b/configure
@@ -5489,7 +5489,6 @@ fi
 mpi_found=ko
 # optional libraries follow
 if test $mpi == true ; then
-  mpi_found=ok
 
     found=ko
     ac_fn_cxx_check_header_mongrel "$LINENO" "mpi.h" "ac_cv_header_mpi_h" "$ac_includes_default"
@@ -5512,6 +5511,9 @@ fi
 $as_echo "$as_me: WARNING: cannot enable __PLUMED_MPI" >&2;}
     fi
 
+  if test "x$ac_cv_func_MPI_Init" = xyes; then
+    mpi_found=ok
+  fi
 else
   mpi_found=ko
 fi
diff --git a/configure.ac b/configure.ac
index 54c6beb61c4fa3801f4b42299169fa61f19a4256..62a4a15cd6d9e4a71bd182518c29a9dbe2ef32f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -301,8 +301,10 @@ AC_CHECK_LIB([dl],dlopen, [STATIC_LIBS="-ldl $STATIC_LIBS"] [LIBS="-ldl $LIBS"])
 mpi_found=ko
 # optional libraries follow
 if test $mpi == true ; then
-  mpi_found=ok
   PLUMED_CHECK_PACKAGE([mpi.h],[MPI_Init],[__PLUMED_MPI])
+  if test "x$ac_cv_func_MPI_Init" = xyes; then
+    mpi_found=ok
+  fi
 else 
   mpi_found=ko
 fi