Hi everyone, I have the following line of codes which I would like to parallelize on the GPU :
U = zeros(q, M, q, 'gpuArray');
for j=1:q
U(j,:,j) = my_line_vector;
end
Is there any way to suppress the loop?
Thes are the lines of code that run the slowest in my program.
Thank you in advance
Michel

 Respuesta aceptada

Joss Knight
Joss Knight el 16 de En. de 2021
Editada: Joss Knight el 16 de En. de 2021

0 votos

I = reshape(gpuArray.eye(q),q,1,q);
U = I.*my_line_vector;

4 comentarios

POHL Michel
POHL Michel el 16 de En. de 2021
Hi, no it does not work, in your case U does not have any zeros,
whereas in my case U has a lot of zeros.
Joss Knight
Joss Knight el 16 de En. de 2021
Ah yes, sorry about that. I've edited the original, see if that works.
POHL Michel
POHL Michel el 16 de En. de 2021
Thank you, it works!
I did not know that the element wise product worked with matrices with different size.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 16 de En. de 2021

Comentada:

el 16 de En. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by