我正在问,能否改进
为了保持我们的重点,请允许我说,我有两个3x3矩阵,有0<的分类;=x<15。
以下宽度C++的实施工作用1秒钟左右进行,测量值为<代码> 时值/代码>。
#include <random>
int main() {
//Random number generator
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution<> distr(0, 15);
int A[3][3];
int B[3][3];
int C[3][3];
for (int trials = 0; trials <= 1000000; trials++) {
//Set up A[] and B[]
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
A[i][j] = distr(eng);
B[i][j] = distr(eng);
C[i][j] = 0;
}
}
//Compute C[]=A[]*B[]
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}
}
}
}
return 0;
}
注:
- The matrices are not necessarily sparse.
- Strassen-like comments does not help here.
- Let s try not to use the circumstantial observation, that in this specific problem the matrices
A[]
andB[]
can be encoded as a single 64 bit integer. Think of what would happen for just a bit larger matrices. - Computation is single-threaded.