speedup via openmp

This commit is contained in:
conrad
2023-06-22 23:14:27 +10:00
parent 046be2a0e9
commit 85ddc3b874
+44 -11
View File
@@ -264,24 +264,57 @@ glue_conv2::apply(Mat<eT>& out, const Mat<eT>& A, const Mat<eT>& B)
out.set_size( out_n_rows, out_n_cols );
for(uword col=0; col < out_n_cols; ++col)
if( (arma_config::openmp) && (out_n_cols >= 2) )
{
eT* out_colptr = out.colptr(col);
for(uword row=0; row < out_n_rows; ++row)
#if defined(ARMA_USE_OPENMP)
{
// out.at(row, col) = accu( H % X(row, col, size(H)) );
const int n_threads = mp_thread_limit::get();
eT acc = eT(0);
for(uword H_col = 0; H_col < H_n_cols; ++H_col)
#pragma omp parallel for schedule(static) num_threads(n_threads)
for(uword col=0; col < out_n_cols; ++col)
{
const eT* X_colptr = X.colptr(col + H_col);
eT* out_colptr = out.colptr(col);
acc += op_dot::direct_dot( H_n_rows, H.colptr(H_col), &(X_colptr[row]) );
for(uword row=0; row < out_n_rows; ++row)
{
// out.at(row, col) = accu( H % X(row, col, size(H)) );
eT acc = eT(0);
for(uword H_col = 0; H_col < H_n_cols; ++H_col)
{
const eT* X_colptr = X.colptr(col + H_col);
acc += op_dot::direct_dot( H_n_rows, H.colptr(H_col), &(X_colptr[row]) );
}
out_colptr[row] = acc;
}
}
}
#endif
}
else
{
for(uword col=0; col < out_n_cols; ++col)
{
eT* out_colptr = out.colptr(col);
out_colptr[row] = acc;
for(uword row=0; row < out_n_rows; ++row)
{
// out.at(row, col) = accu( H % X(row, col, size(H)) );
eT acc = eT(0);
for(uword H_col = 0; H_col < H_n_cols; ++H_col)
{
const eT* X_colptr = X.colptr(col + H_col);
acc += op_dot::direct_dot( H_n_rows, H.colptr(H_col), &(X_colptr[row]) );
}
out_colptr[row] = acc;
}
}
}
}