I have to assemble a matrix using two for-loops, based on matrices from different libraries, using the following algorithm (here based on armadillo):
inline void loop_over_matrix_serial(const size_t &size, arma::mat &matrix)
{
for (size_t i = 0; i < size; ++i)
for (size_t j = 0; j < size; ++j)
matrix(i, j) += position_function(i, j);
}
In order to speed that operation up I would like to use a reduction with OpenMP. There are already custom reduction operators in other questions, such as here: C++ Armadillo and OpenMp: Parallelization of summation of outer products - define reduction for Armadillo matrix, but it is targeted on full matrices, not on single elements. How could I define a custom operator for all matrices which are accessed in the shown way, but from different libraries, for the reduction? It will always be a double-value which is added from the right side.