get_HDF5_scalar_min

C++ Function Reference

1 Signature

double BigDataStatMeth::get_HDF5_scalar_min(BigDataStatMeth::hdf5Dataset *dsA, bool bparal, Rcpp::Nullable< int > wsize, Rcpp::Nullable< int > threads)

2 Description

Minimum of all elements of an HDF5 matrix.

3 Parameters

  • dsA (BigDataStatMeth::hdf5Dataset *): Open HDF5 dataset.
  • bparal (bool): Enable OpenMP parallelism.
  • wsize (Rcpp::Nullable< int >): Block size (NULL = auto).
  • threads (Rcpp::Nullable< int >): Thread count (NULL = auto).

4 Returns

Scalar minimum.

5 Details

Equivalent to min(X). Uses OMP reduction (min clause).

6 Call Graph

Function dependencies

7 Source Code

File: inst/include/hdf5Algebra/matrixAggregations.hppLines 982-1030

inline double get_HDF5_scalar_min(BigDataStatMeth::hdf5Dataset* dsA,
                                   bool bparal,
                                   Rcpp::Nullable<int> wsize,
                                   Rcpp::Nullable<int> threads)
{
    try {
        const hsize_t nHDF5rows = dsA->nrows();
        const hsize_t nHDF5cols = dsA->ncols();

        const hsize_t bs = agg_block_size(wsize, nHDF5rows, nHDF5cols);

        std::vector<hsize_t> starts, sizes;
        agg_make_blocks(nHDF5rows, bs, starts, sizes);

        const std::vector<hsize_t> stride = {1, 1}, blk = {1, 1};
        const int nthreads = static_cast<int>(
            BigDataStatMeth::get_threads(bparal, threads));

        double global_min = std::numeric_limits<double>::infinity();

        #pragma omp parallel for schedule(dynamic) num_threads(nthreads) \
                shared(dsA, starts, sizes) reduction(min:global_min)
        for (hsize_t bi = 0; bi < starts.size(); bi++) {
            std::vector<double> vd(sizes[bi] * nHDF5cols);
            //.. 20260325 - remove critical ..// #pragma omp critical(accessFile)
            //.. 20260325 - remove critical ..// { 
            dsA->readDatasetBlock({starts[bi], 0}, {sizes[bi], nHDF5cols}, stride, blk, vd.data()); 
            //.. 20260325 - remove critical ..// }

            Eigen::Map<const RMMatd> X(vd.data(),
                static_cast<Eigen::Index>(sizes[bi]),
                static_cast<Eigen::Index>(nHDF5cols));

            global_min = std::min(global_min, X.minCoeff());
        }

        return global_min;

    } catch (H5::FileIException& e) {
        throw std::runtime_error("c++ exception get_HDF5_scalar_min (File IException): "
                                 + std::string(e.getDetailMsg()));
    } catch (H5::DataSetIException& e) {
        throw std::runtime_error("c++ exception get_HDF5_scalar_min (DataSet IException): "
                                 + std::string(e.getDetailMsg()));
    } catch (std::exception& e) {
        throw std::runtime_error(std::string("c++ exception get_HDF5_scalar_min: ")
                                 + e.what());
    }
}

8 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = get_HDF5_scalar_min(...);