From 9e8dd10f7c5c88b768be493ae36ed16137682afe Mon Sep 17 00:00:00 2001 From: "yu.dongliang" Date: Sun, 22 Nov 2020 18:00:41 +0800 Subject: [PATCH] ok --- mat.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mat.c b/mat.c index 0368098..4236f35 100644 --- a/mat.c +++ b/mat.c @@ -23,6 +23,9 @@ struct mat_s buf_t* b; }; +int g_buf_size = 0; +int g_buf_size_max = 0; + buf_t* buf_alloc(int n) { assert(n > 0); @@ -30,6 +33,11 @@ buf_t* buf_alloc(int n) buf_t* b = malloc(sizeof(buf_t) + sizeof(int) * n * n); assert(b); + g_buf_size += n * n; + if (g_buf_size_max < g_buf_size) + g_buf_size_max = g_buf_size; +// printf("%s(), g_buf_size: %d, g_buf_size_max: %d\n", __func__, g_buf_size, g_buf_size_max); + b->refs = 1; b->n = n; return b; @@ -37,8 +45,12 @@ buf_t* buf_alloc(int n) void buf_free(buf_t* b) { - if (b && 0 == --b->refs) + if (b && 0 == --b->refs) { + + g_buf_size -= b->n * b->n; + free(b); + } } mat_t* mat_alloc(int i, int j, int n, buf_t* b) @@ -181,27 +193,21 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) // p1 = a * (f - h) mat_sub(t0, f, h); mat_mul_strassen(p1, a, t0, n_min); - // p2 = (a + b) * h mat_add(t0, a, b); mat_mul_strassen(p2, t0, h, n_min); - // s = p1 + p2 mat_add(s, p1, p2); - // p3 = (c + d) * e mat_add(t0, c, d); mat_mul_strassen(p3, t0, e, n_min); - // p4 = d * (g - e) mat_sub(t0, g, e); mat_mul_strassen(p4, d, t0, n_min); - // t = p3 + p4 mat_add(t, p3, p4); - // tmp mat t1 mat_t* t1 = mat_alloc(0, 0, n, NULL); @@ -209,12 +215,10 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) mat_add(t0, a, d); mat_add(t1, e, h); mat_mul_strassen(p5, t0, t1, n_min); - //p6 = (b - d) * (g + h) 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); @@ -225,7 +229,6 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) 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); @@ -348,6 +351,7 @@ int main(int argc, char* argv[]) break; }; + printf("%s(), g_buf_size_max: %d\n", __func__, g_buf_size_max); return 0; } -- 2.25.1