diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc index 8c083fafa..0fa40ce87 100644 --- a/internal/ceres/covariance_impl.cc +++ b/internal/ceres/covariance_impl.cc @@ -337,7 +337,14 @@ bool CovarianceImpl::GetCovarianceMatrixInTangentOrAmbientSpace( max_covariance_block_size]); bool success = true; -#pragma omp parallel for num_threads(num_threads) schedule(dynamic) collapse(2) + +// The collapse() directive is only supported in OpenMP 3.0 and higher. OpenMP +// 3.0 was released in May 2008 (hence the version number). +#if _OPENMP >= 200805 +# pragma omp parallel for num_threads(num_threads) schedule(dynamic) collapse(2) +#else +# pragma omp parallel for num_threads(num_threads) schedule(dynamic) +#endif for (int i = 0; i < parameters.size(); ++i) { for (int j = 0; j < parameters.size(); ++j) { // The second loop can't start from j = i for compatibility with OpenMP