From: yu.dongliang Date: Sun, 22 Nov 2020 11:44:13 +0000 (+0800) Subject: opt X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=c51093352de06470a8e824c5cbc7d4bb37e4e209;p=mat.git opt --- diff --git a/mat.c b/mat.c index 4236f35..65eb0f2 100644 --- a/mat.c +++ b/mat.c @@ -183,9 +183,6 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) mat_t* p2 = mat_alloc(0, 0, n, NULL); mat_t* p3 = mat_alloc(0, 0, n, NULL); mat_t* p4 = mat_alloc(0, 0, n, NULL); - mat_t* p5 = mat_alloc(0, 0, n, NULL); - mat_t* p6 = mat_alloc(0, 0, n, NULL); - mat_t* p7 = mat_alloc(0, 0, n, NULL); // tmp mat t0 mat_t* t0 = mat_alloc(0, 0, n, NULL); @@ -208,42 +205,47 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) // t = p3 + p4 mat_add(t, p3, p4); + mat_sub(r, p4, p2); + mat_free(p2); + mat_free(p4); + + mat_sub(u, p1, p3); + mat_free(p1); + mat_free(p3); + // tmp mat t1 mat_t* t1 = mat_alloc(0, 0, n, NULL); //p5 = (a + d) * (e + h) + mat_t* p5 = mat_alloc(0, 0, n, NULL); mat_add(t0, a, d); mat_add(t1, e, h); mat_mul_strassen(p5, t0, t1, n_min); //p6 = (b - d) * (g + h) + mat_t* p6 = mat_alloc(0, 0, n, NULL); mat_sub(t0, b, d); mat_add(t1, g, h); mat_mul_strassen(p6, t0, t1, n_min); // r = p5 + p4 - p2 + p6 - mat_add(r, p5, p4); - mat_sub(r, r, p2); + mat_add(r, r, p5); mat_add(r, r, p6); + mat_free(p6); //p7 = (a - c) * (e + f) + mat_t* p7 = mat_alloc(0, 0, n, NULL); mat_sub(t0, a, c); mat_add(t1, e, f); mat_mul_strassen(p7, t0, t1, n_min); // u = p5 + p1 -p3 -p7 - mat_add(u, p5, p1); - mat_sub(u, u, p3); + mat_add(u, u, p5); mat_sub(u, u, p7); // free unused mats mat_free(t0); mat_free(t1); - mat_free(p1); - mat_free(p2); - mat_free(p3); - mat_free(p4); mat_free(p5); - mat_free(p6); mat_free(p7); mat_free(a); @@ -333,6 +335,8 @@ int main(int argc, char* argv[]) mat_fill(m0); mat_fill(m1); + printf("%s(), g_buf_size_max: %d\n", __func__, g_buf_size_max); + switch (flag) { case 0: mat_mul(m2, m0, m1);