xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Independent operations should be threaded

Open spectre-ns opened this issue 3 years ago • 1 comments

I have started using xtensor to design filters the following code looks to be very conducive to threading but the profiling tools say it is sequential.

    auto row_axis = xt::linspace<T>(0, rows - 1, rows);
    auto col_axis = xt::linspace<T>(0, cols - 1, cols);
    auto [yv, xv] = xt::meshgrid(row_axis, col_axis);
    auto A = xt::eval(xt::pow(yv, xv));

I'm basically taking exponents off the entire grid which is known upfront so in theory this should be able to be run on size(yv) threads. Is this intended behavior or something that is in the works?

spectre-ns avatar Feb 19 '22 20:02 spectre-ns

Hi,

Theoretically it could be multithreaded. The issue is that multithreading is enabled only for linear assignment, and generators (returned by the meshgrid) prevent that kind of assignment. A workaround can be to first evaluate the meshgrid into tensors, and then run the computation of pow. I agree it is not optimal, the correct solution would be to implement a data_element / simd API in the generators.

JohanMabille avatar Feb 23 '22 09:02 JohanMabille