Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strassen multiplication does more multiplications than necessary #2063

Closed
fredrik-johansson opened this issue Sep 6, 2024 · 1 comment · Fixed by #2076
Closed

Strassen multiplication does more multiplications than necessary #2063

fredrik-johansson opened this issue Sep 6, 2024 · 1 comment · Fixed by #2076

Comments

@fredrik-johansson
Copy link
Collaborator

It looks like in all our implementations of Strassen multiplication, we compute the bottom right entry twice when the number of rows of A and columns of B are both odd. This doesn't really matter for a 101x101 multiply, but it does matter for a 3x3 multiply with big entries where we currently actually do 29 entry multiplications instead of 26 (so here our Strassen is actually worse than classical which does 27).

@fredrik-johansson
Copy link
Collaborator Author

So basically instead of

    if (a > 2*anr)
    {
        fmpz_mat_t Ar, Cr;
        fmpz_mat_window_init(Ar, A, 2*anr, 0, a, b);
        fmpz_mat_window_init(Cr, C, 2*anr, 0, a, c);
        fmpz_mat_mul(Cr, Ar, B);
        fmpz_mat_window_clear(Ar);
        fmpz_mat_window_clear(Cr);
    }

we should do

    if (a > 2*anr)
    {
        fmpz_mat_t Ar, Br, Cr;
        fmpz_mat_window_init(Ar, A, 2*anr, 0, a, b);
        fmpz_mat_window_init(Br, B, 0, 0, b, 2*bnc);
        fmpz_mat_window_init(Cr, C, 2*anr, 0, a, 2*bnc);
        fmpz_mat_mul(Cr, Ar, Br);
        fmpz_mat_window_clear(Ar);
        fmpz_mat_window_clear(Br);
        fmpz_mat_window_clear(Cr);
    }

(maybe with a separate case for when Br = B, to avoid the extra window matrix allocation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant