wdX_parallel
C++ Function Reference
1 Signature
Eigen::MatrixXd BigDataStatMeth::wdX_parallel(const Eigen::MatrixXd &X, const Eigen::VectorXd &w, Rcpp::Nullable< int > threads)2 Description
Compute parallel diagonal-matrix product wX.
3 Parameters
X(const Eigen::MatrixXd &): Input matrixw(const Eigen::VectorXd &): Vector representing diagonal matrixthreads(Rcpp::Nullable< int >): Number of threads for parallel computation
4 Returns
Diagonal-matrix product wX
5 Details
Parallel implementation of diagonal-matrix product computation.
6 Source Code
NoteImplementation
File: inst/include/memAlgebra/memOptimizedProducts.hpp • Lines 312-344
inline Eigen::MatrixXd wdX_parallel(const Eigen::MatrixXd& X, const Eigen::VectorXd& w, Rcpp::Nullable<int> threads = R_NilValue)
{
int n = X.cols();
// unsigned int ithreads;
Eigen::MatrixXd C = Eigen::MatrixXd::Zero(X.rows(),n);
// 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.row(i) = w(i)*X.row(i);
}
}
return(C);
}7 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = wdX_parallel(...);