Open
Conversation
archibate
reviewed
Jan 29, 2022
Contributor
archibate
left a comment
There was a problem hiding this comment.
感谢第一个提交作业!
- 完成作业基本要求 42/50 分
- 能够在 ANSWER.md 中用自己的话解释 23/25 分
- 代码格式规范、能够跨平台 4/5 分
- 有自己独特的创新点 11/20 分
| // 这两个是临时变量,有什么可以优化的? 5 分 | ||
| Matrix Rt, RtA; | ||
| // ans: 改为static变量,预先分配好空间。 | ||
| static Matrix Rt(std::array<std::size_t, 2>{1024, 1024}), RtA(std::array<std::size_t, 2>{1024, 1024}); |
Contributor
There was a problem hiding this comment.
Suggested change
| static Matrix Rt(std::array<std::size_t, 2>{1024, 1024}), RtA(std::array<std::size_t, 2>{1024, 1024}); | |
| static thread_local Matrix Rt, RtA; |
我觉得可以一开始为空没问题。thread_local保证如果多个线程访问不会出错。
| for(int i=0; i<nx; i+=32){ | ||
| for(int t=0; t<nt; t++){ | ||
| for(int i_block=i; i_block<i+32; i_block++){ | ||
| out(i,j) += lhs(i_block, t) * rhs(t, j); |
Contributor
There was a problem hiding this comment.
Suggested change
| out(i,j) += lhs(i_block, t) * rhs(t, j); | |
| out(i_block,j) += lhs(i_block, t) * rhs(t, j); |
漏改了一个?
| for (int y = 0; y < ny; y++) { | ||
| float val = wangsrng(x, y).next_float(); | ||
| out(x, y) = val; | ||
| // ans: 矩阵的x轴是紧密排列的,但是循环的内循环是y,访问数据时会跳跃,不利于cache; |
| out(y, x) = in(x, y); | ||
| } | ||
| } | ||
| // ans: 因为out矩阵是紧密访问,但是in矩阵是跳跃访问,cache中放不下。应改为分块转置。 |
| out(x, y) = 0; // 有没有必要手动初始化? 5 分 | ||
| for (int t = 0; t < nt; t++) { | ||
| out(x, y) += lhs(x, t) * rhs(t, y); | ||
| // ans: lhs是跳跃访问,rhs是连续访问,out不动,造成无法矢量化。 |
| TICK(matrix_RtAR); | ||
| // 这两个是临时变量,有什么可以优化的? 5 分 | ||
| Matrix Rt, RtA; | ||
| // ans: 改为static变量,预先分配好空间。 |
Contributor
There was a problem hiding this comment.
3,应该加thread_local,不需要初始化大小。
| // #pragma omp parallel for collapse(2) | ||
| // for (int y = 0; y < ny; y++) { | ||
| // for (int x = 0; x < nx; x++) { | ||
| // out(x, y) = 0; // 有没有必要手动初始化? 5 分 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
请见ANSWER.md。