如何并行化矩阵转置? [英] How to to parallelize the matrix transpose?

查看:68
本文介绍了如何并行化矩阵转置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何并行化矩阵转置?

我知道要转置矩阵,我必须对此应用一些东西:

I know that to transpose matrix I must apply something about this:

for (int i = 0; i < matrix.length - 1; i++) {
    for (int j = i + 1; j < matrix[i].length; j++) {
        tmp = matrix[i][j];
        matrix[i][j] = matrix[j][i];
        matrix[j][i] = tmp;
    }
}

但是如何并行化这个操作,我不知道.

我需要创建 N 个线程来转置矩阵 4n x 4n.

推荐答案

因为这听起来像是一个家庭作业问题,所以我不会直接给你答案,但我会为你指明正确的方向.

Since this sounds like a homework problem, I won't give you the answer straight out, but I'll point you in the right direction.

假设您要转置一个 4x4 矩阵:

Let's say you're transposing a 4x4 matrix:

A B C D      A E I M
E F G H  ->  B F J N
I J K L      C G K O
M N O P      D H L P

如果我们把它分解成四个子矩阵:

If we break that down into four sub-matrices:

A B | C D      A E | I M
E F | G H      B F | J N
----+----  ->  ----+----
I J | K L      C G | K O
M N | O P      D H | L P

请注意,生成的四个子矩阵都是您开始使用的四个子矩阵的转置(交换了右上和左下矩阵).你怎么能利用这个?:)

Notice that the resulting four sub-matrices are all transposes of the four you started with (with the upper right and lower left matrices swapped). How can you make use of this? :)

这篇关于如何并行化矩阵转置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆