Xwd_parallel

C++ Function Reference

1 Signature

Eigen::MatrixXd BigDataStatMeth::Xwd_parallel(const Eigen::MatrixXd &X, const Eigen::VectorXd &w, Rcpp::Nullable< int > threads)

2 Description

Compute parallel matrix-diagonal product Xw.

3 Parameters

  • X (const Eigen::MatrixXd &): Input matrix
  • w (const Eigen::VectorXd &): Vector representing diagonal matrix
  • threads (Rcpp::Nullable< int >): Number of threads for parallel computation

4 Returns

Matrix-diagonal product Xw

5 Details

Parallel implementation of matrix-diagonal product computation.

6 Source Code

File: inst/include/memAlgebra/memOptimizedProducts.hppLines 275-308

inline Eigen::MatrixXd Xwd_parallel(const Eigen::MatrixXd& X, const Eigen::VectorXd& w, Rcpp::Nullable<int> threads = R_NilValue)
{
    int n = X.rows();
    // unsigned int ithreads;
    Eigen::MatrixXd C = Eigen::MatrixXd::Zero(n,X.cols()) ; 
    
    
    // ithreads = get_number_threads(threads, R_NilValue);
    
    // if(threads.isNotNull()) {
    //     if (Rcpp::as<int> (threads) <= std::thread::hardware_concurrency()){
    //         ithreads = Rcpp::as<int> (threads);
    //     } else {
    //         ithreads = getDTthreads(0, true);
    //         //.11-04-2022.// ithreads = std::thread::hardware_concurrency()/2;}
    //     }
    // } else {
    //     ithreads = getDTthreads(0, true);
    //     //.11-04-2022.// ithreads = std::thread::hardware_concurrency()/2;
    // }
    
    //.OpenMP.//omp_set_num_threads(ithreads);
    
    //.OpenMP.//#pragma omp parallel shared(X, w, C) 
    #pragma omp parallel num_threads( get_number_threads(threads, R_NilValue) ) shared(X, w, C) 
    {
    #pragma omp for schedule (dynamic)
        for (int i=0; i<n; i++)
        {
            C.col(i) = X.col(i)*w(i);
        }  
    }
    return(C);
}

7 Usage Example

#include "BigDataStatMeth.hpp"

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